Skip to content

Commit

Permalink
Add basic RUM conversion tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
herzog31 committed Apr 16, 2024
1 parent 60e6882 commit ba71a79
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,26 @@ window.adobeDataLayer.push(
// Load events SDK and collector
import('./commerce-events-sdk.js');
import('./commerce-events-collector.js');

// Conversion tracking
function convert(event, value, extraData = {}) {
sampleRUM('convert', { source: event, target: value, ...extraData });
}

window.adobeDataLayer.push((dl) => {
dl.addEventListener('add-to-cart', ({ eventInfo }) => {
convert('addToCart', 'addToCart', eventInfo?.shoppingCartContext?.items?.map((item) => item.product.sku));
});

dl.addEventListener('create-account', () => {
convert('createAccount', 'createAccount');
});

dl.addEventListener('sign-in', () => {
convert('signIn', 'signIn');
});

dl.addEventListener('place-order', ({ eventInfo }) => {
convert('placeOrder', 'placeOrder', eventInfo.shoppingCartContext.items.map((item) => item.product.sku));
});
});

0 comments on commit ba71a79

Please sign in to comment.