github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/webapp/templates/_ga.html (about)

     1  {{- /* no data */ -}}
     2  <!-- Global site tag (gtag.js) - Google Analytics -->
     3  <script async src="https://www.googletagmanager.com/gtag/js?id=G-R9Z49K7QCN"></script>
     4  <script>
     5    window.dataLayer = window.dataLayer || [];
     6    function gtag(){dataLayer.push(arguments);}
     7    gtag('js', new Date());
     8  
     9    // Configure Google Analytics 4
    10    // TODO: Look into using Google Tag Manager
    11    // https://github.com/web-platform-tests/wpt.fyi/issues/2919
    12    // Until then, determine which Google Analytics to use by examining the host
    13    const host = window.location.hostname;
    14    if (host == "wpt.fyi"){
    15      gtag('config', 'G-Q5FRYPBBYC');
    16    } else {
    17      // Default to using the staging one
    18      gtag('config', 'G-R9Z49K7QCN');
    19    }
    20    window.onerror = function(message, source, lineno, colno) {
    21      let description;
    22      // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
    23      if (message.toLowerCase().indexOf('script error') > -1) {
    24        description = `External error: ${message}`;
    25      } else {
    26        description = `${message} at ${source}:${lineno}:${colno}`;
    27      }
    28      // https://developers.google.com/analytics/devguides/collection/gtagjs/exceptions
    29      gtag('event', 'exception', {'description': description});
    30    };
    31  </script>