Code:
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '<?php echo $this->id; ?>');
ga('require', 'linker');
ga('linker:autoLink', ['<?php echo $this->setDomainName; ?>']); // Domains that are linked from this page.
<?php if ($this->anonymizeIp): // add JS code for anonymize the IP Address from own settings or from global settings ?>
ga('set', 'anonymizeIp', true);
<?php endif; ?>
<?php if ($this->bounceseconds): // add JS to "define" bounce rate by sending an event (hack, see http://padicode.com/blog/analytics/the-real-bounce-rate/) ?>
setTimeout('ga(\'send\', {\'hitType\': \'event\', \'eventCategory\': \'bounce\', \'eventAction\': \'NoBounce\', \'eventValue\': \'Over <?php echo $this->bounceseconds; ?> seconds\'});',
<?php echo $this->bounceseconds * 1000; ?>);
<?php endif; ?>
<?php if ($this->addlinktracking): /* add JS code to track all external links */ ?>
if (typeof jQuery != 'undefined') {
var filetypes = /\.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
var hrefRedirect = '';
jQuery('body').on('click', 'a', function(event) {
var el = jQuery(this);
var track = true;
var href = (typeof(el.attr('href')) != 'undefined' ) ? el.attr('href') : '';
var isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]);
if (!href.match(/^javascript:/i)) {
var elEv = []; elEv.value=0, elEv.non_i=false;
if (href.match(/^mailto\:/i)) {
elEv.category = 'email';
elEv.action = 'click';
elEv.label = href.replace(/^mailto\:/i, '');
elEv.loc = href;
}
else if (href.match(filetypes)) {
var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
elEv.category = 'download';
elEv.action = 'click-' + extension[0];
elEv.label = href.replace(/ /g,'-');
elEv.loc = baseHref + href;
}
else if (href.match(/^https?\:/i) && !isThisDomain) {
elEv.category = 'external';
elEv.action = 'click';
elEv.label = href.replace(/^https?\:\/\//i, '');
elEv.non_i = true;
elEv.loc = href;
}
else if (href.match(/^tel\:/i)) {
elEv.category = 'telephone';
elEv.action = 'click';
elEv.label = href.replace(/^tel\:/i, '');
elEv.loc = href;
}
else track = false;
if (track) {
var ret = true;
if((elEv.category == 'external' || elEv.category == 'download') && (el.attr('target') == undefined || el.attr('target').toLowerCase() != '_blank') ) {
hrefRedirect = elEv.loc;
ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
'nonInteraction': elEv.non_i ,
'hitCallback':gaHitCallbackHandler
});
ret = false;
}
else {
ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
'nonInteraction': elEv.non_i
});
}
return ret;
}
}
});
gaHitCallbackHandler = function() {
window.location.href = hrefRedirect;
}
}
<?php endif; ?>
ga('send', 'pageview');
</script>
Bookmarks