Tracking external links with Google Analytics trackPageview () does not work

I set tracking of external links as Goals in Google Analytics in accordance with the GA documentation .

Here is the page: http://playmoreatthey.org/ - external links on the page are formatted, for example

<a href="http://www.ymcagreaterprovidence.org/Default.aspx?alias=www.ymcagreaterprovidence.org/baysidebranch" onclick="javascript: pageTracker._trackPageview('/G1/bayside_family.com');" target="_blank">Bayside Family YMCA</a>

I set the target as a "head match" with the url: /G1/bayside_family.com

I checked four days later and there are no results for the purposes or page views for the fake "pagename" (/G1/bayside_family.com) specified in the JavaScript attached to each external link.

+3
source share
3 answers

, GA _gaq.push(...), onclick , "" .

onclick="_gaq.push(['_trackPageview','/G1/bayside_family.com']);"
+6

jQuery, , script:

// Outbound Link Tracking with Google Analytics
// Requires jQuery 1.7 or higher (use .live if using a lower version)
$("a").on('click', function(e){
    var url = $(this).attr("href");
    if($.trim(url).indexOf("javascript:") == 0) return;
    if (e.currentTarget.host != window.location.host) {
        _gaq.push(['_trackEvent', 'Outbound Links', e.currentTarget.host, url, 0]);
        var target = $(this).attr("target");
        if (e.metaKey || e.ctrlKey || target == "_blank") {
             var newtab = true;
        }
        if (!newtab) {
             e.preventDefault();
            if(target) {
               setTimeout('window.open("' + url + '", "' + target + '");', 100);
            } else {
               setTimeout('document.location = "' + url + '"', 100);
            }
        }
    }
});

script : http://wptheming.com/2012/01/tracking-outbound-links-with-google-analytics/comment-page-1/#comment-39716

, script.

script, javascript (aka href="javascript:..."). , target.

jsFiddle, script: http://jsfiddle.net/luisperezphd/45NPe/

+3

One of the recommended ways to do this is through Events. Thus, the metric of your page will not be inflated by virtual pageviews tracked using the method _trackPageview.

http://support.google.com/analytics/bin/answer.py?hl=en&answer=1136920

I am adding this as an answer because the Crayon Violent comment above contains a broken link. At least someone will be able to edit this answer if the link should change again in the future.

0
source

Source: https://habr.com/ru/post/1787804/


All Articles