PageSourceSearch

https://statsig.com/js/site.js

js statsig.com collected 2026-10-01 09:23:08 UTC 13,322 bytes, 463 lines download raw bytes

1window['$d'] = document.getElementById.bind(document);
2const _menuTransition = 'max-height 0.3s ease-out';
3
4const statsigWWW = {
5  clearMenuHighlight: function() {
6    const headerLinks = document.getElementsByClassName('headerLink');
7    for (let ii = 0; ii < headerLinks.length; ii++) {
8      headerLinks[ii].classList.remove('active');
9    }
10  },
11
12  formatNumberForAnimation: function(num, isInteger) {
13    let numericValue = num;
14    return numericValue.toLocaleString('en-US', {
15      style: 'decimal',
16      minimumFractionDigits: isInteger ? 0 : 2,
17      maximumFractionDigits: isInteger ? 0 : 2,
18    });
19  },
20
21  formatNumber: function(num) {
22    if (Number.isNaN(num)) {
23      return "[Out of Range]";
24    }
25
26    return Intl.NumberFormat('en-US', {
27      notation: "compact",
28      maximumFractionDigits: 1
29    }).format(num);
30  },
31
32  getClickHandlerQuery: function(useCached = false) {
33    const url = new URL(window.location.href);
34    const utmKeys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
35    const stmKeys = ['_stm_source', '_stm_medium', '_stm_campaign', '_stm_term', '_stm_content'];
36    for (let ii = 0; ii < utmKeys.length; ii++) {
37      const uk = utmKeys[ii];
38      const sk = stmKeys[ii];
39      const value = url.searchParams.get(uk);
40      if (value) {
41        localStorage.setItem(sk, value);
42      } else if (useCached) {
43        const lv = localStorage.getItem(sk);
44        if (lv) {
45          url.searchParams.set(uk, lv);
46        }
47      }
48    }
49    return url.searchParams.toString();
50  },
51
52  getEventSection: function (element) {
53    while (element) {
54      let eventSection = element.dataset.eventSection;
55      if (eventSection) {
56        return eventSection;
57      }
58
59      element = element.parentElement;
60    }
61
62    return null;
63  },
64
65  getReferrerUrl: function(useCached = false) {
66    const query = this.getClickHandlerQuery(useCached);
67    const url = new URL(window.location.href);
68    url.search = query;
69    url.searchParams.delete('referrer'); // Prevent recursion
70    return url.toString();
71  },
72
73  hideDesktopMenu: function(animate = false) {
74    if (!this.openMenuElement) {
75      return;
76    }
77    const element = this.openMenuElement;
78    if (animate) {
79      element.style.transition = _menuTransition;
80    }    
81    this.clearMenuHighlight();
82    element.style.maxHeight = 0;
83    setTimeout(() => {
84      element.style.transition = 'unset';
85    }, 300);
86    this.openMenuElement = null;
87  },
88
89  hideMobileMenu: function() {
90    const mobileMenuItems = document.getElementsByClassName('mobileMenu');
91    Array.from(mobileMenuItems).forEach(mm => mm.style.display = 'none');
92    $d('mobileLogo').style.display = 'block';
93    Array.from(document.getElementsByClassName('mobileBackLink')).forEach(mbl => {
94      mbl.style.display = 'none';
95    });
96  },
97
98  logEngagementMetrics: function() {
99    window.addEventListener('scroll', () => {
100      const scrollDepth = Math.min(
101        100,
102        Math.round((window.scrollY + window.innerHeight) / document.body.scrollHeight * 100),
103      );
104      if (scrollDepth > statsigWWW.deepestScroll) {
105        statsigWWW.deepestScroll = scrollDepth;
106      }
107    });
108    window.addEventListener('beforeunload', () => {
109      const metadata = { url: window.location.href };
110      window.statsigSDK.logEvent({
111        eventName: 'scroll_depth',
112        value: statsigWWW.deepestScroll,
113        metadata: metadata,
114      });
115      window.statsigSDK.logEvent({
116        eventName: 'time_on_page_ms',
117        value: Date.now() - statsigWWW.loadStartTime,
118        metadata: metadata,
119      });
120    });
121  },
122  
123  onLoad: function () {
124    statsigWWW.deepestScroll = 0;
125    statsigWWW.loadStartTime = Date.now();
126    this.setupDesktopMenus();
127    try {
128      this.wireClickHandlers('button');
129      this.wireClickHandlers('a');
130      this.wireClickHandlers('div[data-event-value]');
131      this.prepareConsoleLinks();
132    } catch(e) {
133      console.error(e);
134    }
135    
136    const bootstrapValues = globalThis.statsigInitializeValues ?? '';
137    let bootstrapObject = undefined;
138    if (bootstrapValues !== '') {
139      try {
140        bootstrapObject = JSON.parse(bootstrapValues);
141        bootstrapObject["can_record_session"] = true;
142        bootstrapObject["session_recording_rate"] = 1;
143        bootstrapObject = JSON.stringify(bootstrapObject);
144      } catch(e) {
145        console.error(e);
146      }
147    }
148
149    const { StatsigClient, StatsigSessionReplayPlugin, StatsigAutoCapturePlugin } = window.Statsig;
150    const user = window['statsigUser'] || null;
151    const client = new StatsigClient(
152      'client-XlqSMkAavOmrePNeWfD0fo2cWcjxkZ0cJZz64w7bfHX', 
153      user, 
154      {
155        plugins: [
156          new StatsigSessionReplayPlugin(),
157          new StatsigAutoCapturePlugin({
158            consoleLogAutoCaptureSettings: {
159              enabled: true,
160            }
161          }),
162        ],
163      },
164    );
165
166    client.on('error', (event) => {
167      if (event.tag === 'NetworkError') {
168        if (event.requestArgs && event.requestArgs.url) {
169          event.error.stack =
170            `StatsigNetworkError: ${event.requestArgs.url}\n` +
171            event.error.stack;
172        }
173
174        client
175          .getContext()
176          .errorBoundary.logError('statig_www:network_error', event.error);
177      }
178    });
179
180    // bootstrap
181    client.dataAdapter.setData(bootstrapObject, user);
182    client.initializeSync();
183
184    window.statsigSDK = client;
185    statsigWWW.onSDKInit(client);
186  },
187
188  onSDKInit: function (statsigClient) {
189    statsigClient.logEvent({
190      eventName: 'ga_available',
191      value: !!(window.ga && ga.create)
192    });
193    if (URLSearchParams) {
194      const params = new URLSearchParams(window.location.search);
195      statsigClient.logEvent({
196        eventName: 'page_load',
197        value: window.location.pathname,
198        metadata: Object.fromEntries(params),
199      });
200    } else {
201      statsigClient.logEvent({
202        eventName: 'page_load',
203        value: window.location.pathname
204      });
205    }
206
207    if (
208      window.__ccKey &&
209      statsigClient.checkGate('show_cookie_consent') &&
210      !document.cookie.includes(window.__ccKey)
211    ) {
212      document.getElementById('cookieConsent').style.display = 'unset';
213    }
214
215    statsigWWW.logEngagementMetrics();
216  },
217
218  prepareConsoleLinks: function() {
219    if (typeof window.cookieStore === 'undefined') {
220      return;
221    }
222
223    const utmEntries = (() => {
224      const keys = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_content', 'utm_term'];
225      try {
226        const refUrl = new URL(this.getReferrerUrl(true));
227        return keys
228          .map((key) => {
229            const value = refUrl.searchParams.get(key);
230            return value ? [key, value] : null;
231          })
232          .filter(Boolean);
233      } catch {
234        return [];
235      }
236    })();
237
238    if (utmEntries.length === 0) {
239      return;
240    }
241
242    const anchors = Array.from(
243      document.querySelectorAll('a[href*="console.statsig.com"]'),
244    );
245    if (anchors.length === 0) {
246      return;
247    }
248
249    const applyParams = (anchor, entries) => {
250      const url = new URL(anchor.href);
251      entries.forEach(([key, value]) => url.searchParams.set(key, value));
252      anchor.href = url.toString();
253    };
254
255    anchors.forEach((anchor) => applyParams(anchor, utmEntries));
256
257    window.cookieStore
258      .get('_ga')
259      .then((cookie) => {
260        if (!cookie?.value) {
261          return;
262        }
263        anchors.forEach((anchor) => applyParams(anchor, [['_ga', cookie.value]]));
264      })
265      .catch(() => {});
266  },
267
268  setupAccordion(containerId, imageId, imageFolder) {
269    const allExpanders = Array.from($d(containerId).querySelectorAll('.expanderContainer'));
270    const image = $d(imageId);
271    image.style.opacity = 1;
272    
273    let activeExpander = null;
274    let prevActive = null;
275    allExpanders.forEach(el => {
276      if (!activeExpander) {
277        activeExpander = el;
278        activeExpander.classList.add('active');
279      }
280      el.addEventListener('click', e => {
281        if (e.currentTarget === activeExpander) {
282          return;
283        }
284        prevActive = activeExpander;
285        activeExpander = e.currentTarget;
286        activeExpander.classList.add('active');        
287        const index = allExpanders.indexOf(activeExpander);
288        if (index >= 0) {
289          image.style.opacity = 0;
290          setTimeout(() => {
291            const imageUrl = activeExpander.dataset['imageUrl'];
292            image.src = imageUrl ? imageUrl : `${imageFolder}/highlight-${index}.png`;
293            image.style.opacity = 1;
294          }, 200);
295        }
296        setTimeout(() => {
297          prevActive.classList.remove('active');
298        }, 10);
299      })
300    });
301  },
302
303  setupAdsTracking: function () {
304    window.dataLayer = window.dataLayer || [];
305
306    window.ko = window.ko || [];
307    [
308      'identify',
309      'track',
310      'removeListeners',
311      'open',
312      'on',
313      'off',
314      'qualify',
315      'ready',
316    ].forEach(function (t) {
317      ko[t] = function () {
318        var n = [].slice.call(arguments);
319        return n.unshift(t), ko.push(n), ko;
320      };
321    });
322
323    if (!window.revealCallback) {
324      window.revealCallback = () => {};
325    }
326  },
327
328  setupDesktopMenus: function() {
329    if (this.menusSetup) {
330      return;
331    }
332    const headerLinks = document.getElementsByClassName('headerLink');
333    if (headerLinks.length === 0) {
334      return;
335    }
336    for (let ii = 0; ii < headerLinks.length; ii++) {
337      const link = headerLinks[ii];
338      link.addEventListener('click', (e) => {
339        const target = link.dataset['targetElement'];
340        if (target) {
341          statsigWWW.toggleDesktopMenu(link, target);
342        }
343        if (!link.classList.contains('passthrough')) {
344          e.preventDefault();
345          return false;
346        }
347      });
348    }
349
350    document.addEventListener('click', (e) => {
351      const desktopMenuContainer = $d('desktopMenuContainer');
352      if (!desktopMenuContainer) {
353        return;
354      }
355      const target = e.target;
356      if (desktopMenuContainer.contains(target) || target.classList.contains('headerLink')) {
357        return;
358      }
359      statsigWWW.hideDesktopMenu(true);
360    });
361    this.menusSetup = true;
362  },
363
364  setupMobileMenus: function() {
365    const menuItems = document.getElementsByClassName('mobileMenuItem');
366    for (let ii = 0; ii < menuItems.length; ii++) {
367      const link = menuItems[ii];
368      link.addEventListener('click', (e) => {
369        const target = link.dataset['targetElement'];
370        if (target) {
371          statsigWWW.showMobileMenu(link, target);
372        }
373        if (!link.classList.contains('passthrough')) {
374          e.preventDefault();
375          return false;
376        }
377      });
378    }
379
380    Array.from(document.getElementsByClassName('mobileBackLink')).forEach(mbl => {
381      mbl.addEventListener('click', (e) => {
382        $d('mobileMenuContainer').style.left = '0';
383        setTimeout(() => {
384          statsigWWW.hideMobileMenu();
385        }, 200);
386      });
387    });
388  },
389
390  showDesktopMenu: function(link, element) {
391    if (this.openMenuElement == element) {
392      return;
393    }
394    const anotherMenuOpen = this.openMenuElement ? true : false;
395    this.hideDesktopMenu();
396    
397    this.openMenuElement = element;
398    if (!anotherMenuOpen) {
399      element.style.transition = _menuTransition;
400    }
401    element.style.maxHeight = '625px';
402    link.classList.add('active');
403    setTimeout(() => {
404      element.style.transition = 'unset';
405    }, 300);
406  },
407
408  showMobileMenu: function(link, target) {
409    this.hideMobileMenu();
410    $d('mobileLogo').style.display = 'none';
411    $d('mobileMenu' + target).style.display = 'block';
412    $d('back' + target).style.display = 'block';
413    $d('mobileMenuContainer').style.left = '-100%';
414  },
415
416  toggleDesktopMenu: function(link, target) {
417    const elementId = 'desktopMenu' + target;
418    const element = $d(elementId);
419    if (!element) {
420      return;
421    }
422    element.offsetHeight > 20 
423      ? this.hideDesktopMenu(true) 
424      : this.showDesktopMenu(link, element);
425  },
426
427  toggleHamburgerMenu: function () {
428    this.menuVisible = !this.menuVisible;
429    this.hideMobileMenu();
430    $d('mobileMenuContainer').style.display = this.menuVisible ? 'block' : 'none';
431    $d('mobileMenuContainer').style.left = 0;
432    $d('navicon').classList[this.menuVisible ? 'add' : 'remove']('open');
433    $d('pageContent').style.display = this.menuVisible ? 'none' : 'block';
434    $d('footer').style.display = this.menuVisible ? 'none' : 'block';
435  },
436
437  wireClickHandlers: function (tagName) {
438    const elements = document.querySelectorAll(tagName);
439    for (let ii = 0; ii < elements.length; ii++) {
440      const el = elements[ii];
441      if (!el.dataset.eventValue) {
442        continue;
443      }
444
445      el.addEventListener('click', () => {
446        const section = this.getEventSection(el);
447        window.statsigSDK && window.statsigSDK.logEvent('click', el.dataset.eventValue, {
448          section: section,
449          type: el.dataset.eventType,
450        });
451        dataLayer.push({
452          'event': el.dataset.eventValue,
453          'location': section
454        });
455      });
456    }
457  },
458};
459
460document.addEventListener('DOMContentLoaded', () => {
461  statsigWWW.setupDesktopMenus();
462  statsigWWW.setupMobileMenus();
463});

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.