From 70b61f35a4af5dff45100235fc64fd19d960c531 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Mon, 31 Jul 2023 17:23:17 -0700 Subject: [PATCH 1/2] feat: track hemingway info on click events --- express/scripts/instrument.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/express/scripts/instrument.js b/express/scripts/instrument.js index a75a78903..b750113d6 100644 --- a/express/scripts/instrument.js +++ b/express/scripts/instrument.js @@ -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'); @@ -727,6 +742,15 @@ loadScript(martechURL, () => { sendTimestamp: new Date().getTime(), }, }, + ...(hemingwayAsset + ? { + hemingway: { + assetId: hemingwayAssetId, + assetPath: hemingwayAssetPath, + assetPosition: hemingwayAssetPosition, + }, + } + : {}), }, }, }, From bf305d31425c56eda6be6b01ed52896ce7f7fdd8 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Mon, 31 Jul 2023 17:26:04 -0700 Subject: [PATCH 2/2] feat: track hemingway info on click events --- express/scripts/instrument.js | 1 + express/scripts/scripts.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/express/scripts/instrument.js b/express/scripts/instrument.js index b750113d6..8c3b92f7e 100644 --- a/express/scripts/instrument.js +++ b/express/scripts/instrument.js @@ -1260,6 +1260,7 @@ loadScript(martechURL, () => { hemingway: { assetId: evt.assetId, assetPath: evt.assetPath, + assetPosition: evt.assetPosition, }, }, }, diff --git a/express/scripts/scripts.js b/express/scripts/scripts.js index 9a60e6174..86eaa7052 100644 --- a/express/scripts/scripts.js +++ b/express/scripts/scripts.js @@ -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