elgorditosalsero / react-gtm-hook

Easily manage the Google Tag Manager via Hook
https://elgorditosalsero-react-gtm-hook.netlify.app/
MIT License
220 stars 28 forks source link

Inject dataLayer before GTM script #41

Closed cristianlivella closed 2 years ago

cristianlivella commented 2 years ago

By injecting the GTM script before the dataLayer, the userId in the state doesn't work in Google Analytics, as it is initialized before the id is set.

This way it seems to work correctly.

Reference: https://developers.google.com/tag-platform/tag-manager/web/datalayer#installation