johannschopplich / nuxt-gtag

🔸 Google Analytics & Ads integration made easy

Home Page:https://developers.google.com/tag-platform/gtagjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tracking events when gtag not set up

nandi95 opened this issue · comments

Environment

latest

Reproduction

set up module but don't set an id (happens in development)

Describe the bug

The module only sets up with dataLayer on the window when the id has been set.

if (!id)
return
window.dataLayer = window.dataLayer || []

The trackEvent etc expects the window.dataLayer to be set.

export function gtag(..._args: any[]) {
// eslint-disable-next-line prefer-rest-params
window.dataLayer!.push(arguments)
}

This should not have that assertion and should have a check for the existence of the id or the dataLayer.

Am I missing something?

Additional context

No response

Logs

No response

Thanks for pointing that out!