Skip to content

Commit

Permalink
fix: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rpapani committed Sep 20, 2024
1 parent 5e0d23b commit 9445211
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 172 deletions.
31 changes: 25 additions & 6 deletions packages/spacecat-shared-rum-api-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Calculates the amount of inorganic traffic and the bounce rate for each page. Id

### high-organic-low-ctr (Experimentation Opportunity)

Calculates the amount of non-inorganic (earned and owned) traffic and the click-through rate for each page. Identifies pages with high non-inorganic traffic and low click-through rates, which can be targeted for future experimentation opportunities. An example payload is provided below:
Calculates the amount of non-inorganic (earned and owned) traffic and the click-through rate for each page and vendor. Identifies pages with high non-inorganic traffic and low click-through rates, which can be targeted for future experimentation opportunities. An example payload is provided below:

```json
[
Expand All @@ -251,24 +251,43 @@ Calculates the amount of non-inorganic (earned and owned) traffic and the click-
"page": "https://www.spacecat.com/about-us",
"screenshot": "",
"trackedPageKPIName": "Click Through Rate",
"trackedPageKPIValue": 0.14099783080260303,
"trackedPageKPIValue": 0.14316702819956617,
"pageViews": 46100,
"samples": 46100,
"siteAverage": 0.40828402366863903,
"metrics": [
{
"type": "traffic",
"vendor": "*",
"value": {
"total": 46100,
"paid": 0,
"owned": 46100,
"paid": 300,
"owned": 45800,
"earned": 0
}
},
{
"type": "ctr",
"vendor": "*",
"value": {
"page": 0.14099783080260303,
"siteAverage": 0.4077909270216962
"page": 0.14316702819956617
}
},
{
"type": "traffic",
"vendor": "tiktok",
"value": {
"total": 300,
"owned": 0,
"earned": 0,
"paid": 300
}
},
{
"type": "ctr",
"vendor": "tiktok",
"value": {
"page": 0.3333333333333333
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,28 @@ const CTR_THRESHOLD_RATIO = 0.95;
const DAILY_PAGEVIEW_THRESHOLD = 1000;
const VENDORS_TO_CONSIDER = 5;

const MAIN_TYPES = ['paid', 'earned', 'owned'];

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

const vendors = sources.reduce((acc, { type, views }) => {
const [trafficType, , vendor] = type.split(':');
if (!vendor) {
return acc;
}
if (MAIN_TYPES.includes(trafficType)) {
acc[vendor] = acc[vendor] || {
total: 0, owned: 0, earned: 0, paid: 0,
};
acc[vendor].total += views;
acc[vendor][trafficType] += views;
}
return acc;
}, {});

const topVendors = Object.entries(vendors)
.sort((a, b) => b[1].total - a[1].total).slice(0, VENDORS_TO_CONSIDER);
const opportunity = {
Expand All @@ -36,7 +53,7 @@ function convertToOpportunity(traffic) {
siteAverage: siteAvgCTR,
metrics: [{
type: 'traffic',
referrer: '*',
vendor: '*',
value: {
total,
paid,
Expand All @@ -45,7 +62,7 @@ function convertToOpportunity(traffic) {
},
}, {
type: 'ctr',
referrer: '*',
vendor: '*',
value: {
page: ctr,
},
Expand All @@ -56,7 +73,7 @@ function convertToOpportunity(traffic) {
}]) => {
const trafficMetrics = {
type: 'traffic',
referrer: vendor,
vendor,
value: {
total: _total,
owned: _owned,
Expand All @@ -66,7 +83,7 @@ function convertToOpportunity(traffic) {
};
const ctrMetrics = {
type: 'ctr',
referrer: vendor,
vendor,
value: {
page: ctrByUrlAndVendor[vendor],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,15 @@ import { classifyTrafficSource, extractTrafficHints } from '../common/traffic.js
const MAIN_TYPES = ['total', 'paid', 'earned', 'owned'];

function collectByUrlAndTrafficSource(acc, {
url, weight, trafficSource, vendor,
url, weight, trafficSource,
}) {
acc[url] = acc[url] || {
total: 0, owned: 0, earned: 0, paid: 0, vendors: {},
total: 0, owned: 0, earned: 0, paid: 0,
};
acc[url][trafficSource] = (acc[url][trafficSource] || 0) + weight;
acc[url].total += weight;
const trafficType = trafficSource.split(':')[0];
acc[url][trafficType] += weight;
if (vendor) {
if (!acc[url].vendors[vendor]) {
acc[url].vendors[vendor] = {
total: 0, owned: 0, earned: 0, paid: 0,
};
}
acc[url].vendors[vendor].total += weight;
acc[url].vendors[vendor][trafficType] += weight;
}
return acc;
}

Expand All @@ -44,9 +35,8 @@ function transformFormat(trafficSources) {
owned: value.owned,
paid: value.paid,
sources: Object.entries(value)
.filter(([source]) => !MAIN_TYPES.includes(source) && source !== 'vendors')
.filter(([source]) => !MAIN_TYPES.includes(source))
.map(([source, views]) => ({ type: source, views })),
vendors: value.vendors,
}));
}

Expand All @@ -62,8 +52,7 @@ function handler(bundles) {
return {
url: row.url,
weight: row.weight,
trafficSource: `${type}:${category}`,
vendor,
trafficSource: vendor ? `${type}:${category}:${vendor}` : `${type}:${category}`,
};
})
.reduce(collectByUrlAndTrafficSource, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"metrics": [
{
"type": "traffic",
"referrer": "*",
"vendor": "*",
"value": {
"total": 46100,
"paid": 300,
Expand All @@ -21,14 +21,14 @@
},
{
"type": "ctr",
"referrer": "*",
"vendor": "*",
"value": {
"page": 0.14316702819956617
}
},
{
"type": "traffic",
"referrer": "tiktok",
"vendor": "tiktok",
"value": {
"total": 300,
"owned": 0,
Expand All @@ -38,7 +38,7 @@
},
{
"type": "ctr",
"referrer": "tiktok",
"vendor": "tiktok",
"value": {
"page": 0.3333333333333333
}
Expand Down
Loading

0 comments on commit 9445211

Please sign in to comment.