1 2/** 3 * Google Preview 4 * 5 * @author Ryan Chase 6 * @version 1.0 7 * @url http://www.blastam.com/blog/index.php/2013/03/how-to-track-downloads-in-google-analytics-v2 8 */ 9(function ($, document) { 10 $(document).ready(function(){ 11 var filetypes = /\.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i; 12 13 $('a').on('click', function (event) { 14 var el = $(this), 15 track = true, 16 href = this.href, 17 isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]); 18 19 if (!href.match(/^javascript:/i)) { 20 var elEv = []; 21 elEv.value = 0, elEv.non_i = false; 22 if (href.match(/^mailto\:/i)) { 23 elEv.category = "email"; 24 elEv.action = "click"; 25 elEv.label = href.replace(/^mailto\:/i, ''); 26 elEv.loc = href; 27 } 28 else if (href.match(filetypes)) { 29 var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined; 30 elEv.category = "download"; 31 elEv.action = "click-" + extension[0]; 32 elEv.label = href.replace(/ /g, "-"); 33 elEv.loc = href; 34 } 35 else if (href.match(/^https?\:/i) && !isThisDomain) { 36 elEv.category = "external"; 37 elEv.action = "click"; 38 elEv.label = href.replace(/^https?\:\/\//i, ''); 39 elEv.non_i = true; 40 elEv.loc = href; 41 } 42 else if (href.match(/^tel\:/i)) { 43 elEv.category = "telephone"; 44 elEv.action = "click"; 45 elEv.label = href.replace(/^tel\:/i, ''); 46 elEv.loc = href; 47 } 48 else track = false; 49 50 if (track) { 51 ga('send', 'event', elEv.category.toLowerCase(), elEv.action.toLowerCase(), elEv.label.toLowerCase(), elEv.value, {'nonInteraction': elEv.non_i}); 52 if (el.attr('target') == undefined || el.attr('target').toLowerCase() != '_blank') { 53 setTimeout(function () { 54 location.href = elEv.loc; 55 }, 400); 56 return false; 57 } 58 } 59 } 60 }); 61 }); 62})($, document);
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.