diff --git a/packages/marko-web-native-x/utils/gtm-events.js b/packages/marko-web-native-x/utils/gtm-events.js index d17b9d6de..c523d4835 100644 --- a/packages/marko-web-native-x/utils/gtm-events.js +++ b/packages/marko-web-native-x/utils/gtm-events.js @@ -1,19 +1,19 @@ export const pageLoad = (window) => { - const dataLayer = window.dataLayerNativeX || []; - dataLayer.push({ event: 'page_load' }); + const dataLayer = window.dataLayerNativeX; + if (dataLayer) dataLayer.push({ event: 'page_load' }); }; export const outboundLink = (window, url) => { - const dataLayer = window.dataLayerNativeX || []; - dataLayer.push({ event: 'outbound_click', outbound_url: url, eventTimeout: 3000 }); + const dataLayer = window.dataLayerNativeX; + if (dataLayer) dataLayer.push({ event: 'outbound_click', outbound_url: url, eventTimeout: 3000 }); }; export const share = (window, provider) => { - const dataLayer = window.dataLayerNativeX || []; - dataLayer.push({ event: 'share', social_provider: provider }); + const dataLayer = window.dataLayerNativeX; + if (dataLayer) dataLayer.push({ event: 'share', social_provider: provider }); }; export const endOfContent = (window) => { - const dataLayer = window.dataLayerNativeX || []; - dataLayer.push({ event: 'scroll_to_bottom' }); + const dataLayer = window.dataLayerNativeX; + if (dataLayer) dataLayer.push({ event: 'scroll_to_bottom' }); };