Skip to content

Commit

Permalink
remove old gtag code
Browse files Browse the repository at this point in the history
  • Loading branch information
romgere committed Oct 24, 2023
1 parent 4184095 commit cee7878
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 5 additions & 3 deletions app/initializers/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}

Expand All @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions app/routes/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down

0 comments on commit cee7878

Please sign in to comment.