Each of my registered clients have an unique account ID (eg: agent n°: 00173393).
I want to retrieve this information through google analytics... It's not a personal information and for statistics use only.
I implemented userID, but how to match userID and the accounts IDs ?
Is it possible to create a variable for the account ID number ?
Why don't you use the account ID
as User ID
as well? That way you would have a 1-to-1 match:
ga('create', 'UA-XXXXX-Y', 'auto', {
userId: accountId
});
Please note however that the User ID
is not exposed back by Google Analytics. If you want to retrieve it, you need to save it inside a custom dimension:
- Admin -> Property -> Custom Dimensions -> Create one with User scope
- Add custom dimension tracking to your code
For instance:
ga('create', 'UA-XXXXX-Y', 'auto', {
userId: accountId,
});
ga('set', 'cd1', accountId); // if it's custom dimension n1
ga('send', 'pageview');
Then you can retrieve the User ID
via the UI:
or the API