Skip to content

Commit

Permalink
Defined sendDataLayer (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Feb 20, 2024
1 parent 7f19ebe commit c1f9c6e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions resources/js/gtm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ let dataLayersPromise = (async () => {
})()

function sendDataLayer(func, ...args) {
if (!'dataLayer' in window) {
return
}

['ua', 'ga4'].forEach(layer => {
if(dataLayers?.[layer]?.[func]) {
dataLayers?.[layer]?.[func](...args);
}
})
}

window.sendDataLayer = sendDataLayer;

document.addEventListener('turbo:load', async (event) => {
if (!('dataLayer' in window)) {
return;
Expand Down

0 comments on commit c1f9c6e

Please sign in to comment.