1/** 2 * PressLearn Analytics Tracking 3 * 4 */ 5 6(function($) { 7 'use strict'; 8 9 function getVisitorId() { 10 let visitorId = localStorage.getItem('presslearn_visitor_id'); 11 if (!visitorId) { 12 if (window.crypto && window.crypto.getRandomValues) { 13 const array = new Uint32Array(4); 14 window.crypto.getRandomValues(array); 15 visitorId = Array.from(array, x => x.toString(36).substr(2, 8)).join(''); 16 } else { 17 visitorId = Math.random().toString(36).substring(2, 15) + 18 Math.random().toString(36).substring(2, 15); 19 } 20 localStorage.setItem('presslearn_visitor_id', visitorId); 21 } 22 return visitorId; 23 } 24 25 26 function getReferrer() { 27 if (document.referrer) { 28 const currentHost = window.location.hostname; 29 try { 30 let referrerUrl; 31 try { 32 referrerUrl = new URL(document.referrer); 33 } catch (e) { 34 return ''; 35 } 36 37 if (referrerUrl.hostname === currentHost) { 38 return ''; 39 } 40 return document.referrer; 41 } catch(e) { 42 return ''; 43 } 44 } 45 return ''; 46 } 47 48 function trackPageview() { 49 if (window.location.href.includes('/wp-admin/')) { 50 return; 51 } 52 53 if (typeof pressleanAnalytics === 'undefined') { 54 return; 55 } 56 57 const data = { 58 action: 'presslearn_track_pageview', 59 visitor_id: getVisitorId(), 60 url: window.location.href, 61 title: document.title, 62 referrer: getReferrer(), 63 nonce: pressleanAnalytics.nonce 64 }; 65 66 $.ajax({ 67 url: pressleanAnalytics.ajaxurl, 68 type: 'POST', 69 data: data, 70 success: function(response) { 71 if (response.success) { 72 console.debug('Analytics tracking successful'); 73 } else { 74 } 75 }, 76 error: function(xhr, status, error) { 77 } 78 }); 79 } 80 81 $(document).ready(function() { 82 try { 83 trackPageview(); 84 } catch (e) { 85 } 86 }); 87 88})(jQuery);
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.