Skip to content

Commit

Permalink
feat: Include site level metrics in the CWV response
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed Dec 4, 2024
1 parent da78c12 commit 50e93b9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
8 changes: 5 additions & 3 deletions packages/spacecat-shared-rum-api-client/src/functions/cwv.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function handler(rawBundles, opts = []) {
// counts metrics per each facet
METRICS.forEach((metric) => dataChunks.addSeries(metric, series[metric]));

// count organic traffic per each facet
// counts organic traffic per each facet
dataChunks.addSeries('organic', series.organic);

const patternsResult = dataChunks.facets.patternsDevices.reduce((acc, facet) => {
Expand All @@ -109,14 +109,15 @@ function handler(rawBundles, opts = []) {
metrics: [],
};

// Increment the total pageviews for pattern
// Increment the total pageviews and organic traffic for pattern
acc[pattern].pageviews += facet.weight;
acc[pattern].organic += facet.metrics.organic.sum;

// Add metrics for the specific device type
acc[pattern].metrics.push({
deviceType,
pageviews: facet.weight, // Pageviews for this device type
organic: facet.metrics.organic.sum, // Organic traffic for this device type
...calculateMetricsPercentile(facet.metrics),
});

Expand All @@ -134,14 +135,15 @@ function handler(rawBundles, opts = []) {
metrics: [],
};

// Increment the total pageviews for url
// Increment the total pageviews and organic traffic for url
acc[url].pageviews += facet.weight;
acc[url].organic += facet.metrics.organic.sum;

// Add metrics for the specific device type
acc[url].metrics.push({
deviceType,
pageviews: facet.weight, // Pageviews for this device type
organic: facet.metrics.organic.sum, // Organic traffic for this device type
...calculateMetricsPercentile(facet.metrics),
});

Expand Down
4 changes: 2 additions & 2 deletions packages/spacecat-shared-rum-api-client/test/cwv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import bundlesForPatterns from './fixtures/cwv/bundles-for-url-patterns.json' as
import resultForPatterns from './fixtures/cwv/result-for-url-patterns.json' assert { type: 'json' };

describe('CWV Queries', () => {
it('crunches cwv data', async () => {
it('crunches CWV data', async () => {
const result = cwv.handler(bundlesForUrls.rumBundles);
expect(result).to.deep.equal(resultForUrls);
});

it('should correctly process CWV data with url patterns', async () => {
it('crunches CWV data based on url patterns', async () => {
const groupedURLs = [
{ name: 'Catalog', pattern: 'https://www.aem.live/catalog/*' },
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
}
]
},

{
"id": "product_1_mobile_session_1",
"host": "main--helix-website--adobe.aem.live",
Expand Down Expand Up @@ -290,6 +289,12 @@
"userAgent": "mobile:ios",
"weight": 100,
"events": [
{
"checkpoint": "enter",
"target": "visible",
"source": "https://www.google.com",
"timeDelta": 122
},
{
"checkpoint": "cwv-lcp",
"value": 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"name": "Catalog",
"pattern": "https://www.aem.live/catalog/*",
"pageviews": 1200,
"organic": 300,
"organic": 400,
"metrics": [
{
"deviceType": "desktop",
"pageviews": 600,
"organic": 200,
"lcp": 40,
"lcpCount": 6,
"cls": 0.3,
Expand All @@ -21,6 +22,7 @@
{
"deviceType": "mobile",
"pageviews": 600,
"organic": 200,
"lcp": 40,
"lcpCount": 6,
"cls": 0.3,
Expand All @@ -41,6 +43,7 @@
{
"deviceType": "desktop",
"pageviews": 500,
"organic": 200,
"lcp": 40,
"lcpCount": 5,
"cls": 0.2,
Expand All @@ -53,6 +56,7 @@
{
"deviceType": "mobile",
"pageviews": 500,
"organic": 100,
"lcp": 40,
"lcpCount": 5,
"cls": 0.2,
Expand All @@ -68,11 +72,12 @@
"type": "url",
"url": "https://www.aem.live/catalog/product-2",
"pageviews": 200,
"organic": 0,
"organic": 100,
"metrics": [
{
"deviceType": "desktop",
"pageviews": 100,
"organic": 0,
"lcp": 30,
"lcpCount": 1,
"cls": 0.3,
Expand All @@ -85,6 +90,7 @@
{
"deviceType": "mobile",
"pageviews": 100,
"organic": 100,
"lcp": 30,
"lcpCount": 1,
"cls": 0.3,
Expand Down
Loading

0 comments on commit 50e93b9

Please sign in to comment.