revolunet / angular-google-analytics

Google Analytics tracking for your AngularJS apps
MIT License
652 stars 179 forks source link

Get and Set CliendId on configuration #186

Open lyvyu opened 7 years ago

lyvyu commented 7 years ago

Hello,

I need to set clientId on analytics init but i don't understand how to get it.

Here is what i found in google docs:

Getting the client ID on the source domain

To retrieve a client ID on the source domain, you use the get method:

ga(function(tracker) {
  var clientId = tracker.get('clientId');
});
Once you have the client ID on the source domain, you can add it to links that point to the destination domain.

<a href="https://destination.com/?clientId=XXXXXX">destination.com</a>
Setting the client ID on the destination domain

You can tell a tracker object on the destination domain what client ID to use by specifying the client ID field in the create command:

ga('create', 'UA-XXXXX-Y', 'auto', {
  'clientId': getClientIdFromUrl()
});

So my question is How can i do this with this angular module ?

Thanks in advance.

lyvyu commented 7 years ago

Sorry, my bad, everything is ok!

machulav commented 7 years ago

@lyvyu how did you do this:

ga(function(tracker) {
  var clientId = tracker.get('clientId');
});

using this library?

lyvyu commented 7 years ago

@machulav in config, when you set up your GA account you have to set up object fields with key clientId: {value}, see example below:

AnalyticsProvider.setAccount({
       ...
       fields: {
         clientId: 12345 // here you set your client id       
       },
       ...
})
machulav commented 7 years ago

@lyvyu ok, I see, thank you! But how to get clientId using this library? Do you have such experience?

lyvyu commented 7 years ago

@machulav well if you want to retrieve you can reefer to window.ga object, but what exactly you want to achieve ? why do yo need clientId ?

machulav commented 7 years ago

@lyvyu I need to send clientId to GA in a custom dimension to achieve this goal: https://www.clickinsight.ca/about/blog/using-clientid-to-connect-multiple-visits

It would be preferable to get clientId using this library instead of using window.ga object. But in this library I can't find any property or function which return tracker object.

lyvyu commented 7 years ago

@machulav ok, I understood...unfortunately you can't do this with this library. In my case, I was supposed just to change default clientId with one that came from another site! Anyway you have to do this with window.ga instead! Good luck!

machulav commented 7 years ago

@lyvyu thank you!

justinsa commented 7 years ago

This seems like a reasonable feature addition to surface the clientId. I am re-opening this issue and updating it to be a feature request.