From ba6899a908c080dff8e98e0423d316d3c11b3476 Mon Sep 17 00:00:00 2001 From: "Mark J. Becker" Date: Thu, 11 Apr 2024 13:32:12 +0200 Subject: [PATCH] Add page view event --- .../acdl/schemas/eventForwardingContext.json | 17 ++++ scripts/acdl/schemas/page-view.json | 12 +++ .../schemas/storefrontInstanceContext.json | 77 +++++++++++++++++++ scripts/acdl/validate.js | 5 +- scripts/delayed.js | 8 +- scripts/scripts.js | 3 + 6 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 scripts/acdl/schemas/eventForwardingContext.json create mode 100644 scripts/acdl/schemas/page-view.json create mode 100644 scripts/acdl/schemas/storefrontInstanceContext.json diff --git a/scripts/acdl/schemas/eventForwardingContext.json b/scripts/acdl/schemas/eventForwardingContext.json new file mode 100644 index 0000000000..ba21059a6d --- /dev/null +++ b/scripts/acdl/schemas/eventForwardingContext.json @@ -0,0 +1,17 @@ +{ + "type": "object", + "properties": { + "eventForwardingContext": { + "type": "object", + "properties": { + "commerce": { + "type": "boolean" + }, + "aep": { + "type": "boolean" + } + }, + "additionalProperties": false + } + } +} \ No newline at end of file diff --git a/scripts/acdl/schemas/page-view.json b/scripts/acdl/schemas/page-view.json new file mode 100644 index 0000000000..d771059465 --- /dev/null +++ b/scripts/acdl/schemas/page-view.json @@ -0,0 +1,12 @@ +{ + "type": "object", + "properties": { + "event": { + "type": "string", + "const": "page-view" + } + }, + "required": [ + "event" + ] +} \ No newline at end of file diff --git a/scripts/acdl/schemas/storefrontInstanceContext.json b/scripts/acdl/schemas/storefrontInstanceContext.json new file mode 100644 index 0000000000..0209ff1086 --- /dev/null +++ b/scripts/acdl/schemas/storefrontInstanceContext.json @@ -0,0 +1,77 @@ +{ + "type": "object", + "properties": { + "storefrontInstanceContext": { + "type": "object", + "properties": { + "environmentId": { + "type": "string" + }, + "instanceId": { + "type": "string" + }, + "environment": { + "type": "string", + "enum": ["prod", "non-prod"] + }, + "storeUrl": { + "type": "string" + }, + "websiteId": { + "type": "number" + }, + "websiteCode": { + "type": "string" + }, + "storeId": { + "type": "number" + }, + "storeCode": { + "type": "string" + }, + "storeViewId": { + "type": "number" + }, + "storeViewCode": { + "type": "string" + }, + "websiteName": { + "type": "string" + }, + "storeName": { + "type": "string" + }, + "storeViewName": { + "type": "string" + }, + "baseCurrencyCode": { + "type": "string" + }, + "storeViewCurrencyCode": { + "type": "string" + }, + "catalogExtensionVersion": { + "type": ["string", "null"] + }, + "storefrontTemplate": { + "type": "string", + "enum": ["Franklin"] + } + }, + "required": [ + "environmentId", + "environment", + "storeUrl", + "websiteId", + "storeId", + "storeViewId", + "websiteName", + "storeName", + "storeViewName", + "baseCurrencyCode", + "storeViewCurrencyCode" + ], + "additionalProperties": false + } + } +} \ No newline at end of file diff --git a/scripts/acdl/validate.js b/scripts/acdl/validate.js index 0a87bda00c..f965735467 100644 --- a/scripts/acdl/validate.js +++ b/scripts/acdl/validate.js @@ -6,6 +6,7 @@ const validator = new AcdlValidator(); // Add schemas const schemas = [ 'pageContext', + 'page-view', 'productContext', 'categoryContext', 'product-page-view', @@ -14,7 +15,9 @@ const schemas = [ 'recs-api-response-received', 'recs-item-click', 'recs-unit-impression-render', - 'recs-unit-view' + 'recs-unit-view', + 'storefrontInstanceContext', + 'eventForwardingContext', ]; (await Promise.all( schemas.map(async schema => { diff --git a/scripts/delayed.js b/scripts/delayed.js index 1f8687eb3c..769e0cd9c3 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -10,13 +10,13 @@ sampleRUM('cwv'); // Load Commerce events SDK and collector const config = { environmentId: await getConfigValue('commerce-environment-id'), - environment: await getConfigValue('commerce-environment'), + environment: await getConfigValue('commerce-environment') === 'Production' ? 'prod' : 'non-prod', storeUrl: await getConfigValue('commerce-store-url'), - websiteId: await getConfigValue('commerce-website-id'), + websiteId: parseInt(await getConfigValue('commerce-website-id'), 10), websiteCode: await getConfigValue('commerce-website-code'), - storeId: await getConfigValue('commerce-store-id'), + storeId: parseInt(await getConfigValue('commerce-store-id'), 10), storeCode: await getConfigValue('commerce-store-code'), - storeViewId: await getConfigValue('commerce-store-view-id'), + storeViewId: parseInt(await getConfigValue('commerce-store-view-id'), 10), storeViewCode: await getConfigValue('commerce-store-view-code'), websiteName: await getConfigValue('commerce-website-name'), storeName: await getConfigValue('commerce-store-name'), diff --git a/scripts/scripts.js b/scripts/scripts.js index 026635a6fb..5e362d0a43 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -108,6 +108,9 @@ async function loadEager(doc) { minYOffset: 0, }, }); + window.adobeDataLayer.push((dl) => { + dl.push({ event: 'page-view', eventInfo: { ...dl.getState() } }); + }); const main = doc.querySelector('main'); if (main) {