javascript - How to obtain Google Analytics visitor unique id? - Stack Overflow

I know that second value after splitting __utma cookie is a visitor unique id. How can I obtain that in

I know that second value after splitting __utma cookie is a visitor unique id. How can I obtain that in proper way? Something like this: var uid = _ga.visitor.getUid();

I know that second value after splitting __utma cookie is a visitor unique id. How can I obtain that in proper way? Something like this: var uid = _ga.visitor.getUid();

Share Improve this question edited Nov 28, 2013 at 16:07 Robert 5,31043 gold badges68 silver badges115 bronze badges asked Nov 26, 2012 at 14:27 Ivan VelichkoIvan Velichko 6,7197 gold badges49 silver badges97 bronze badges 2
  • You should add to the question why you want to get this number. This is a random id used internally by Google Analytics. This number is not available on GA interface. Hard to think about a real use case to use it. – Eduardo Commented Nov 26, 2012 at 14:54
  • Payment transaction starts on web site (frontend), this event tracked successful. But thus transaction ends on backend (when payment system callback us). Not in all times we have thus events trackend from frontend. Hence we want use php GA framework to push events to GA directly from backend. – Ivan Velichko Commented Nov 26, 2012 at 15:30
Add a ment  | 

3 Answers 3

Reset to default 5
_gaq.push(function(){
  var tracker = _gat._getTrackers()[0];
  var visit_code = tracker._visitCode();

  console.log(visit_code);
});

UPDATE

_visitCode() is an undocumented method but it has been around for at least one year as far as I know. My guess is that Google will not get rid of it, since it's concentrating it's new efforts on implementing Universal Analytics that has a different approach.

The 2 options you have here is to either use this undocumented method or fiddle with a cookie that also has an undocumented format. So both are somewhat unreliable.

On the time of this posting Universal Analytics is still in beta.

As per this: https://developers.google./analytics/devguides/collection/gajs/methods/gaJSApi_gat#_gat._getTrackerByName

Getting the tracker:

var tracker = _gat._getTrackerByName();

Now get the visit code:

var visitcode = tracker._visitCode();

Or one liner:

var visitcode = _gat._getTrackerByName()._visitCode();

I think the proper and only way is to split the __utma cookie as you say. Since you may and can assume the second value always is the id this is pretty safe

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744890756a4599398.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信