Skip to content

best way to add user_id #56

Description

@MicahDavid

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions