Skip to content

Commit

Permalink
Properly implement allowed_pages in Hyva scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Sep 27, 2023
1 parent 3011c5d commit b444534
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Fixed
- Properly implement `allowed_pages` in Hyva scripts
- Make sure `minicart_collapse` is only there if cart event is allowed everywhere
- `Fatal error: Uncaught Error: Call to a member function getCarrierCode` (#192 @WGenie @bvmax)

Expand Down
10 changes: 3 additions & 7 deletions view/frontend/templates/hyva/script-additions.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ $commons = $block->getCommonsViewModel();

const gtmEvents = event.detail.data[sectionName].gtm_events;
for (const [eventId, eventData] of Object.entries(gtmEvents)) {
const metaData = eventData.meta;
const copyEventData = Object.assign({}, eventData);

if (metaData) {
delete copyEventData.meta;
}
yireoGoogleTagManager2Logger('found event in section "' + sectionName + '"', eventData);

yireoGoogleTagManager2Pusher(copyEventData, 'push (customerData "' + sectionName + '" event "' + eventId + '")');
const metaData = eventData.meta;
yireoGoogleTagManager2Pusher(eventData, 'push (customerData "' + sectionName + '" event "' + eventId + '")');

if (!metaData || metaData.cacheable !== true) {
yireoGoogleTagManager2Logger('removing event "' + eventId + '" from section "' + sectionName + '"')
Expand Down
8 changes: 8 additions & 0 deletions view/frontend/templates/hyva/script-pusher.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS = window.YIREO_GOOGLETAGMANAGER2_PAST_EVENTS || [];

const copyEventData = Object.assign({}, eventData);
let metaData = {};
if (copyEventData.meta) {
metaData = copyEventData.meta;
delete copyEventData.meta;
}

Expand All @@ -23,6 +25,12 @@
return;
}

if (metaData && metaData.allowed_pages && metaData.allowed_pages.length > 0
&& false === metaData.allowed_pages.includes(window.location.pathname)) {
yireoGoogleTagManager2Logger('Warning: Skipping event, not in allowed pages', window.location.pathname, eventData);
return;
}

if (!message) {
message = 'push (unknown) [unknown]';
}
Expand Down

0 comments on commit b444534

Please sign in to comment.