Skip to content

Commit b4f3601

Browse files
authored
Deploy to main: PM-806: Add DL fallback for cta_locations (#311)
* PM-806: Add DL fallback for cta_locations * PM-806: Add pumpkin wellness default cta_location
1 parent b46948b commit b4f3601

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

blocks/header/header.js

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ function instrumentTrackingEvents(header) {
299299
// track cta clicks on header
300300
if (e.target.classList.contains('button')) {
301301
trackGTMEvent('cta_click', {
302+
cta_location: 'header_cta',
302303
link_text: linkText,
303304
link_url: linkUrl,
304305
});

scripts/scripts.js

+43-6
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,10 @@ function instrumentTrackingEvents(main) {
314314
ctaLocation = 'pick_your_plan';
315315
} else if (e.target.closest('.curated-products-pumpkin-wellness')) {
316316
ctaLocation = 'join_the_club_footer';
317+
} else {
318+
ctaLocation = 'join_the_club_banner';
317319
}
318320
trackCTAEvent(ctaLocation);
319-
320321
// track .button cta clicks for paid pages
321322
} else if (body.className.includes('paid')) {
322323
if (e.target.closest('.hero-paid-membership')) {
@@ -335,17 +336,53 @@ function instrumentTrackingEvents(main) {
335336
ctaLocation = 'body_1_cta';
336337
} else if (e.target.closest('.callout-get-a-quote2')) {
337338
ctaLocation = 'body_2_cta';
339+
} else {
340+
const containerBlock = e.target.closest('[data-block-name]');
341+
// if containerBlock is null, fallback to sections
342+
if (containerBlock) {
343+
const blockList = document.querySelectorAll(`[data-block-name=${containerBlock.dataset.blockName}]`);
344+
blockList.forEach((block, key) => {
345+
if (block === containerBlock) {
346+
ctaLocation = `${containerBlock.dataset.blockName}_${key}`;
347+
}
348+
});
349+
} else {
350+
// check for the closest section
351+
const parentSection = e.target.closest('.section');
352+
if (parentSection) {
353+
const sectionList = document.querySelectorAll('.section');
354+
sectionList.forEach((section, key) => {
355+
if (section === parentSection) {
356+
ctaLocation = `section_${key}`;
357+
}
358+
});
359+
}
360+
}
338361
}
339362
trackCTAEvent(ctaLocation);
340363
return;
341364
} else {
342365
const containerBlock = e.target.closest('[data-block-name]');
343-
const blockList = document.querySelectorAll(`[data-block-name=${containerBlock.dataset.blockName}]`);
344-
blockList.forEach((block, key) => {
345-
if (block === containerBlock) {
346-
ctaLocation = `${containerBlock.dataset.blockName}_${key}`;
366+
// if containerBlock is null, fallback to sections
367+
if (containerBlock) {
368+
const blockList = document.querySelectorAll(`[data-block-name=${containerBlock.dataset.blockName}]`);
369+
blockList.forEach((block, key) => {
370+
if (block === containerBlock) {
371+
ctaLocation = `${containerBlock.dataset.blockName}_${key}`;
372+
}
373+
});
374+
} else {
375+
// check for the closest section
376+
const parentSection = e.target.closest('.section');
377+
if (parentSection) {
378+
const sectionList = document.querySelectorAll('.section');
379+
sectionList.forEach((section, key) => {
380+
if (section === parentSection) {
381+
ctaLocation = `section_${key}`;
382+
}
383+
});
347384
}
348-
});
385+
}
349386
trackCTAEvent(ctaLocation);
350387
return;
351388
}

0 commit comments

Comments
 (0)