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: Pages with steady decline of conversion #293

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c42f301
feat: Pages with steady decline of conversion
Jul 17, 2024
7098e37
fix lint issues
Jul 18, 2024
a99194f
feat: Pages with steady decline of conversion
Jul 19, 2024
0ea09d1
merge main to branch
Jul 30, 2024
e64d279
WIP
Jul 30, 2024
1db3702
merging main to branch
Jul 30, 2024
1e86711
feat: Pages with steady decline of conversion
Aug 2, 2024
faab213
Merge branch 'main' into SITES-22537
Dereje24 Aug 2, 2024
b8c547f
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
5627ed5
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
7bd17ff
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
057efc4
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
5d6aada
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
2f2c53f
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
86f5aed
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
6c212b4
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 14, 2024
61d200e
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 15, 2024
3edcd69
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
c7e18b6
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
f7624c1
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
30358ed
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
3ba9258
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
51f2fdd
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
d16f567
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
07ff401
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
92156f5
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
b9384aa
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 19, 2024
aa877bf
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 20, 2024
311ff29
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
baceb4f
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
f56cecb
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
5bec5aa
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
9cb173d
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
d5e5853
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
88083f7
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
69a926d
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
11e4844
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
fb7369b
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
a52afa7
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
ff4c4e5
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
0f1a7ab
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 21, 2024
ebf9175
SITES-22537 [oppty] Pages with steady decline of CTR
Aug 22, 2024
9af5727
fix filtering threshold
Aug 28, 2024
45a0fb3
refactor oppty
Nov 6, 2024
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 @@ -22,7 +22,6 @@ function collect404s(groupedByUrlAndSource) {

// calculate the total number of views per 404 event
const views = itemsByUrl.flatMap((item) => item.items).reduce((acc, cur) => acc + cur.weight, 0);

return {
url,
views,
Expand Down
131 changes: 131 additions & 0 deletions packages/spacecat-shared-rum-api-client/src/functions/opportunities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/* c8 ignore start */
const PAGEVIEW_THRESHOLD = 35000;

function getWeekIndex(time) {
const date = new Date(time);
const currentDate = new Date();
const diff = Math.abs(currentDate - date);
const diffDays = Math.floor(diff / (1000 * 60 * 60 * 24));
switch (true) {
case diffDays < 7: return 4;
case diffDays < 14: return 3;
case diffDays < 21: return 2;
case diffDays < 28: return 1;
default: return 0;
}
}

function processBundles(bundles) {
const data = {};

for (const bundle of bundles) {
const weekIndex = getWeekIndex(bundle.time);
const weekKey = `week${weekIndex}`;
Fixed Show fixed Hide fixed

if (!data[bundle.url]) {
data[bundle.url] = {};
}

if (!data[bundle.url][weekKey]) {
data[bundle.url][weekKey] = {
pageViews: 0,
clicks: 0,
pageCTR: 0,
metrics: [],
};
}

data[bundle.url][weekKey].pageViews += bundle.weight;
const selector = {};
const bundleWeight = bundle.weight;
for (const event of bundle.events) {
if (event.checkpoint === 'click') {
selector[event.source] = selector[event.source] ? selector[event.source] + 1 : 1;
}
}

for (const source of Object.keys(selector)) {
// eslint-disable-next-line max-len
const existingMetric = data[bundle.url][weekKey].metrics.find((metric) => metric.selector === source);
if (existingMetric) {
existingMetric.clicks += bundleWeight;
} else {
data[bundle.url][weekKey].metrics.push({ selector: source, clicks: bundleWeight });
}
}

data[bundle.url][weekKey].clicks += Object.keys(selector).length > 0 ? bundleWeight : 0;
}

// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const url in data) {
// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const weekKey in data[url]) {
// eslint-disable-next-line max-len
data[url][weekKey].pageCTR = parseFloat((data[url][weekKey].clicks / data[url][weekKey].pageViews).toFixed(2));
data[url][weekKey].metrics = data[url][weekKey].metrics.map((metric) => {
// eslint-disable-next-line no-param-reassign
metric.ctr = parseFloat((metric.clicks / data[url][weekKey].pageViews).toFixed(2));
return metric;
}).filter((metric) => metric.ctr >= 0.05);
}
}

// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const url in data) {
let hasEnoughPageViews = true;
// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const weekKey in data[url]) {
if (data[url][weekKey].pageViews < PAGEVIEW_THRESHOLD) {
hasEnoughPageViews = false;
break;
}
}
if (!hasEnoughPageViews) {
delete data[url];
}
}

return data;
}

function handler(bundles) {
const acquisitionBundles = [];
const nonAcquisitionBundles = [];

for (const bundle of bundles) {
const hasAcquisition = bundle.events.some((event) => event.checkpoint === 'acquisition');
if (hasAcquisition) {
acquisitionBundles.push(bundle);
} else {
nonAcquisitionBundles.push(bundle);
}
}

const acquisitionData = processBundles(acquisitionBundles);
const nonAcquisitionData = processBundles(nonAcquisitionBundles);

return {
acquisitionData,
nonAcquisitionData,
};
}

export default {
handler,
};

// eslint-disable-next-line guard-for-in,no-restricted-syntax
/* c8 ignore end */
2 changes: 2 additions & 0 deletions packages/spacecat-shared-rum-api-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import cwv from './functions/cwv.js';
import experiment from './functions/experiment.js';
import trafficAcquisition from './functions/traffic-acquisition.js';
import variant from './functions/variant.js';
import opportunities from './functions/opportunities.js';

const HANDLERS = {
404: notfound,
cwv,
experiment,
'traffic-acquisition': trafficAcquisition,
variant,
opportunities,
};

export default class RUMAPIClient {
Expand Down
194 changes: 194 additions & 0 deletions packages/spacecat-shared-rum-api-client/test/fixtures/oppty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
[
{
"url": "https://www.aem.live/docs/sidekick-extension",
"views": 1400,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/placeholders",
"views": 1300,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/home",
"views": 1000,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/block-collection",
"views": 900,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/importer",
"views": 800,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/",
"views": 700,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/tools/rum/explorer.html",
"views": 600,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/tutorial",
"views": 600,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/davidsmodel",
"views": 600,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/byo-cdn-cloudflare-worker-setup",
"views": 500,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/block-collection/breadcrumbs",
"views": 400,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/rum",
"views": 400,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/go-live-checklist",
"views": 400,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/web-components",
"views": 200,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/keeping-it-100",
"views": 200,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/dev-collab-and-good-practices",
"views": 200,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/target-integration",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/developer/anatomy-of-a-franklin-project",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/tools/bot/setup",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/placeholders",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/custom-headers",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/tools/rum/list.html",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/docs/authentication-setup-site",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
},
{
"url": "https://www.aem.live/vip/intake",
"views": 100,
"week1CTR": 0.01,
"week2CTR": 0.01,
"week3CTR": 0.01,
"week4CTR": 0.01
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import { expect } from 'chai';
import cwv from '../src/functions/cwv.js';
import opportunity from '../src/functions/opportunities.js';
import notfound from '../src/functions/404.js';
import experiment from '../src/functions/experiment.js';
import trafficAcquisition from '../src/functions/traffic-acquisition.js';
Expand All @@ -24,6 +25,7 @@
import expectedExperimentsResult from './fixtures/experiments.json' assert { type: 'json' };
import expectedTrafficSourcesResult from './fixtures/trafficSources.json' assert { type: 'json' };
import expectedVariantResult from './fixtures/variant.json' assert { type: 'json' };
import expectedOpportunitiesResult from './fixtures/petplace_bundles.json' assert { type: 'json' };

Check failure on line 28 in packages/spacecat-shared-rum-api-client/test/functions.test.js

View workflow job for this annotation

GitHub Actions / Test

Unable to resolve path to module './fixtures/petplace_bundles.json'

describe('Query functions', () => {
it('crunches cwv data', async () => {
Expand All @@ -50,4 +52,11 @@
const trafficSourcesResult = await trafficAcquisition.handler(bundles.rumBundles);
expect(expectedTrafficSourcesResult).to.eql(trafficSourcesResult);
});

it('crunches CTR opportunity data', async () => {
const opportunitiesResult = opportunity.handler(expectedOpportunitiesResult.rumBundles);
// expect(expectedOpportunitiesResult).to.eql(opportunitiesResult);
// eslint-disable-next-line no-console
console.log(JSON.stringify(opportunitiesResult, null, 2));
});
});
Loading