-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Low form views auto detect #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/forms-opportunities/oppty-handlers/low-views-handler.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2025 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { FORM_OPPORTUNITY_TYPES } from '../constants.js'; | ||
import { filterForms, generateOpptyData } from '../utils.js'; | ||
|
||
/** | ||
* @param auditUrl - The URL of the audit | ||
* @param auditData - The audit data containing the audit result and additional details. | ||
* @param context - The context object containing the data access and logger objects. | ||
* @param excludeForms - A set of Forms to exclude from the opportunity creation process. | ||
*/ | ||
// eslint-disable-next-line max-len | ||
export default async function createLowViewsOpportunities(auditUrl, auditDataObject, scrapedData, context, excludeForms = new Set()) { | ||
const { dataAccess, log } = context; | ||
const { Opportunity } = dataAccess; | ||
|
||
const auditData = JSON.parse(JSON.stringify(auditDataObject)); | ||
log.info(`Syncing high page views low form views opportunity for ${auditData.siteId}`); | ||
let opportunities; | ||
|
||
try { | ||
opportunities = await Opportunity.allBySiteIdAndStatus(auditData.siteId, 'NEW'); | ||
} catch (e) { | ||
log.error(`Fetching opportunities for siteId ${auditData.siteId} failed with error: ${e.message}`); | ||
throw new Error(`Failed to fetch opportunities for siteId ${auditData.siteId}: ${e.message}`); | ||
} | ||
|
||
const { formVitals } = auditData.auditResult; | ||
// eslint-disable-next-line max-len | ||
const formOpportunities = await generateOpptyData(formVitals, context, [FORM_OPPORTUNITY_TYPES.LOW_VIEWS]); | ||
log.debug(`forms opportunities high-page-views-low-form-views: ${JSON.stringify(formOpportunities, null, 2)}`); | ||
|
||
const filteredOpportunities = filterForms(formOpportunities, scrapedData, log, excludeForms); | ||
filteredOpportunities.forEach((oppty) => excludeForms.add(oppty.form + oppty.formsource)); | ||
log.info(`filtered opportunities: high-page-views-low-form-views: ${JSON.stringify(filteredOpportunities, null, 2)}`); | ||
try { | ||
for (const opptyData of filteredOpportunities) { | ||
let highPageViewsLowFormViewsOptty = opportunities.find( | ||
(oppty) => oppty.getType() === FORM_OPPORTUNITY_TYPES.LOW_VIEWS | ||
&& oppty.getData().form === opptyData.form, | ||
); | ||
|
||
const opportunityData = { | ||
siteId: auditData.siteId, | ||
auditId: auditData.auditId, | ||
runbook: 'https://adobe.sharepoint.com/:w:/s/AEM_Forms/EeYKNa4HQkRAleWXjC5YZbMBMhveB08F1yTTUQSrP97Eow?e=cZdsnA', | ||
type: FORM_OPPORTUNITY_TYPES.LOW_VIEWS, | ||
origin: 'AUTOMATION', | ||
title: 'The form has low views', | ||
description: 'The form has low views but the page containing the form has higher traffic', | ||
tags: ['Forms Conversion'], | ||
data: { | ||
...opptyData, | ||
}, | ||
guidance: { | ||
recommendations: [ | ||
{ | ||
insight: `The form in the page: ${opptyData.form} has low discoverability and only ${(opptyData.formViews / opptyData.pageViews) * 100}% visitors landing on the page are viewing the form.`, | ||
recommendation: 'Position the form higher up on the page so users see it without scrolling. Consider using clear and compelling CTAs, minimizing distractions, and ensuring strong visibility across devices.', | ||
type: 'guidance', | ||
rationale: 'Forms that are visible above the fold are more likely to be seen and interacted with by users.', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
log.info(`Forms Opportunity created high page views low form views ${JSON.stringify(opportunityData, null, 2)}`); | ||
if (!highPageViewsLowFormViewsOptty) { | ||
// eslint-disable-next-line no-await-in-loop | ||
highPageViewsLowFormViewsOptty = await Opportunity.create(opportunityData); | ||
} else { | ||
highPageViewsLowFormViewsOptty.setAuditId(auditData.auditId); | ||
highPageViewsLowFormViewsOptty.setData({ | ||
...highPageViewsLowFormViewsOptty.getData(), | ||
...opportunityData.data, | ||
}); | ||
highPageViewsLowFormViewsOptty.setGuidance(opportunityData.guidance); | ||
// eslint-disable-next-line no-await-in-loop | ||
await highPageViewsLowFormViewsOptty.save(); | ||
} | ||
} | ||
} catch (e) { | ||
log.error(`Creating Forms opportunity for high page views low form views for siteId ${auditData.siteId} failed with error: ${e.message}`, e); | ||
} | ||
log.info(`Successfully synced Opportunity for site: ${auditData.siteId} and high page views low form views audit type.`); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we update this excludeForms set in filterForms method itself?