Skip to content

Commit

Permalink
Add page view event
Browse files Browse the repository at this point in the history
  • Loading branch information
herzog31 committed Apr 11, 2024
1 parent e86b5ad commit ba6899a
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 5 deletions.
17 changes: 17 additions & 0 deletions scripts/acdl/schemas/eventForwardingContext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"type": "object",
"properties": {
"eventForwardingContext": {
"type": "object",
"properties": {
"commerce": {
"type": "boolean"
},
"aep": {
"type": "boolean"
}
},
"additionalProperties": false
}
}
}
12 changes: 12 additions & 0 deletions scripts/acdl/schemas/page-view.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "object",
"properties": {
"event": {
"type": "string",
"const": "page-view"
}
},
"required": [
"event"
]
}
77 changes: 77 additions & 0 deletions scripts/acdl/schemas/storefrontInstanceContext.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
5 changes: 4 additions & 1 deletion scripts/acdl/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const validator = new AcdlValidator();
// Add schemas
const schemas = [
'pageContext',
'page-view',
'productContext',
'categoryContext',
'product-page-view',
Expand All @@ -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 => {
Expand Down
8 changes: 4 additions & 4 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
3 changes: 3 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ba6899a

Please sign in to comment.