Skip to content

Commit

Permalink
Ensure datalayer providers are imported before sending pageview events (
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Sep 7, 2023
1 parent 3e3d698 commit b4ae0f6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion resources/js/gtm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.removeTrailingZeros = (price) => parseFloat(parseFloat(price).toString());

(async () => {
let dataLayersPromise = (async () => {
// This async function is in order to work around "ERROR: Top-level await is not available" when building for older browsers.
window.dataLayers = {
ua: window.config.gtm['send-ua-events'] ? await import('./datalayer/ua.js') : undefined,
Expand All @@ -15,6 +15,7 @@ document.addEventListener('turbo:load', async (event) => {
if (window.config.gtm['clear-on-load']) {
window.dataLayer = []
}
await dataLayersPromise

let url = new URL(event.detail.url);

Expand Down

0 comments on commit b4ae0f6

Please # to comment.