开发者

Help with GATC and var _gaq = _gaq || [];

开发者 https://www.devze.com 2023-03-28 16:20 出处:网络
Here is my GATC. It is located in the FOOTER of my application. <script type=\"text/javascript\">

Here is my GATC. It is located in the FOOTER of my application.

<script type="text/javascript">
   var _gaq = _gaq || [];

  _gaq.push(['_setAccount', 'UA-XXX-XX']);
  _gaq.push(['_setDomainName', 'mysite.com']);
  _gaq.push(['_addIgnoredRef', 'mysite.com']);
  _gaq.push(['_setCustomVar',1,'UserType','Visitor', 2]);
  _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>

开发者_C百科If I want to set some new custom variables in the BODY page, how would I do that?

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setCustomVar',2,'NewVar','Name', 2]);
</script>

Or

<script type="text/javascript">
    _gaq.push(['_setCustomVar',2,'NewVar','Name', 2]);
</script>

To summarize:

I need to define some custom variables in the body of a page and my GATC is in the footer. I'm not quite sure the meaning of _gaq = _gaq and how it will effect this. Should it be in the snippet to define the custom variable in the body and then again in the GATC in the footer?


var _gaq = _gaq || [];

This line uses existing _gaq array or creates a new one and assigns to _gaq if it hasn't been defined(or contains falsy value). Therefore your first option (containing _gaq assignment) is better.

0

精彩评论

暂无评论...
验证码 换一张
取 消