Skip to content
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

feat: introduce navigation and traffic acquisition data in form audit #544

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -11,6 +11,7 @@
*/

import { DataChunks } from '@adobe/rum-distiller';
import trafficAcquisition from './traffic-acquisition.js';
import { generateKey, DELIMITER, loadBundles } from '../utils.js';

const FORM_SOURCE = ['.form', '.marketo', '.marketo-form'];
Expand All @@ -24,6 +25,7 @@ function initializeResult(url) {
formengagement: {},
formbuttonclick: {},
pageview: {},
forminternalnavigation: [],
};
}

Expand All @@ -48,6 +50,23 @@ const metricFns = {
},
};

function populateFormsInternalNavigation(bundles, formVitals) {
const dataChunks = new DataChunks();
loadBundles(bundles, dataChunks);
dataChunks.filter = { checkpoint: ['navigate'] };
dataChunks.filtered.forEach((bundle) => {

Choose a reason for hiding this comment

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

to add CTA clicks and total clicks here for opportunity classification

const forminternalnavigation = bundle.events.find((e) => e.checkpoint === 'navigate');
if (forminternalnavigation
&& !formVitals[bundle.url].forminternalnavigation
.some((e) => e.url === forminternalnavigation.source)) {
formVitals[bundle.url].forminternalnavigation.push({
url: forminternalnavigation.source,
pageview: formVitals[forminternalnavigation.source]?.pageview || null,
});
}
});
}

function containsFormVitals(row) {
return METRICS.some((metric) => Object.keys(row[metric]).length > 0);
}
Expand All @@ -62,12 +81,19 @@ function handler(bundles) {
// counts metrics per each group
METRICS.forEach((metric) => dataChunks.addSeries(metric, metricFns[metric]));

// traffic acquisition data per url
const trafficByUrl = trafficAcquisition.handler(bundles);
const trafficByUrlMap = Object.fromEntries(
trafficByUrl.map(({ url, ...item }) => [url, item]),
);

// aggregates metrics per group (url and user agent)
const formVitals = dataChunks.facets.urlUserAgents.reduce((acc, { value, metrics, weight }) => {
const [url, userAgent] = value.split(DELIMITER);

acc[url] = acc[url] || initializeResult(url);
acc[url].pageview[userAgent] = weight;
acc[url].trafficacquisition = trafficByUrlMap[url];

METRICS.filter((metric) => metrics[metric].sum) // filter out user-agents with no form vitals
.forEach((metric) => {
Expand All @@ -77,11 +103,13 @@ function handler(bundles) {
return acc;
}, {});

return Object.values(formVitals)
.filter(containsFormVitals); // filter out pages with no form vitals
// populate internal navigation data
populateFormsInternalNavigation(bundles, formVitals);
// filter out pages with no form vitals
return Object.values(formVitals).filter(containsFormVitals);
}

export default {
handler,
checkpoints: ['viewblock', 'formsubmit', 'click'],
checkpoints: ['viewblock', 'formsubmit', 'click', 'navigate'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -61384,6 +61384,12 @@
"userAgent": "desktop:windows",
"weight": 100,
"events": [
{
"checkpoint": "navigate",
"target": "visible",
"source": "https://business.adobe.com/products/marketo.html",
"timeDelta": 5750
},
{
"checkpoint": "click",
"target": "https://pps.services.adobe.com/api/profile/image/default/bb99dbb8-eab4-438d-ab41-f2f9f1b8ead3/138",
Expand Down
Loading
Loading