Closed matheusm closed 4 months ago
Hi there! Have you checked if that isn't already supported? See the multi-tenancy support guide:
You can even leave the Google tag ID in your Nuxt config blank and set it dynamically later in your application by passing your ID as the first argument to initialize. This is especially useful if you want to use a custom ID for each user or if your app manages multiple tenants.
const { gtag, initialize } = useGtag()
function acceptTracking() {
initialize('G-XXXXXXXXXX')
}
Yes, I saw it and tried to implement it, but I encountered some issues. @johannschopplich
Basically, the initialize function adds the script to the page, but it doesn't trigger the pageview base event. Is that correct?
Basically, the initialize function adds the script to the page, but it doesn't trigger the pageview base event. Is that correct?
Yes, it does and also initializes the dataLayer
object required for Gtag to work. A pageview event is not emitted by this Nuxt module; this is handled by Gtag and your Analytics configuration.
One suggestion I have is to enhance the current setup. While the ID and pageview event are initialized in nuxt.config, it would be beneficial to also handle this tracking directly within the initialize function if its possible
By the way, thanks for helping! Best regrads
While the ID and pageview event are initialized in nuxt.config, it would be beneficial to also handle this tracking directly within the initialize function if its possible.
Can't you call the event manually? I want to keep the behavior as opinionless, as possible:
initialize('G-XXXXXXXXXX')
useTrackEvent('pageview')
Excellent! I am in complete agreement. The inclusion of an illustrative example within the documentation would be quite advantageous. This addition would undoubtedly facilitate comprehension for all users.
Describe the feature
Hi team,
I would like to suggest an enhancement to the gtag configuration, allowing the ability to start with gtag disabled and then dynamically set the options later. This would provide more flexibility and control over the initialization process. Here's a proposed implementation:
In my case, user tags are only available when the component is rendered because I need to fetch this data from an API.
Thanks for considering this enhancement!
Best regards, Matheus Martins
Additional information
Final checks