Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function handler(message, context) {
} = context;
const { Opportunity } = dataAccess;
const { data, auditId: id } = message;
const { form_details: formDetails } = data;
const { formDetails } = data;

const opportunity = await Opportunity.findById(id);
if (opportunity) {
Expand All @@ -30,11 +30,11 @@ export default async function handler(message, context) {
const opportunityData = opportunity.getData();
const updatedAccessibility = opportunityData.accessibility.map((item) => {
// eslint-disable-next-line max-len
const matchingFormDetail = formDetails.find((detail) => detail.url === item.form && detail.form_source === item.formSource);
const matchingFormDetail = formDetails.find((detail) => detail.url === item.form && detail.formSource === item.formSource);
if (matchingFormDetail) {
log.info(`Matching form details : ${JSON.stringify(matchingFormDetail)}`);
// eslint-disable-next-line
const { url, form_source, ...cleanedFormDetail } = matchingFormDetail;
const { url, formSource, ...cleanedFormDetail } = matchingFormDetail;
const formTitle = getFormTitle(cleanedFormDetail, opportunity);
return { ...item, formTitle, formDetails: cleanedFormDetail };
}
Expand All @@ -46,10 +46,10 @@ export default async function handler(message, context) {
} else {
const opportunityData = opportunity.getData();
// eslint-disable-next-line max-len
const matchingFormDetail = formDetails.find((detail) => detail.url === opportunityData.form && detail.form_source === opportunityData.formsource);
const matchingFormDetail = formDetails.find((detail) => detail.url === opportunityData.form && detail.formSource === opportunityData.formsource);
if (matchingFormDetail) {
// eslint-disable-next-line
const { form, form_source, ...cleanedFormDetail } = matchingFormDetail;
const { form, formSource, ...cleanedFormDetail } = matchingFormDetail;
const formTitle = getFormTitle(cleanedFormDetail, opportunity);

// Check if this form should be ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function handler(message, context) {
const {
url,
guidance,
form_source: formsource,
formSource: formsource,
suggestions,
} = data;
log.info(`[Form Opportunity] [Site Id: ${siteId}] message received in high-form-views-low-conversions guidance handler: ${JSON.stringify(message, null, 2)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function handler(message, context) {
const {
url,
guidance,
form_source: formsource,
formSource: formsource,
suggestions,
} = data;
log.info(`[Form Opportunity] [Site Id: ${siteId}] message received in high-page-views-low-form-nav guidance handler: ${JSON.stringify(message, null, 2)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function handler(message, context) {
const { auditId, siteId, data } = message;
const {
url,
form_source: formsource,
formSource: formsource,
guidance, suggestions,
} = data;
log.info(`[Form Opportunity] [Site Id: ${siteId}] message received in high-page-views-low-form-views guidance handler: ${JSON.stringify(message, null, 2)}`);
Expand Down
32 changes: 15 additions & 17 deletions src/forms-opportunities/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,17 @@ export function shouldExcludeForm(scrapedFormData) {
* Forms are ignored if they match certain form types (defined in FORM_TYPES_TO_IGNORE)
* and are not lead generation forms.
*
* @param {Object} formDetails - The form details object containing form_type and is_lead_gen
* @param {Object} formDetails - The form details object containing formType and isLeadGen
* @returns {boolean} - True if the form should be ignored, false otherwise
*/
export function shouldIgnoreFormByDetails(formDetails) {
if (!formDetails || typeof formDetails !== 'object') {
return false;
}
// Normalize form_type to lowercase for case-insensitive comparison
const formType = formDetails.form_type?.toLowerCase();
// Normalize formType to lowercase for case-insensitive comparison
const formType = formDetails.formType?.toLowerCase();
// Ignore forms that match specified types and are not lead generation (boolean check)
return FORM_TYPES_TO_IGNORE.includes(formType) && formDetails.is_lead_gen === false;
return FORM_TYPES_TO_IGNORE.includes(formType) && formDetails.isLeadGen === false;
}

/**
Expand Down Expand Up @@ -442,9 +442,9 @@ export async function sendMessageToFormsQualityAgent(context, opportunity, forms

const data = {
url: site ? site.getBaseURL() : formsList[0]?.form,
form_details: formsList.map(({ form, formSource }) => ({
formDetails: formsList.map(({ form, formSource }) => ({
url: form,
form_source: formSource,
formSource,
})),
};

Expand Down Expand Up @@ -478,25 +478,23 @@ export async function sendMessageToMystiqueForGuidance(context, opportunity, opt
auditId: opptyData.auditId,
deliveryType: site ? site.getDeliveryType() : 'aem_cs',
time: new Date().toISOString(),
// keys inside data should follow snake case and outside should follow camel case
data: {
url: opptyData.data?.form,
cr: opptyData.data?.trackedFormKPIValue || 0,
metrics: opptyData.data?.metrics || [],
cta_source: opptyData.data?.formNavigation?.source || '',
cta_text: opptyData.data?.formNavigation?.text || '',
ctaSource: opptyData.data?.formNavigation?.source || '',
ctaText: opptyData.data?.formNavigation?.text || '',
opportunityId: opptyData.opportunityId || '',
form_source: opptyData.data?.formsource || '',
// form_details: opptyData.data?.formDetails,
formSource: opptyData.data?.formsource || '',
// eslint-disable-next-line max-len,no-nested-ternary
form_details: Array.isArray(opptyData.data?.formDetails) ? opptyData.data.formDetails : (opptyData.data?.formDetails ? [opptyData.data.formDetails] : []),
page_views: opptyData.data?.pageViews,
form_views: opptyData.data?.formViews,
form_navigation: {
formDetails: Array.isArray(opptyData.data?.formDetails) ? opptyData.data.formDetails : (opptyData.data?.formDetails ? [opptyData.data.formDetails] : []),
pageViews: opptyData.data?.pageViews,
formViews: opptyData.data?.formViews,
formNavigation: {
url: opptyData.data?.formNavigation?.url || '',
source: opptyData.data?.formNavigation?.source || '',
cta_clicks: opptyData.data?.formNavigation?.clicksOnCTA || 0,
page_views: opptyData.data?.formNavigation?.pageViews || 0,
ctaClicks: opptyData.data?.formNavigation?.clicksOnCTA || 0,
pageViews: opptyData.data?.formNavigation?.pageViews || 0,
},
},
};
Expand Down
6 changes: 3 additions & 3 deletions test/audits/forms/accessibility-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2162,10 +2162,10 @@ describe('Forms Opportunities - Accessibility Handler', () => {
accessibility: [{
form: 'test-form-2',
formDetails: {
is_lead_gen: true,
isLeadGen: true,
industry: 'Insurance',
form_type: 'Quote Request Form',
form_category: 'B2C',
formType: 'Quote Request Form',
formCategory: 'B2C',
cpl: 230.6,
},
formsource: 'test-source',
Expand Down
64 changes: 32 additions & 32 deletions test/audits/forms/form-details-handler/detect-form-details.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ describe('Detect Form Details Handler', () => {
auditId: 'testAuditId',
siteId: 'testSiteId',
data: {
form_details: [
{ url: 'testUrl1', form_source: 'formSource1', testKey: 'testValue1' },
{ url: 'testUrl2', form_source: 'formSource2', testKey: 'testValue1' },
formDetails: [
{ url: 'testUrl1', formSource: 'formSource1', testKey: 'testValue1' },
{ url: 'testUrl2', formSource: 'formSource2', testKey: 'testValue1' },
],
},
};
Expand Down Expand Up @@ -98,13 +98,13 @@ describe('Detect Form Details Handler', () => {
save: sinon.stub().resolvesThis(),
});

message.data.form_details = [
message.data.formDetails = [
{
url: 'testUrl1',
form_source: 'formSource1',
is_lead_gen: true,
form_type: 'Contact Form',
form_category: 'B2B',
formSource: 'formSource1',
isLeadGen: true,
formType: 'Contact Form',
formCategory: 'B2B',
industry: 'Telecommunications',
cpl: 94.0,
},
Expand All @@ -121,9 +121,9 @@ describe('Detect Form Details Handler', () => {
samples: 987,
projectedConversionValue: 8789.0,
formDetails: {
is_lead_gen: true,
form_type: 'Contact Form',
form_category: 'B2B',
isLeadGen: true,
formType: 'Contact Form',
formCategory: 'B2B',
industry: 'Telecommunications',
cpl: 94.0,
},
Expand Down Expand Up @@ -218,13 +218,13 @@ describe('Detect Form Details Handler', () => {
save: sinon.stub().resolvesThis(),
});

message.data.form_details = [
message.data.formDetails = [
{
url: 'testUrl1',
form_source: 'formSource1',
is_lead_gen: true,
form_type: 'Contact Form',
form_category: 'B2B',
formSource: 'formSource1',
isLeadGen: true,
formType: 'Contact Form',
formCategory: 'B2B',
industry: 'Telecommunications',
cpl: 94.0,
},
Expand All @@ -242,9 +242,9 @@ describe('Detect Form Details Handler', () => {
a11yIssues: [],
formTitle: 'Forms missing key accessibility attributes — enhancements prepared to support all users',
formDetails: {
is_lead_gen: true,
form_type: 'Contact Form',
form_category: 'B2B',
isLeadGen: true,
formType: 'Contact Form',
formCategory: 'B2B',
industry: 'Telecommunications',
cpl: 94,
},
Expand Down Expand Up @@ -272,13 +272,13 @@ describe('Detect Form Details Handler', () => {
save: sinon.stub().resolvesThis(),
});

message.data.form_details = [
message.data.formDetails = [
{
url: 'testUrl1',
form_source: 'formSource1',
is_lead_gen: false,
form_type: 'search form',
form_category: 'B2B',
formSource: 'formSource1',
isLeadGen: false,
formType: 'search form',
formCategory: 'B2B',
industry: 'Telecommunications',
cpl: 94.0,
},
Expand Down Expand Up @@ -307,12 +307,12 @@ describe('Detect Form Details Handler', () => {
save: sinon.stub().resolvesThis(),
});

message.data.form_details = [
message.data.formDetails = [
{
url: 'testUrl1',
form_source: 'formSource1',
is_lead_gen: false,
form_type: 'SEARCH form',
formSource: 'formSource1',
isLeadGen: false,
formType: 'SEARCH form',
},
];

Expand All @@ -338,12 +338,12 @@ describe('Detect Form Details Handler', () => {
save: sinon.stub().resolvesThis(),
});

message.data.form_details = [
message.data.formDetails = [
{
url: 'testUrl1',
form_source: 'formSource1',
is_lead_gen: true,
form_type: 'search form',
formSource: 'formSource1',
isLeadGen: true,
formType: 'search form',
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Guidance High Form Views Low Conversions Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance',
suggestions: ['Suggestion 1', 'Suggestion 2'],
},
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Guidance High Form Views Low Conversions Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance'
},
};
Expand All @@ -159,7 +159,7 @@ describe('Guidance High Form Views Low Conversions Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance'
},
};
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('Guidance High Form Views Low Conversions Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance',
suggestions: newSuggestion
},
Expand Down Expand Up @@ -279,7 +279,7 @@ describe('Guidance High Form Views Low Conversions Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance',
suggestions: newSuggestion
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Guidance High Page Views Low Form Navigation Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance',
suggestions: ['Suggestion 1', 'Suggestion 2'],
},
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('Guidance High Page Views Low Form Navigation Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance'
},
};
Expand All @@ -153,7 +153,7 @@ describe('Guidance High Page Views Low Form Navigation Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance'
},
};
Expand Down Expand Up @@ -212,7 +212,7 @@ describe('Guidance High Page Views Low Form Navigation Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance',
suggestions: newSuggestion
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Guidance High Page Views Low Form Views Handler', () => {
auditId: 'audit-id',
siteId: 'site-id',
data: {
form_source: '.form',
formSource: '.form',
url: 'https://example.com',
guidance: 'Some guidance',
suggestions: ['Suggestion 1', 'Suggestion 2'],
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('Guidance High Page Views Low Form Views Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance'
},
};
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('Guidance High Page Views Low Form Views Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance'
},
};
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('Guidance High Page Views Low Form Views Handler', () => {
siteId: 'site-id',
data: {
url: 'https://example.com',
form_source: '.form',
formSource: '.form',
guidance: 'Some guidance',
suggestions: newSuggestion
},
Expand Down
Loading
Loading