Hi there! I’m trying to integrate the Google Tag inside my app using the Web Pixel app extension, however when i test the pixel, I get an error in the console saying:
worker.modern.js:3 Uncaught (in promise) ReferenceError: window is not defined
at Object.<anonymous> (worker.modern.js:3:339)
However, when I insert the same code manually using the “Customer Events” tab in the store settings, everything seems to work fine. Both of these supposedly run in the same sandbox, so I’m not sure why it works on only the manually configured pixel and not the one created by my app. What can I do in this case? Below is the code in question.
import {register} from "@shopify/web-pixels-extension";
register(({ configuration, analytics, browser , settings}) => {
const tagID = settings.tagID;
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
const googleTagScript = document.createElement('script');
googleTagScript.async = true;
googleTagScript.src="https://www.googletagmanager.com/gtag/js?id=AW-" + tagID;
document.head.appendChild(googleTagScript);
gtag('js', new Date());
gtag('config', 'AW-' + tagID);
});