Google Analytics pageTracker is not defined?

怎甘沉沦 提交于 2019-12-02 15:09:55

The new Async Google Analytics code (that you're using) works a bit differently than the non-Async. Any time that you want to call a method on pageTracker you simply push a "message" onto the "_gaq" queue.

<a href="mailto:hello@mydomain.co.uk" onClick="_gaq.push(['_trackPageview', '/mailto/hello'])">hello@mydomain.co.uk</a>

Although, tracking a mailto link may work better as an event:

<a href="mailto:hello@mydomain.co.uk" onClick="_gaq.push(['_trackEvent', 'mailto', 'home'])">hello@mydomain.co.uk</a>

For more info take a look at the Async Tracking Users Guide.

We can also add:

//mantain syntax between old and new asynch methods
//http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html#Syntax
function _pageTracker (type) {
    this.type = type;
    this._trackEvent = function(a,b,c) {
       _gaq.push(['_trackEvent', a, b, c]);
    };
}

var pageTracker = new _pageTracker();

in new code to mantain old code in pages.

Nanda

Here is the code :

onClick="_gaq.push(['_trackEvent', 'pdf', 'download', '/pdf/myPdf'])">myPdf</a>
Osura

I needed a way to tack downloading PDFs too and heres what I used:

<a href="http://www.domain.com/assets/downloads/filename.pdf" target="_blank" onClick="_gaq.push(['_trackEvent', 'Downloads', 'Download', 'Price Brochure PDF'])">Download Brochure</a>

For more info about _trackEvent, heres the API Doc page

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