Set Google Analytics User ID after creating the tr

2019-03-11 02:53发布

The Google Analytics User ID documentation page shows that you set the User ID when you create the tracker. I have a javascript only project with sign-in after page load, is there any way to set the User ID after login? Something like ga("set", "userid", "UNIQUEID")

On the field reference page it says you can only set user-id in the create function. Are we able to call create again with the user-id? Will that create a new tracker, or override the old one?

EDIT: The beta version of User ID tracking showed that you could specify the userid after creating the tracker using ga('set', '&uid', {{ USER_ID }}); and that would try to unify the session from before the userid was set with the one after. That seems to be very different than what the docs current specify. Is there any way to do this with the current method?

5条回答
走好不送
2楼-- · 2019-03-11 03:30

You should set userId beofre sending event to Google Analytics. I couldn't manage to send userId after sending events pageview and ecommerce:send.

查看更多
老娘就宠你
3楼-- · 2019-03-11 03:40

The documentation seems to indicate that, with analytics.js, you should do the following:

// Alternatively, you may set the user ID via the `set` method.
ga('set', 'userId', 'as8eknlll');

I'm not sure how this differs from the current answer (which uses &uid), but this solution is working for us.

查看更多
smile是对你的礼貌
4楼-- · 2019-03-11 03:41

It appears from Justin Cutroni's blog that he's saying that data stitching (in your case matching the userid prior to login to the userid post-login) is not currently offered in Google Analytics.

http://cutroni.com/blog/2014/04/10/understanding-cross-device-measurement-and-the-user-id/

See specifically this sentence: "Google Analytics will not go back in time and stitch every single session from a given user together."

查看更多
可以哭但决不认输i
5楼-- · 2019-03-11 03:41

If you are using Google Tag Manager you can set the User ID by added '&uid' as a field to your Google Analytics Setting variable:

enter image description here

查看更多
Melony?
6楼-- · 2019-03-11 03:50

This one works

ga('set', '&uid', '<dynamic user id here>');
查看更多
登录 后发表回答