MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
863 stars 66 forks source link

Unable to get the clientId for multi site tracking #61

Closed giacomotorricelli closed 4 years ago

giacomotorricelli commented 4 years ago

I'm trying to implement the cross-domain measurement but I'm not able to access to the clientId

https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain

Am I doing something wrong?

MatteoGabriele commented 4 years ago

well that's the analytics.js library, this is the gtag.js one: the newest one. if you need to use analytics.js I can suggest you to use my other package vue-analytics, but with gtag you can also add your client id by passing it like this, for example

Vue.use(VueGtag, {
  config: {
    id: 'UA-12345678-9',
    params: { 
      client_id: 1234
    }
  }
})
giacomotorricelli commented 4 years ago

Thanks @MatteoGabriele for you reply.

I was probably watching at the wrong documentation, anyway I also tried with the linker configuration of gtag but it doesn't seems to work.

https://developers.google.com/analytics/devguides/collection/gtagjs/cross-domain#configuring_a_site_to_accept_linker_parameters

That's my really simple implementation on the source site:

Vue.use(VueGtag, {
    config: {id: "UA-1234567-89"},
    pageTrackerScreenviewEnabled: true,
    'linker': {
        'domains': ['target.domain']
    }
}, router);

As written in the documentation the parameters should be added dynamically from the library anyway it doesn't seems to work

When configured and running, gtag.js will listen for selections on links that point to the destination domain (or domains), and it will automatically add the linker parameter to those links immediately prior to navigation starting. (Waiting until a user clicks a link to add the linker parameter is necessary because linker parameters expire after two minutes.)

MIght be an implementation issue or an incompatibility with the SPA.

MatteoGabriele commented 4 years ago

everything you want to add as a configuration, needs to be inside the config.params object. that will be attached to the config call, right now you are just passing a plugin option that doesn't exist. I should probably try to explain this in the doc a bit more clearly

try something like this

Vue.use(VueGtag, {
  config: {
    id: "UA-1234567-89",
    params: { 
      linker: {
        domains: ['target.domain']
      }
    }
  },
  pageTrackerScreenviewEnabled: true
}, router);
giacomotorricelli commented 4 years ago

Thanks @MatteoGabriele, I did not understand correctly. With the params parameter it works as expected.