简体   繁体   中英

Incognito/private browsing breaks links

We are tracking traffic using cross domain tracking via an onclick in our hrefs:

Analytics code:

<script type="text/javascript">
function trackOutboundLink(link, category, action) {
try {
_gaq.push(['_trackEvent', category , action]);
} catch(err){}
setTimeout(function() {
document.location.href = link.href;
}, 100);
}
var _gaq = _gaq || [];
var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-XXXXXXXXX']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_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>

HREF:

<a class="cta" href="https://www.otherdomain.com" onclick="_gaq.push(['_link', this.href]); return false;">

Tracking works perfectly for 99% of our visitors, but for those that are attempting to block tracking attempts (such as Firefox's private browsing feature), clicking the link just does nothing at all.

I'm not trying to force tracking on these visitors, but I'd still like the link to go to the proper location. Is there a way to correct this? At this time, we are unable to migrate over to Universal Analytics.

What's likely to be happening here is that private browsing is blocking the google analytics script from loading and is causing an error in your javascript so that the

document.location.href 

is not being reached.

To get this working more reliably, you could consider making an ajax request to a url on your server and write the analytics tracking code server side.

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