1if (typeof (jQuery) != 'undefined') 2{ 3 // Examples of how to call this method: 4 // $(function () { Escc.Statistics.TrackWithGoogleAnalytics(); }); 5 // $(function () { Escc.Statistics.TrackWithGoogleAnalytics({ domains: ['eastsussex.gov.uk', 'eastsussexcc.gov.uk'] }); }); 6 var Escc = { Statistics: { 7 TrackWithGoogleAnalytics: function (options) 8 { 9 // Allow option for specific domains to be treated as internal 10 var defaultOptions = { domains: [] } 11 options = $.extend(defaultOptions, options); 12 options.domains.push(document.location.host); 13 14 var len = options.domains.length; 15 for (var i = 0; i < len; i++) options.domains[i] = options.domains[i].toLowerCase(); 16 17 // Track clicks on links with these extensions using Google Analytics 18 $("a") 19 .filter(function () { return /(\.pdf|\.rtf|\.doc|\.docx|\.dot|\.dotx|\.xls|\.xlsx|\.xlt|\.xltx|\.csv|\.mp3|\.wmv|\.mov|\.xml|\.ashx|\.rss|\.ical|\.hcard|\.ppt|\.pptx|\.pps|\.ppsx|\.pot|\.potx)$/i.test($(this).attr('href')); }) 20 .click(function () 21 { 22 // Track as virtual page view from Oct 2011 (not as event, because that doesn't support goals or in-page analytics) 23 if (typeof (ga) !== 'undefined') ga('send', 'pageview', $(this).attr("href").toLowerCase()); 24 }); 25 26 // Act on all external links 27 $("a[href^='http']").filter(function () 28 { 29 // Selector only targets absolute links. Isolate domain using the slashes that must be there. 30 var href = this.getAttribute('href'); 31 var pos = href.indexOf("/"); 32 if (pos > -1 && href.length > pos + 2) href = href.substring(pos + 2); 33 pos = href.indexOf("/"); 34 if (pos > -1) href = href.substring(0, pos); 35 36 // See whether one of the domains regarded as internal matches the current domain. Use .indexOf 37 // rather than exact match to allow for sub-domains to match as the same site. 38 var include = true; 39 for (var i = 0; i < options.domains.length; i++) 40 { 41 include = include && (href.indexOf(options.domains[i]) == -1); 42 } 43 return include; 44 }) 45 .each(function () 46 { 47 // Add rel="external" 48 var link = $(this); 49 var rel = link.attr("rel"); 50 if (typeof (rel) == 'undefined') rel = ""; 51 if (!rel || rel.indexOf("external") == -1) 52 { 53 rel = (rel && rel.length > 0) ? rel + " " : ""; 54 rel += "external"; 55 link.attr("rel", rel); 56 } 57 }) 58 .click(function () 59 { 60 // Track in Google Analytics 61 if (typeof(ga) !== 'undefined') ga('send', 'event', 'external links', document.URL, $(this).attr("href"), 0); 62 }); 63 64 // Track mailto: links in Google Analytics 65 // Include them with "external links" so that it's fewer clicks to see where a user went from a page. Can separate the types by filtering on "mailto" if needed. 66 $("a[href^='mailto:']").click(function () 67 { 68 if (typeof(ga) !== 'undefined') ga('send', 'event', 'external links', document.URL, $(this).attr("href"), 0); 69 }); 70 } 71 } 72 } 73}
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.