angular-google-analytics icon indicating copy to clipboard operation
angular-google-analytics copied to clipboard

Get and Set CliendId on configuration

Open lyvyu opened this issue 7 years ago • 9 comments

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 avatar Dec 09 '16 08:12 lyvyu

Sorry, my bad, everything is ok!

lyvyu avatar Dec 09 '16 10:12 lyvyu

@lyvyu how did you do this:

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

using this library?

machulav avatar Jan 24 '17 13:01 machulav

@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       
       },
       ...
})

lyvyu avatar Jan 24 '17 13:01 lyvyu

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

machulav avatar Jan 24 '17 15:01 machulav

@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 ?

lyvyu avatar Jan 24 '17 15:01 lyvyu

@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.

machulav avatar Jan 24 '17 15:01 machulav

@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!

lyvyu avatar Jan 24 '17 15:01 lyvyu

@lyvyu thank you!

machulav avatar Jan 24 '17 15:01 machulav

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.

justinsa avatar Feb 03 '17 16:02 justinsa