From bf305d31425c56eda6be6b01ed52896ce7f7fdd8 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Mon, 31 Jul 2023 17:26:04 -0700 Subject: [PATCH] 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