diff --git a/app/initializers/gtag.ts b/app/initializers/gtag.ts index c73c6e5..4992786 100644 --- a/app/initializers/gtag.ts +++ b/app/initializers/gtag.ts @@ -3,8 +3,11 @@ const { gTag, environment } = config; export function initialize() { if (!gTag?.forceEnable && ['development', 'test'].includes(environment)) { + // Just define gtag function to prevent dev/test to fail + fakeGtag(); return; } else if (!gTag?.tag) { + console.error('no GTAG defined, skipping Gtag script load'); return; } @@ -31,6 +34,14 @@ function initGtag() { document.body.appendChild(script); } +function fakeGtag() { + const script = document.createElement('script'); + script.innerHTML = `function gtag(){}`; + + // Append the script tag to the document. + document.body.appendChild(script); +} + export default { initialize, }; diff --git a/config/environment.js b/config/environment.js index 16469e8..09cabf4 100644 --- a/config/environment.js +++ b/config/environment.js @@ -16,7 +16,7 @@ module.exports = function (environment) { gTag: { tag: 'G-47QBQ5GB3Y', - forceEnable: true, + // forceEnable: true, // For testing }, 'ember-toggle': {