1(function ($) { 2 3"use strict"; 4 5Backdrop.googleanalytics = {}; 6 7$(document).ready(function() { 8 9 // Attach mousedown, keyup, touchstart events to document only and catch 10 // clicks on all elements. 11 $(document.body).bind("mousedown keyup touchstart", function(event) { 12 13 // Catch the closest surrounding link of a clicked element. 14 $(event.target).closest("a,area").each(function() { 15 16 // Is the clicked URL internal? 17 if (Backdrop.googleanalytics.isInternal(this.href)) { 18 // Skip 'click' tracking, if custom tracking events are bound. 19 if ($(this).is('.colorbox')) { 20 // Do nothing here. The custom event will handle all tracking. 21 //console.info("Click on .colorbox item has been detected."); 22 } 23 // Is download tracking activated and the file extension configured for download tracking? 24 else if (Backdrop.settings.googleanalytics.trackDownload && Backdrop.googleanalytics.isDownload(this.href)) { 25 // Download link clicked. 26 ga("send", "event", "Downloads", Backdrop.googleanalytics.getDownloadExtension(this.href).toUpperCase(), Backdrop.googleanalytics.getPageUrl(this.href)); 27 } 28 else if (Backdrop.googleanalytics.isInternalSpecial(this.href)) { 29 // Keep the internal URL for Google Analytics website overlay intact. 30 ga("send", "pageview", { "page": Backdrop.googleanalytics.getPageUrl(this.href) }); 31 } 32 } 33 else { 34 if (Backdrop.settings.googleanalytics.trackMailto && $(this).is("a[href^='mailto:'],area[href^='mailto:']")) { 35 // Mailto link clicked. 36 ga("send", "event", "Mails", "Click", this.href.substring(7)); 37 } 38 else if (Backdrop.settings.googleanalytics.trackOutbound && this.href.match(/^\w+:\/\//i)) { 39 if (Backdrop.settings.googleanalytics.trackDomainMode != 2 || (Backdrop.settings.googleanalytics.trackDomainMode == 2 && !Backdrop.googleanalytics.isCrossDomain(this.hostname, Backdrop.settings.googleanalytics.trackCrossDomains))) { 40 // External link clicked / No top-level cross domain clicked. 41 ga("send", "event", "Outbound links", "Click", this.href); 42 } 43 } 44 } 45 }); 46 }); 47 48 // Track hash changes as unique pageviews, if this option has been enabled. 49 if (Backdrop.settings.googleanalytics.trackUrlFragments) { 50 window.onhashchange = function() { 51 ga('send', 'pageview', location.pathname + location.search + location.hash); 52 } 53 } 54 55 // Colorbox: This event triggers when the transition has completed and the 56 // newly loaded content has been revealed. 57 $(document).bind("cbox_complete", function () { 58 var href = $.colorbox.element().attr("href"); 59 if (href) { 60 ga("send", "pageview", { "page": Backdrop.googleanalytics.getPageUrl(href) }); 61 } 62 }); 63 64}); 65 66/** 67 * Check whether the hostname is part of the cross domains or not. 68 * 69 * @param string hostname 70 * The hostname of the clicked URL. 71 * @param array crossDomains 72 * All cross domain hostnames as JS array. 73 * 74 * @return boolean 75 */ 76Backdrop.googleanalytics.isCrossDomain = function (hostname, crossDomains) { 77 /** 78 * jQuery < 1.6.3 bug: $.inArray crushes IE6 and Chrome if second argument is 79 * `null` or `undefined`, http://bugs.jquery.com/ticket/10076, 80 * https://github.com/jquery/jquery/commit/a839af034db2bd934e4d4fa6758a3fed8de74174 81 * 82 * @todo: Remove/Refactor in D8 83 */ 84 if (!crossDomains) { 85 return false; 86 } 87 else { 88 return $.inArray(hostname, crossDomains) > -1 ? true : false; 89 } 90}; 91 92/** 93 * Check whether this is a download URL or not. 94 * 95 * @param string url 96 * The web url to check. 97 * 98 * @return boolean 99 */ 100Backdrop.googleanalytics.isDownload = function (url) { 101 var isDownload = new RegExp("\\.(" + Backdrop.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 102 return isDownload.test(url); 103}; 104 105/** 106 * Check whether this is an absolute internal URL or not. 107 * 108 * @param string url 109 * The web url to check. 110 * 111 * @return boolean 112 */ 113Backdrop.googleanalytics.isInternal = function (url) { 114 var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); 115 return isInternal.test(url); 116}; 117 118/** 119 * Check whether this is a special URL or not. 120 * 121 * URL types: 122 * - gotwo.module /go/* links. 123 * 124 * @param string url 125 * The web url to check. 126 * 127 * @return boolean 128 */ 129Backdrop.googleanalytics.isInternalSpecial = function (url) { 130 var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); 131 return isInternalSpecial.test(url); 132}; 133 134/** 135 * Extract the relative internal URL from an absolute internal URL. 136 * 137 * Examples: 138 * - http://mydomain.com/node/1 -> /node/1 139 * - http://example.com/foo/bar -> http://example.com/foo/bar 140 * 141 * @param string url 142 * The web url to check. 143 * 144 * @return string 145 * Internal website URL 146 */ 147Backdrop.googleanalytics.getPageUrl = function (url) { 148 var extractInternalUrl = new RegExp("^(https?):\/\/" + window.location.host, "i"); 149 return url.replace(extractInternalUrl, ''); 150}; 151 152/** 153 * Extract the download file extension from the URL. 154 * 155 * @param string url 156 * The web url to check. 157 * 158 * @return string 159 * The file extension of the passed url. e.g. "zip", "txt" 160 */ 161Backdrop.googleanalytics.getDownloadExtension = function (url) { 162 var extractDownloadextension = new RegExp("\\.(" + Backdrop.settings.googleanalytics.trackDownloadExtensions + ")([\?#].*)?$", "i"); 163 var extension = extractDownloadextension.exec(url); 164 return (extension === null) ? '' : extension[1]; 165}; 166 167})(jQuery); 168;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.