Skip to content

device wise metrics #683

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

Closed
wants to merge 1 commit into from
Closed
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
64 changes: 54 additions & 10 deletions packages/spacecat-shared-utils/src/formcalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function aggregateFormVitalsByDevice(formVitalsCollection) {
formVitalsCollection.forEach((item) => {
const {
url, formview = {}, formengagement = {}, pageview = {}, formsubmit = {},
trafficacquisition = {},
} = item;

const totals = {
Expand All @@ -54,7 +55,13 @@ function aggregateFormVitalsByDevice(formVitalsCollection) {
totals.formengagement = calculateSums(formengagement, totals.formengagement);
totals.pageview = calculateSums(pageview, totals.pageview);
totals.formsubmit = calculateSums(formsubmit, totals.formsubmit);

// Traffic Acquisition is not aggregated by device type
totals.trafficacquisition = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totals.trafficacquisition = { ...trafficacquisition }

total: trafficacquisition.total ? trafficacquisition.total : null,
paid: trafficacquisition.paid ? trafficacquisition.paid : null,
earned: trafficacquisition.earned ? trafficacquisition.earned : null,
owned: trafficacquisition.owned ? trafficacquisition.owned : null,
};
resultMap.set(url, totals);
});

Expand Down Expand Up @@ -90,18 +97,53 @@ export function getHighFormViewsLowConversionMetrics(formVitalsCollection) {
const urls = [];
resultMap.forEach((metrics, url) => {
const pageViews = metrics.pageview.total;
const mobilePageViews = metrics.pageview.mobile;
const desktopPageViews = metrics.pageview.desktop;
// Default to pageViews if formViews are not available
const formViews = metrics.formview.total || pageViews;
let formViews = metrics.formview.total;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check if formViews = 0
hasLowerConversionRate this will do division by 0

let mobileFormViews = metrics.formview.mobile;
let desktopFormViews = metrics.formview.desktop;
if (!formViews) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets skip the fallback now as we have improved RUM to capture formviews.

formViews = pageViews;
mobileFormViews = mobilePageViews;
desktopFormViews = desktopPageViews;
}
const formEngagement = metrics.formengagement.total;
const formSubmit = metrics.formsubmit.total || formEngagement;
const mobileFormEngagement = metrics.formengagement.mobile;
const desktopFormEngagement = metrics.formengagement.desktop;
let formSubmit = metrics.formsubmit.total;
let mobileFormSubmit = metrics.formsubmit.mobile;
let desktopFormSubmit = metrics.formsubmit.desktop;
if (!formSubmit) {
formSubmit = formEngagement;
mobileFormSubmit = mobileFormEngagement;
desktopFormSubmit = desktopFormEngagement;
}

if (hasHighPageViews(pageViews) && hasLowerConversionRate(formSubmit, formViews)) {
urls.push({
url,
pageViews,
formViews,
formEngagement,
formSubmit,
pageViews: {
total: pageViews,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to simplify it to:

urls.push({
        url,
        ...metrics
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can cleanup all the existing code then

mobile: mobilePageViews,
desktop: desktopPageViews,
},
formEngagement: {
total: formEngagement,
mobile: mobileFormEngagement,
desktop: desktopFormEngagement,
},
formViews: {
total: formViews,
mobile: mobileFormViews,
desktop: desktopFormViews,
},
formSubmit: {
total: formSubmit,
mobile: mobileFormSubmit,
desktop: desktopFormSubmit,
},
trafficacquisition: metrics.trafficacquisition,
});
}
});
Expand Down Expand Up @@ -182,13 +224,15 @@ export function getHighPageViewsLowFormCtrMetrics(formVitalsCollection) {
if (deviceData != null) {
urls.push({
url: entry.url,
pageViews: deviceData.pageview.total,
formViews: deviceData.formview.total,
formEngagement: deviceData.formengagement.total,
pageViews: deviceData.pageview,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here too:

urls.push({
        url,
        ...metrics
});

formViews: deviceData.formview,
formEngagement: deviceData.formengagement,
formSubmit: deviceData.formsubmit,
CTA: {
url: maxPageviewUrl.url,
source: y.source,
},
trafficacquisition: deviceData.trafficacquisition,
});
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/spacecat-shared-utils/test/fixtures/formcalcaudit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const formVitalsCollection = [
'desktop:windows': 5690,
'mobile:ios': 1000,
},
trafficacquisition: {
total: 1000,
paid: 500,
owned: 500,
earned: 100,
},
},
{
url: 'https://www.surest.com/info/win',
Expand Down
59 changes: 52 additions & 7 deletions packages/spacecat-shared-utils/test/formcalc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,32 @@ describe('Form Calc functions', () => {
expect(result).to.eql([
{
url: 'https://www.surest.com/contact-us',
pageViews: 6690,
formViews: 6690,
formEngagement: 1000,
formSubmit: 100,
pageViews: {
desktop: 5690,
mobile: 1000,
total: 6690,
},
formViews: {
desktop: 5690,
mobile: 1000,
total: 6690,
},
formEngagement: {
desktop: 700,
mobile: 300,
total: 1000,
},
formSubmit: {
desktop: 100,
mobile: 0,
total: 100,
},
trafficacquisition: {
total: 1000,
paid: 500,
owned: 500,
earned: 100,
},
},
]);
});
Expand Down Expand Up @@ -57,9 +79,32 @@ describe('Form Calc functions', () => {
expect(result).to.eql([
{
url: 'https://www.surest.com/newsletter',
pageViews: 8670,
formViews: 300,
formEngagement: 300,
pageViews: {
desktop: 4670,
mobile: 4000,
total: 8670,
},
formViews: {
desktop: 0,
mobile: 300,
total: 300,
},
formEngagement: {
desktop: 0,
mobile: 300,
total: 300,
},
formSubmit: {
desktop: 0,
mobile: 0,
total: 0,
},
trafficacquisition: {
total: null,
paid: null,
owned: null,
earned: null,
},
CTA: {
url: 'https://www.surest.com/about-us',
source: '#teaser-related02 .cmp-teaser__action-link',
Expand Down