PageSourceSearch

https://codelamp.co.uk/js/gtrack.js?build=BUILDTOKEN

js codelamp.co.uk collected 2026-10-04 13:34:22 UTC 3,385 bytes, 106 lines download raw bytes

1var gtrack = (function(){
2  var describeTrackingName = function(elm){
3    var e = jQuery(elm).closest('a').get(0) || elm;
4    var cn = String(e.className),
5        re = new RegExp('(^|\\s)(gt-[^\\s]+)', 'gi'),
6        m = re.exec(cn);
7    if ( m && m[2] ) {
8      return m[2];
9    }
10    return '';
11  };
12  var describeLinkName = function(elm){
13    var href = elm.getAttribute('href') || '';
14    if ( href.indexOf('javascript:') != -1 ) {
15      return '';
16    }
17    return href;
18  };
19  var describeElement = function(elm){
20    var tname = describeTrackingName(elm), lname = describeLinkName(elm), name = '';
21    if ( lname ) {
22      name = lname + (tname ? ' (' + tname + ')' : '');
23    }
24    else if ( tname ) {
25      name = tname;
26    }
27    else {
28      name = jQuery(elm).elementPath();
29    }
30    return name;
31  };
32  var toArray = function(a){ return Array.prototype.slice.call(a, 0); };
33  var lga = function(){
34    try {
35      console.log('track event', arguments);
36      ga.apply(this, arguments);
37    }
38    catch(ex){}
39  };
40  return function(context){
41    // no tracking for you...
42    if ( !context || !context.querySelectorAll ) return;
43    var outbounds = context.querySelectorAll('a[href^="http://"], a[href^="https://"]');
44    var internals = toArray(context.querySelectorAll('a[href]'));
45    var interacts = [];
46    var i, idx, l;
47    var olink = function(elm){
48      // use custom attribute, rather than class to avoid reflows
49      if ( elm.hasAttribute && elm.hasAttribute('data-gt-out') ) { return; }
50      elm.setAttribute && elm.setAttribute('data-gt-out', '1');
51      elm.addEventListener('click', function(e){
52        lga('send', {
53          hitType: 'event',
54          eventCategory: 'outbound',
55          eventAction: 'click',
56          eventLabel: describeElement(e.target),
57          transport: 'beacon'
58        });
59      });
60    };
61    var ilink = function(elm){
62      // use custom attribute, rather than class to avoid reflows
63      if ( elm.hasAttribute && elm.hasAttribute('data-gt-in') ) { return; }
64      elm.setAttribute && elm.setAttribute('data-gt-in', '1');
65      elm.addEventListener('click', function(e){
66        lga('send', {
67          hitType: 'event',
68          eventCategory: 'internal',
69          eventAction: 'click',
70          eventLabel: describeElement(e.target)
71        });
72      });
73    };
74    var jlink = function(elm){
75      // use custom attribute, rather than class to avoid reflows
76      if ( elm.hasAttribute && elm.hasAttribute('data-gt-js') ) { return; }
77      elm.setAttribute && elm.setAttribute('data-gt-js', '1');
78      elm.addEventListener('click', function(e){
79        lga('send', {
80          hitType: 'event',
81          eventCategory: 'interaction',
82          eventAction: 'click',
83          eventLabel: describeElement(e.target)
84        });
85      });
86    };
87    // remove outbounds from internals
88    l=outbounds.length; for ( i=0; i<l; i++ ) {
89      idx = internals.indexOf(outbounds[i]);
90      if ( idx != -1 ) {
91        olink(outbounds[i]);
92        internals.splice(idx, 1);
93      }
94    }
95    // remove js links from internals
96    l=internals.length; for ( i=0; i<l; i++ ) {
97      if ( String(internals[i].href).indexOf('javascript:') != -1 ) {
98        jlink(internals[i]); interacts.push(internals[i]);
99        internals.splice(i, 1); i--; l--;
100      }
101      else {
102        ilink(internals[i]);
103      }
104    }
105  };
106})();

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.