diff --git a/app/initializers/gtag.ts b/app/initializers/gtag.ts index d8969c2..c73c6e5 100644 --- a/app/initializers/gtag.ts +++ b/app/initializers/gtag.ts @@ -2,7 +2,9 @@ import config from 'text2stl/config/environment'; const { gTag, environment } = config; export function initialize() { - if (!gTag.forceEnable && ['development', 'test'].includes(environment)) { + if (!gTag?.forceEnable && ['development', 'test'].includes(environment)) { + return; + } else if (!gTag?.tag) { return; } @@ -12,7 +14,7 @@ export function initialize() { async function injectGtag() { const script = document.createElement('script'); - script.setAttribute('src', `https://www.googletagmanager.com/gtag/js?id=${gTag.tag}`); + script.setAttribute('src', `https://www.googletagmanager.com/gtag/js?id=${gTag?.tag}`); document.body.appendChild(script); } @@ -22,7 +24,7 @@ function initGtag() { window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); - gtag('config', '${gTag.tag}'); + gtag('config', '${gTag?.tag}'); `; // Append the script tag to the document. diff --git a/app/routes/app.ts b/app/routes/app.ts index 3fb4b68..d855e1c 100644 --- a/app/routes/app.ts +++ b/app/routes/app.ts @@ -13,13 +13,10 @@ export default class AppRoute extends Route { @service declare intl: IntlService; @service declare router: Services['router']; @service declare fontManager: FontManagerService; - @service declare gtag: GTagService; constructor(props: object | undefined) { super(props); this.router.on('routeDidChange', (transition: Transition) => this.updateMeta(transition)); - // Jut get the gtatg service to trigger Google script injection - this.gtag; } async model({ locale }: { locale: string }) {