diff --git a/packages/spacecat-shared-rum-api-client/src/functions/form-vitals.js b/packages/spacecat-shared-rum-api-client/src/functions/form-vitals.js index f2738f9d..42178c1b 100644 --- a/packages/spacecat-shared-rum-api-client/src/functions/form-vitals.js +++ b/packages/spacecat-shared-rum-api-client/src/functions/form-vitals.js @@ -14,7 +14,7 @@ import { DataChunks } from '@adobe/rum-distiller'; import { generateKey, DELIMITER, loadBundles } from '../utils.js'; const FORM_SOURCE = ['.form', '.marketo', '.marketo-form']; -const METRICS = ['formview', 'formengagement', 'formsubmit', 'formbuttonclick']; +const METRICS = ['formview', 'formengagement', 'formsubmit', 'formbuttonclick', 'bounces']; function initializeResult(url) { return { @@ -24,6 +24,7 @@ function initializeResult(url) { formengagement: {}, formbuttonclick: {}, pageview: {}, + bounces: {}, }; } @@ -46,10 +47,16 @@ const metricFns = { && /\bbutton\b/.test(e.source.toLowerCase())); return formButtonClick ? bundle.weight : 0; }, + bounces: (bundle) => { + const bounces = (bundle.visit && !bundle.events.find(({ checkpoint }) => checkpoint === 'click') + ? bundle.weight : 0); + return bounces; + }, }; function containsFormVitals(row) { - return METRICS.some((metric) => Object.keys(row[metric]).length > 0); + return METRICS.filter((metric) => metric !== 'bounces') + .some((metric) => Object.keys(row[metric]).length > 0); } function handler(bundles) { diff --git a/packages/spacecat-shared-rum-api-client/test/fixtures/bundles-for-form-vitals.json b/packages/spacecat-shared-rum-api-client/test/fixtures/bundles-for-form-vitals.json index b605dca8..e3f69b80 100644 --- a/packages/spacecat-shared-rum-api-client/test/fixtures/bundles-for-form-vitals.json +++ b/packages/spacecat-shared-rum-api-client/test/fixtures/bundles-for-form-vitals.json @@ -2831,6 +2831,7 @@ "url": "https://business.adobe.com/jp/products/magento/magento-commerce.html", "userAgent": "desktop:linux", "weight": 100, + "visit": true, "events": [ { "checkpoint": "viewblock", diff --git a/packages/spacecat-shared-rum-api-client/test/fixtures/expected-form-vitals-result.json b/packages/spacecat-shared-rum-api-client/test/fixtures/expected-form-vitals-result.json index ba5ab1c0..1dde2d8a 100644 --- a/packages/spacecat-shared-rum-api-client/test/fixtures/expected-form-vitals-result.json +++ b/packages/spacecat-shared-rum-api-client/test/fixtures/expected-form-vitals-result.json @@ -17,6 +17,9 @@ "desktop:linux": 2200, "desktop:mac": 100, "desktop:windows": 100 + }, + "bounces": { + "desktop:linux": 100 } }, { @@ -38,6 +41,9 @@ "desktop:mac": 800, "mobile:android": 300, "mobile:ios": 100 + }, + "bounces": { + } }, { @@ -57,6 +63,9 @@ "pageview": { "desktop:linux": 1600, "desktop:mac": 200 + }, + "bounces": { + } }, { @@ -77,6 +86,9 @@ "desktop:windows": 400, "mobile:android": 200, "mobile:ios": 100 + }, + "bounces": { + } }, { @@ -95,6 +107,9 @@ }, "pageview": { "desktop:windows": 200 + }, + "bounces": { + } }, { @@ -113,6 +128,9 @@ }, "pageview": { "desktop:windows": 100 + }, + "bounces": { + } }, { @@ -131,6 +149,9 @@ }, "pageview": { "desktop:windows": 100 + }, + "bounces": { + } }, { @@ -149,6 +170,9 @@ }, "pageview": { "desktop:windows": 100 + }, + "bounces": { + } }, { @@ -167,6 +191,9 @@ }, "pageview": { "desktop:mac": 100 + }, + "bounces": { + } }, { @@ -185,6 +212,9 @@ }, "pageview": { "desktop:windows": 100 + }, + "bounces": { + } }, { @@ -203,6 +233,9 @@ }, "pageview": { "desktop:mac": 100 + }, + "bounces": { + } } ] \ No newline at end of file