Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

best way to add user_id #56

Open
MicahDavid opened this issue Oct 22, 2024 · 0 comments
Open

best way to add user_id #56

MicahDavid opened this issue Oct 22, 2024 · 0 comments

Comments

@MicahDavid
Copy link

MicahDavid commented Oct 22, 2024

Look for best way to add user_id to gtag config?

It doesn't seem possible to add the user_id inside nuxt.config.js like below, since I need the $auth object?

    'google-gtag': {
        id: 'G-XXXXXXX',
        config:{
            user_id: xxx
        },
    },

It does look like I can call the gtag config method elsewhere in my code. Will this accomplish the goal of tracking all page views with the user_id including the initial page view with the user_id?

      this.$gtag("config", "UA-XXXXXXX", {
        user_id: (this.$auth.loggedIn) ? this.$auth.$state.user.id : null,
      });

I am adding the above config call when the app header component is mounted. Please suggest if there is a better place to put this.

-- EDIT--
It looked like in the documentation, that instead of calling config twice, I should be calling the set method like this:

 this.$gtag('set','user_id',xxx)

This, however doesn't seem to work in analytics data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant