johannschopplich / nuxt-gtag

🔸 Google Analytics & Ads integration made easy
https://developers.google.com/tag-platform/gtagjs
MIT License
302 stars 9 forks source link

Tracking events when gtag not set up #24

Closed nandi95 closed 1 year ago

nandi95 commented 1 year ago

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. https://github.com/johannschopplich/nuxt-gtag/blob/d307c78bae140393b15034cd06d4958ef4f0e87c/src/runtime/plugin.client.ts#L9-L12

The trackEvent etc expects the window.dataLayer to be set. https://github.com/johannschopplich/nuxt-gtag/blob/d307c78bae140393b15034cd06d4958ef4f0e87c/src/runtime/gtag.ts#L1-L4

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

johannschopplich commented 1 year ago

Thanks for pointing that out!