Last active
November 1, 2019 14:15
-
-
Save vimes1984/96b453127eff3715860b to your computer and use it in GitHub Desktop.
Track and push all a links for google anayltics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(document).ready(function() { | |
| jQuery("a").each(function() { | |
| var e = jQuery(this); | |
| var t = e.attr("href"); | |
| if (t == undefined || t == "") | |
| return; | |
| var n = t.replace("http://", "").replace("https://", ""); | |
| var r = t.split(".").reverse(); | |
| var i = r[0].toLowerCase(); | |
| var r = t.split("/").reverse(); | |
| var s = r[2]; | |
| var o = false; | |
| if (typeof analyticsFileTypes != "undefined") { | |
| if (jQuery.inArray(i, analyticsFileTypes) != -1) { | |
| o = true; | |
| e.click(function() { | |
| if (analyticsEventTracking == "enabled") { | |
| if (analyticsSnippet == "enabled") { | |
| _gaq.push(["_trackEvent", "Downloads", i.toUpperCase(), t]) | |
| } else { | |
| ga("send", "event", "Downloads", i.toUpperCase(), t) | |
| } | |
| } else { | |
| if (analyticsSnippet == "enabled") { | |
| _gaq.push(["_trackPageview", analyticsDownloadsPrefix + n]) | |
| } else { | |
| ga("send", "pageview", analyticsDownloadsPrefix + n) | |
| } | |
| } | |
| }) | |
| } | |
| } | |
| if (t.match(/^http/) && !t.match(document.domain) && o == false) { | |
| e.click(function() { | |
| if (analyticsEventTracking == "enabled") { | |
| if (analyticsSnippet == "enabled") { | |
| _gaq.push(["_trackEvent", "Outbound Traffic", t.match(/:\/\/(.[^/]+)/)[1], t]) | |
| } else { | |
| ga("send", "event", "Outbound Traffic", t.match(/:\/\/(.[^/]+)/)[1], t) | |
| } | |
| } else if (analyticsSnippet == "enabled") { | |
| _gaq.push(["_trackPageview", analyticsOutboundPrefix + n]) | |
| } else { | |
| ga("send", "pageview", analyticsOutboundPrefix + n) | |
| } | |
| }) | |
| } | |
| }) | |
| }) | |
| //Mailto links tracking | |
| jQuery('a[href^="mailto:"]').on('click', function(){ | |
| var getlinktype = jQuery(this).attr('href'); | |
| _gaq.push(["_trackEvent", "Mailto link clicked", getlinktype, ""]) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment