PageSourceSearch

https://www.kporttrust.org/_assets/e435091b0aeadf9cf08aa87798d58693/JavaScript/analytics.js?1783024240

js kporttrust.org collected 2026-09-26 04:32:22 UTC 8,064 bytes, 256 lines download raw bytes

1;(function() {
2  console.log('loaded');
3
4  function trackForms () {
5      // Track form submissions
6      /** @type {HTMLFormElement[]} */
7      const forms = document.getElementsByTagName("form");
8      for (let i = 0; i < forms.length; i++) {
9          const form = forms[i];
10          form.onsubmit = function (event) {
11              /** @type {HTMLFormElement} */
12              const form = event.target;
13
14              /** @type {HTMLInputElement} */
15
16              const position = button.closest("#header,#main,#footer").id;
17              const section = button.closest('.top,.middle,.bottom');
18              const sectionName = (section && section.className) || '';
19
20              gtag('event', 'Form Submission', {
21                  'event_category' : 'Form',
22                  'event_label' : position + ' > ' + sectionName + ' on ' + document.title.split(' - ')[0].substring(0, 200)
23              });
24          }
25      }
26  }
27
28  function trackButtons () {
29      // Track button clicks
30      /** @type {HTMLAnchorElement[]} */
31      const buttons = document.querySelectorAll("a.btn");
32      for (let i = 0; i < buttons.length; i++) {
33          button = buttons[i];
34          const label = button.innerText;
35
36          button.onclick = function (event) {
37              // position on page (header, main, or footer)
38              const position = button.closest("#header,#main,#footer").id;
39
40              gtag('event', 'Button Press', {
41                  'event_category' : 'Button',
42                  'event_label' : label.substring(0, 200),
43                  'position' : position,
44              });
45          }
46      }
47
48
49  }
50
51  function trackFiles () {
52      // Track internal file links using /fileadmin/
53      /** @type {HTMLAnchorElement[]} */
54      const files = document.querySelectorAll("a[href^='/fileadmin/']");
55
56      /** Truncate filenames using their local length
57          @param {string} filename @param {number} [maxLength=500] */
58      const truncateFilename = function (filename, maxLength) {
59          maxLength = maxLength || 500; // IE-supported default value assignment
60          if (filename.length > maxLength) {
61              const localName = filename.substring(filename.lastIndexOf('/') + 1);
62
63              return filename.substr(0, maxLength - 3 - localName.length) +
64                  '...' + localName.substr(-maxLength + 3);
65          }
66          return filename;
67      }
68
69      for (let i = 0; i < files.length; i++) {
70          const file = files[i];
71
72          file.onclick = function (event) {
73              /** @type {HTMLAnchorElement} */
74              const file = event.target;
75
76              const originalFilename = file.pathname.split('/fileadmin/')[1];
77              const filetype = originalFilename.substring(originalFilename.indexOf('.') + 1).toUpperCase();
78              const truncatedName = truncateFilename(originalFilename, 500);
79
80              gtag('event', 'View ' + filetype.substr(0, 50), {
81                  'event_category' : 'File View',
82                  'event_label' : truncatedName
83              });
84          }
85      }
86  }
87
88  function trackExternal () {
89      // Tracking external links
90      /** @type {HTMLAnchorElement[]} */
91      const externals = document.querySelectorAll("a[href^='http'], a[href^=ftp], a[href^=sftp], a[href^=ssh]");
92
93      for (let i = 0; i < externals.length; i++) {
94          const link = externals[i];
95
96          if (link.hostname === location.hostname) continue;
97
98          link.onclick = function(event) {
99              const link = event.target;
100              gtag('event', 'External Link Navigation', {
101                  'event_category' : 'External Links',
102                  'event_label' : link.href.substr(0, 200)
103              });
104          }
105      }
106
107
108  }
109
110  function trackEmails () {
111      // Track email address clicks
112      /** @type {HTMLAnchorElement[]} */
113      const emails = document.querySelectorAll('a[data-epgtag=mailto]');
114
115      for (let i = 0; i < emails.length; i++) {
116          /** @type {HTMLAnchorElement} */
117          const email = emails[i];
118
119          email.onclick = function(event) {
120          /** @type {HTMLAnchorElement} */
121              const email = event.target;
122
123              let label = email.innerText.split('@')[1];
124              label = label ? label.substring(0, 150) + ' address' : email.innerText;
125
126              gtag('event', 'Email Address Click', {
127                  'event_category' : 'Email',
128                  'event_label' : label
129              });
130          }
131      }
132
133
134  }
135
136  function trackLightBoxes () {
137      // Track lightbox views
138      /** @type {HTMLAnchorElement[]} */
139      const lightboxes = document.querySelectorAll('a.lightbox');
140
141      for (let i = 0; i < lightboxes.length; i++) {
142          const lightbox = lightboxes[i];
143
144          lightbox.onclick = function(event) {
145              gtag('event', 'Lightbox View', {
146                  'event_category' : 'Lightbox',
147                  'event_label' : document.title.split(' - ')[0].substring(0, 200)
148              });
149          }
150      }
151  }
152
153  function trackLogo () {
154      // Track logo clicks
155      document.getElementsByClassName('frame-header-logo')[0].onclick = function (event) {
156          gtag('event', 'Logo Click', {
157              'event_category' : 'Logo',
158              'event_label' : 'From: ' + document.title.split(' - ')[0].substring(0, 200)
159          });
160      };
161
162
163  }
164
165  function trackBreadcrumbs () {
166      // Track breadcrumbs
167      /** @type {HTMLAnchorElement[]} */
168      const breadcrumbs = document.getElementsByClassName('breadcrumb');
169
170      for (let i = 0; i < breadcrumbs.length; i++) {
171          breadcrumbs[i].onclick = function (event) {
172              gtag('event', 'Breadcrumb Navigation', {
173                  'event_category': 'Navigation'
174              });
175          }
176      }
177  }
178
179  function trackFrameMenus () {
180      // Track navigation clicks in menus
181      /** @type {HTMLAnchorElement[]} */
182      const menuLinks = document.querySelectorAll('div[class*="frame-type-menu_"] a');
183
184      for (let i = 0; i < menuLinks.length; i++) {
185          menuLinks[i].onclick = function (event) {
186              gtag('event', 'Menu Navigation', {
187                  'event_category': 'Navigation'
188              });
189          }
190      }
191  }
192
193  function trackNavbar () {
194      // Track navbar clicks
195      /** @type {HTMLAnchorElement[]} */
196      const menuLinks = document.querySelectorAll('.navbar-nav a');
197
198      for (let i = 0; i < menuLinks.length; i++) {
199          if(menuLinks[i].classList.contains('dropdown-toggle')) continue;
200          menuLinks[i].onclick = function (event) {
201              gtag('event', 'Navbar Navigation', {
202                  'event_category': 'Navigation'
203              });
204          }
205      }
206  }
207
208  window.addEventListener('beforeunload', trackNavigation);
209
210  /**
211   * Track navigation during BeforeUnload event
212   * @param {BeforeUnloadEvent} event
213   */
214  function trackNavigation (event) {
215      /** @type {HTMLElement} */
216      let active = document.activeElement;
217      if (!active) return;
218
219      if (active.closest('.navbar-nav')) {
220          var action = 'Navbar Navigation';
221      } else if (active.closest('div[class*="frame-type-menu_"]')) {
222          var action = 'Menu Navigation';
223      } else if (active.closest('.breadcrumb')) {
224          var action = 'Breadcrumb Navigation';
225      } else if (active.closest('.frame-header-logo')) {
226          console.log('Logo');
227          return;
228      } else {
229          return;
230      }
231
232      console.log(active);
233      console.log(action);
234      if (action) {
235        gtag('event', action, {
236            'event_category': 'Navigation',
237            'transport_type': 'beacon'
238        });
239      }
240  }
241
242  if (!navigator.doNotTrack) {
243    trackForms();
244    trackButtons();
245    trackFiles();
246    trackExternal();
247    trackEmails();
248    trackLightBoxes();
249    if (document.getElementsByClassName('frame-header-logo').length > 0) {
250      trackLogo();
251    }
252    /* trackBreadcrumbs();
253    trackFrameMenus();
254    trackNavbar(); */
255  }
256})();

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.