Skip to content

Commit

Permalink
Merge pull request #211 from spring-media/TRAC-2029_brandstory_and_sc…
Browse files Browse the repository at this point in the history
…rolldepth

Fixed brandstory milestones missing data issues
  • Loading branch information
mehakraza authored May 17, 2024
2 parents 23abc6a + ad5fd80 commit b63f5b1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion extensions/brandstory/brandstory_milestones.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ window.onload = function setMilestones() {

milestones.forEach(milestone => {
setTimeout(() => {
window.utag.link({ event_name: 'article_milestone', event_label: milestone.label }, null, tagNumber);
window.utag.link({
event_name: 'article_milestone',
event_label: milestone.label,
adobe_pageName: window.utag.data.adobe_pageName,
page_escenicId: window.utag.data.page_escenicId,
page_platform: window.utag.data.page_platform,
page_type: window.utag.data.page_type,
page_sectionPath: window.utag.data.page_sectionPath
}, null, tagNumber);
}, milestone.time);
});
};
44 changes: 31 additions & 13 deletions extensions/brandstory/brandstory_scrolldepth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ function getDomainTagValue(domain) {
}
}

// Function to send link event
function sendLinkEvent(scrollDepth, platform, pageName, tagNumber) {
window.utag.link({
'event_name': 'scroll depth',
'event_action': 'view' + scrollDepth,
'page_platform': platform,
'adobe_pageName': pageName,
}, null, tagNumber);
}

// Array to store scroll depths
const scrollArray = [];

Expand All @@ -37,18 +47,26 @@ window.addEventListener('scroll', function () {
// Get domain-specific tag number
const tagNumber = getDomainTagValue(window.location.hostname);

// Check scroll depth
if (scrollDepth <= 100) {
// Check if scroll depth is 50, 75 or 100
if (scrollDepth === 50 || scrollDepth === 75 || scrollDepth === 100) {
scrollArray.push(scrollDepth);
// Send data to utag
window.utag.link({
'event_name': 'scroll depth',
'event_action': 'view' + scrollDepth,
'page_platform': window.utag.data.page_platform,
'adobe_pageName': window.utag.data.adobe_pageName,
}, null, tagNumber);
}
/* If scroll depth is 50, 75 or 100 the request should be triggered once
for each number. To prevent multiple requests for each, we set trigger flags */
var triggered50, triggered75, triggered100 = false;

if (!triggered50 && scrollDepth === 50) {
triggered50 = true;
scrollArray.push(scrollDepth);
// Send data to utag
sendLinkEvent(scrollDepth, window.utag.data.page_platform, window.utag.data.adobe_pageName, tagNumber);
}
else if (!triggered75 && scrollDepth === 75) {
triggered75 = true;
scrollArray.push(scrollDepth);
// Send data to utag
sendLinkEvent(scrollDepth, window.utag.data.page_platform, window.utag.data.adobe_pageName, tagNumber);
}
else if (!triggered100 && scrollDepth === 100) {
triggered100 = true;
scrollArray.push(scrollDepth);
// Send data to utag
sendLinkEvent(scrollDepth, window.utag.data.page_platform, window.utag.data.adobe_pageName, tagNumber);
}
});

0 comments on commit b63f5b1

Please sign in to comment.