Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

feat: track asset position as part of hemingway events #949

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions express/scripts/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,21 @@ loadScript(martechURL, () => {
let adobeEventName = 'adobe.com:express:cta:';
let sparkEventName;
let sparkButtonId;
let hemingwayAssetId;
let hemingwayAssetPath;
let hemingwayAssetPosition;

const hemingwayAsset = $a.querySelector('picture,video,audio,img');
if (hemingwayAsset) {
// Get asset details
const assetPath = hemingwayAsset.currentSrc // the active source in the element
|| hemingwayAsset.src; // the source for an image/video/iframe
hemingwayAssetPath = new URL(assetPath).pathname;
const match = assetPath.match(/media_([a-f0-9]+)\.\w+/);
hemingwayAssetId = match ? match[0] : assetPath;
const siblings = [...$a.closest('.block').querySelectorAll(`.${$a.className.split(' ').join('.')}`)];
hemingwayAssetPosition = siblings.indexOf($a);
}

const $templateContainer = $a.closest('.template-list');
const $tutorialContainer = $a.closest('.tutorial-card');
Expand Down Expand Up @@ -727,6 +742,15 @@ loadScript(martechURL, () => {
sendTimestamp: new Date().getTime(),
},
},
...(hemingwayAsset
? {
hemingway: {
assetId: hemingwayAssetId,
assetPath: hemingwayAssetPath,
assetPosition: hemingwayAssetPosition,
},
}
: {}),
},
},
},
Expand Down Expand Up @@ -1236,6 +1260,7 @@ loadScript(martechURL, () => {
hemingway: {
assetId: evt.assetId,
assetPath: evt.assetPath,
assetPosition: evt.assetPosition,
},
},
},
Expand Down
4 changes: 4 additions & 0 deletions express/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,14 @@ function trackViewedAssetsInDataLayer(assetsSelector = 'img[src*="/media_"]') {
assetPath = new URL(assetPath).pathname;
const match = assetPath.match(/media_([a-f0-9]+)\.\w+/);
const assetFilename = match ? match[0] : assetPath;
const siblings = el.className
? [...el.closest('.block').querySelectorAll(`.${el.className.split(' ').join('.')}`)]
: [];
const details = {
event: 'viewasset',
assetId: assetFilename,
assetPath,
assetPosition: siblings.indexOf(el),
};

// Add experiment details
Expand Down