Skip to content

Commit

Permalink
adds the maximum time on page for high organic traffic low ctr
Browse files Browse the repository at this point in the history
  • Loading branch information
manani_adobe committed Jan 31, 2025
1 parent 7590869 commit 316f88b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MAIN_TYPES = ['paid', 'earned', 'owned'];

function convertToOpportunity(traffic) {
const {
url, total, ctr, paid, owned, earned, sources, siteAvgCTR, ctrByUrlAndVendor,
url, total, ctr, paid, owned, earned, sources, siteAvgCTR, ctrByUrlAndVendor, pageOnTime,
} = traffic;

const vendors = sources.reduce((acc, { type, views }) => {
Expand Down Expand Up @@ -66,6 +66,12 @@ function convertToOpportunity(traffic) {
value: {
page: ctr,
},
}, {
type: 'pageOnTime',
vendor: '*',
value: {
time: pageOnTime,
},
}],
};
opportunity.metrics.push(...topVendors.flatMap(([vendor, {
Expand All @@ -88,7 +94,14 @@ function convertToOpportunity(traffic) {
page: ctrByUrlAndVendor[vendor],
},
};
return [trafficMetrics, ctrMetrics];
const pageOnTimeMetrics = {
type: 'pageOnTime',
vendor,
value: {
time: pageOnTime,
},
};
return [trafficMetrics, ctrMetrics, pageOnTimeMetrics];
}));
return opportunity;
}
Expand Down Expand Up @@ -117,11 +130,11 @@ function handler(bundles, opts = {}) {
ctr: ctrByUrlAndVendor[traffic.url].value,
siteAvgCTR,
ctrByUrlAndVendor: ctrByUrlAndVendor[traffic.url].vendors,
pageOnTime: traffic.maxTimeDelta,
}))
.map(convertToOpportunity);
}

export default {
handler,
checkpoints: ['email', 'enter', 'paid', 'utm', 'click', 'experiment'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import { classifyTraffic } from '../common/traffic.js';
const MAIN_TYPES = ['total', 'paid', 'earned', 'owned'];

function collectByUrlAndTrafficSource(acc, {
url, weight, trafficSource,
url, weight, trafficSource, maxTimeDelta,
}) {
acc[url] = acc[url] || {
total: 0, owned: 0, earned: 0, paid: 0,
total: 0, owned: 0, earned: 0, paid: 0, maxTimeDelta: 0,
};
acc[url][trafficSource] = (acc[url][trafficSource] || 0) + weight;
acc[url].total += weight;
acc[url].maxTimeDelta = maxTimeDelta;
const trafficType = trafficSource.split(':')[0];
acc[url][trafficType] += weight;
return acc;
Expand All @@ -34,26 +35,35 @@ function transformFormat(trafficSources) {
earned: value.earned,
owned: value.owned,
paid: value.paid,
maxTimeDelta: value.maxTimeDelta,
sources: Object.entries(value)
.filter(([source]) => !MAIN_TYPES.includes(source))
.filter(([source]) => !MAIN_TYPES.includes(source) && source !== 'maxTimeDelta')
.map(([source, views]) => ({ type: source, views })),
}));
}

function formatTraffic(row) {
const {
url, weight, type, category, vendor,
url, weight, type, category, vendor, events = [],
} = row;

const timeDeltas = events.map((event) => event.timeDelta);
const maxTimeDelta = Math.max(...timeDeltas, 0);

return {
url,
weight,
trafficSource: vendor ? `${type}:${category}:${vendor}` : `${type}:${category}`,
maxTimeDelta,
};
}

function handler(bundles) {
const trafficSources = bundles
.map(classifyTraffic)
.map((bundle) => ({
...classifyTraffic(bundle),
events: bundle.events,
}))
.map(formatTraffic)
.reduce(collectByUrlAndTrafficSource, {});

Expand All @@ -63,5 +73,4 @@ function handler(bundles) {

export default {
handler,
checkpoints: ['email', 'enter', 'paid', 'utm', 'experiment'],
};

0 comments on commit 316f88b

Please sign in to comment.