最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论