简体   繁体   中英

_gaq.push Not Working

Here is my piece of code in head.php

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-*******-*']);
  _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>

And here is another piece of code:

<a href="tel:8976414707" class="order_btn order_btn_phone" onclick="_gaq.push(['_trackEvent', 'ClickToCall', 'CallRequest', 'Mobile', false]);">Order by Phone</a>

So the thing is I have to work on already built website and this code part of code is not working. Google analytics is totally new part for me.

So can anyone help me to know this code works and what are the mistakes?

It looks like your pageview should be working, however your event is incorrect - you're passing a boolean as the event value when a number is expected. If you want to pass nothing as an event value, you can use undefined . However, you could just pass the event category, action, and label, as the last argument (non-interaction) is, by default, false .

With undefined :

_gaq.push(['_trackEvent', 'ClickToCall', 'CallRequest', 'Mobile', undefined, false]);

Without event value and event non-interaction:

_gaq.push(['_trackEvent', 'ClickToCall', 'CallRequest', 'Mobile']);

More info Event Tracking - Web Tracking (ga.js)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM