1(function ($) { 2 3$(document).ready(function() { 4 5 // Accepts a string; returns the string with regex metacharacters escaped. The returned string 6 // can safely be used at any point within a regex to match the provided literal string. Escaped 7 // characters are [ ] { } ( ) * + ? - . , \ ^ $ # and whitespace. The character | is excluded 8 // in this function as it's used to separate the domains names. 9 RegExp.escapeDomains = function(text) { 10 return (text) ? text.replace(/[-[\]{}()*+?.,\\^$#\s]/g, "\\$&") : ''; 11 } 12 13 // Attach onclick event to document only and catch clicks on all elements. 14 $(document.body).click(function(event) { 15 // Catch the closest surrounding link of a clicked element. 16 $(event.target).closest("a,area").each(function() { 17 18 var ga = Drupal.settings.googleanalytics; 19 // Expression to check for absolute internal links. 20 var isInternal = new RegExp("^(https?):\/\/" + window.location.host, "i"); 21 // Expression to check for special links like gotwo.module /go/* links. 22 var isInternalSpecial = new RegExp("(\/go\/.*)$", "i"); 23 // Expression to check for download links. 24 var isDownload = new RegExp("\\.(" + ga.trackDownloadExtensions + ")$", "i"); 25 // Expression to check for the sites cross domains. 26 var isCrossDomain = new RegExp("^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\/.*(" + RegExp.escapeDomains(ga.trackCrossDomains) + ")", "i"); 27 28 // Is the clicked URL internal? 29 if (isInternal.test(this.href)) { 30 // Is download tracking activated and the file extension configured for download tracking? 31 if (ga.trackDownload && isDownload.test(this.href)) { 32 // Download link clicked. 33 var extension = isDownload.exec(this.href); 34 _gaq.push(["_trackEvent", "Downloads", extension[1].toUpperCase(), this.href.replace(isInternal, '')]); 35 } 36 else if (isInternalSpecial.test(this.href)) { 37 // Keep the internal URL for Google Analytics website overlay intact. 38 _gaq.push(["_trackPageview", this.href.replace(isInternal, '')]); 39 } 40 } 41 else { 42 if (ga.trackMailto && $(this).is("a[href^=mailto:],area[href^=mailto:]")) { 43 // Mailto link clicked. 44 _gaq.push(["_trackEvent", "Mails", "Click", this.href.substring(7)]); 45 } 46 else if (ga.trackOutbound && this.href) { 47 if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) { 48 // Top-level cross domain clicked. document.location is handled by _link internally. 49 _gaq.push(["_link", this.href]); 50 } 51 else if (ga.trackOutboundAsPageview) { 52 // Track all external links as page views after URL cleanup. 53 // Currently required, if click should be tracked as goal. 54 _gaq.push(["_trackPageview", '/outbound/' + this.href.replace(/^(https?|ftp|news|nntp|telnet|irc|ssh|sftp|webcal):\/\//i, '').split('/').join('--')]); 55 } 56 else { 57 // External link clicked. 58 _gaq.push(["_trackEvent", "Outbound links", "Click", this.href]); 59 } 60 } 61 } 62 }); 63 }); 64}); 65 66})(jQuery); 67;
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.