1/** 2 * Deferred marketing tags (Meta, GA4 x2, Pinterest, TikTok). Config: window.__NR_ANALYTICS__ 3 * @typedef {Object} NrAnalyticsConfig 4 * @property {boolean} [enabled] 5 * @property {string} [meta_pixel_id] 6 * @property {string} [tiktok_pixel_id] 7 * @property {string} [tiktok_store_event] 8 * @property {string} [pinterest_tag_id] 9 * @property {string} [ga_measurement_id] 10 * @property {string} [ga_measurement_chrome_extension_id] 11 * @property {string} [pinterest_track_event_id] 12 * @property {string} [pinterest_lead_type] 13 * @property {string} [pinterest_em_sha256] 14 */ 15(function () { 16 var cfg = window.__NR_ANALYTICS__; 17 if (!cfg || cfg.enabled === false) return; 18 19 var IDLE_TIMEOUT_MS = 2600; 20 var activated = false; 21 22 function isValidEmHash(s) { 23 if (!s || typeof s !== 'string' || s.length !== 64) return false; 24 return /^[a-f0-9]{64}$/.test(s); 25 } 26 27 function loadMeta() { 28 var id = cfg.meta_pixel_id; 29 if (!id || window.__nrMetaPixelInit) return; 30 window.__nrMetaPixelInit = true; 31 /* global fbq */ 32 !(function (f, b, e, v, n, t, s) { 33 if (f.fbq) return; 34 n = f.fbq = function () { 35 n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments); 36 }; 37 if (!f._fbq) f._fbq = n; 38 n.push = n; 39 n.loaded = true; 40 n.version = '2.0'; 41 n.queue = []; 42 t = b.createElement(e); 43 t.async = true; 44 t.src = v; 45 s = b.getElementsByTagName(e)[0]; 46 s.parentNode.insertBefore(t, s); 47 })(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js'); 48 window.fbq('init', id); 49 window.fbq('track', 'PageView'); 50 } 51 52 function loadGtag() { 53 var primary = cfg.ga_measurement_id; 54 var chromeExt = cfg.ga_measurement_chrome_extension_id; 55 if (!primary || !chromeExt || window.__nrGtagInit) return; 56 window.__nrGtagInit = true; 57 window.dataLayer = window.dataLayer || []; 58 function gtag() { 59 window.dataLayer.push(arguments); 60 } 61 window.gtag = gtag; 62 gtag('js', new Date()); 63 var s = document.createElement('script'); 64 s.async = true; 65 s.src = 'https://www.googletagmanager.com/gtag/js?id=' + encodeURIComponent(primary); 66 s.onload = function () { 67 gtag('config', primary); 68 gtag('config', chromeExt); 69 }; 70 document.head.appendChild(s); 71 } 72 73 function loadPinterest() { 74 var tid = cfg.pinterest_tag_id; 75 if (!tid || window.__nrPinterestCoreQueued) return; 76 window.__nrPinterestCoreQueued = true; 77 var w = window; 78 if (!w.pintrk) { 79 w.pintrk = function () { 80 (w.pintrk.queue = w.pintrk.queue || []).push(Array.prototype.slice.call(arguments)); 81 }; 82 w.pintrk.queue = []; 83 w.pintrk.version = '3.0'; 84 } 85 var s = document.createElement('script'); 86 s.async = true; 87 s.src = 'https://s.pinimg.com/ct/core.js'; 88 s.onload = function () { 89 var em = cfg.pinterest_em_sha256; 90 if (isValidEmHash(em)) { 91 w.pintrk('load', tid, { em: em }); 92 } else { 93 w.pintrk('load', tid); 94 } 95 w.pintrk('page'); 96 if (cfg.pinterest_track_event_id) { 97 w.pintrk('track', 'pagevisit', { event_id: cfg.pinterest_track_event_id }); 98 } 99 w.__nrPinterestReady = true; 100 }; 101 document.head.appendChild(s); 102 } 103 104 function loadTikTok() { 105 var id = cfg.tiktok_pixel_id; 106 if (!id || window.__nrTikTokInit) return; 107 window.__nrTikTokInit = true; 108 /* global ttq */ 109 !(function (w, d, t) { 110 w.TiktokAnalyticsObject = t; 111 var ttq = (w[t] = w[t] || []); 112 ttq.methods = [ 113 'page', 114 'track', 115 'identify', 116 'instances', 117 'debug', 118 'on', 119 'off', 120 'once', 121 'ready', 122 'alias', 123 'group', 124 'enableCookie', 125 'disableCookie', 126 'holdConsent', 127 'revokeConsent', 128 'grantConsent', 129 ]; 130 ttq.setAndDefer = function (t, e) { 131 t[e] = function () { 132 t.push([e].concat(Array.prototype.slice.call(arguments, 0))); 133 }; 134 }; 135 for (var i = 0; i < ttq.methods.length; i++) ttq.setAndDefer(ttq, ttq.methods[i]); 136 ttq.instance = function (t) { 137 for (var e = ttq._i[t] || [], n = 0; n < ttq.methods.length; n++) ttq.setAndDefer(e, ttq.methods[n]); 138 return e; 139 }; 140 ttq.load = function (e, n) { 141 var r = 'https://analytics.tiktok.com/i18n/pixel/events.js'; 142 var o = n && n.partner; 143 ttq._i = ttq._i || {}; 144 ttq._i[e] = []; 145 ttq._i[e]._u = r; 146 ttq._t = ttq._t || {}; 147 ttq._t[e] = +new Date(); 148 ttq._o = ttq._o || {}; 149 ttq._o[e] = n || {}; 150 n = document.createElement('script'); 151 n.type = 'text/javascript'; 152 n.async = true; 153 n.src = r + '?sdkid=' + e + '&lib=' + t; 154 e = document.getElementsByTagName('script')[0]; 155 e.parentNode.insertBefore(n, e); 156 }; 157 })(window, document, 'ttq'); 158 window.ttq.load(id); 159 window.ttq.page(); 160 } 161 162 function bindStoreCtaLeads() { 163 document.addEventListener( 164 'click', 165 function (e) { 166 var el = e.target; 167 if (!el || !el.closest) return; 168 var a = el.closest('a[data-nr-store-cta]'); 169 if (!a) return; 170 if (typeof window.pintrk === 'function') { 171 try { 172 window.pintrk('track', 'lead', { 173 event_id: cfg.pinterest_track_event_id, 174 lead_type: cfg.pinterest_lead_type || 'Newsletter', 175 }); 176 } catch (err) { 177 /* ignore */ 178 } 179 } 180 if (typeof window.ttq !== 'undefined' && cfg.tiktok_pixel_id) { 181 try { 182 window.ttq.track(cfg.tiktok_store_event || 'Download'); 183 } catch (err) { 184 /* ignore */ 185 } 186 } 187 }, 188 true 189 ); 190 } 191 192 function activate() { 193 if (activated) return; 194 activated = true; 195 loadMeta(); 196 loadGtag(); 197 loadPinterest(); 198 loadTikTok(); 199 } 200 201 function scheduleIdle() { 202 if (window.requestIdleCallback) { 203 window.requestIdleCallback( 204 function () { 205 activate(); 206 }, 207 { timeout: IDLE_TIMEOUT_MS } 208 ); 209 } else { 210 window.setTimeout(activate, IDLE_TIMEOUT_MS); 211 } 212 } 213 214 bindStoreCtaLeads(); 215 scheduleIdle();
216 ['scroll', 'pointerdown', 'keydown'].forEach(function (ev) { 217 window.addEventListener(ev, activate, { passive: true, once: true }); 218 }); 219})();
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.