Access previously stored Visitor-level custom variable

◇◆丶佛笑我妖孽 提交于 2019-12-04 19:49:40

There is _getVisitorCustomVar(index).

eg:

_gaq.push(function() {
  var pageTracker = _gat._getTrackerByName(); // Gets the default tracker.
  var visitorCustomVar1Value = pageTracker._getVisitorCustomVar(1);
});

It only works for Visitor level custom var because that's the only one stored client size in the GA cookie __utmz. But that's exactly what you are looking for I guess.

If you want to see if a non-visitor level custom var that has already been set, then you would need to write the logic yourself storing a separate cookie when you set the custom var to be able to retrieve later. But it should be a simple thing and probably better idea than hacking into proprietary cookies.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'xxxxxxxxxxxxxxx']);

   _gaq.push(function() {
        var pageTracker = _gat._getTrackerByName();
        var userTypeVar = pageTracker._getVisitorCustomVar(1);
    });

  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!