$(document).ready(function() {
    const lhost   = window.location.href.indexOf("localhost/") > -1;
    const prod    = window.location.href.indexOf("https://documentation") != -1;
    const tst     = window.location.href.indexOf("https://tst-documentation") != -1;
    const exp     = window.location.href.indexOf("https://tst-expere-documentation") != -1;
    const stg     = window.location.href.indexOf("https://stg-documentation") != -1;
    const dev     = window.location.href.indexOf("https://dev-documentation") != -1;

    // #region New GoogleAnalytics code
    let measurement_id; // Declare measurement_id with let for reassignment
    if (lhost) { measurement_id = "G-8W3ELS3KFC"; }
    if (dev) { measurement_id = "G-8W3ELS3KFC"; }
    if (stg) { measurement_id = "G-NC1L9ZF3TZ"; }
    if (exp) { measurement_id = "G-KWZDBNMN7N"; }
    if (tst) { measurement_id = "G-1VKNZWG6N7"; }
    if (prod) { measurement_id = "G-QT84BCZHEM"; }
    // console.log(measurement_id);

    const ga_code_head = "<!-- Google Tag Manager --><script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','" + measurement_id + "');</script><!-- End Google Tag Manager -->"

    const ga_code_body = "<!-- Google Tag Manager (noscript) --><noscript><iframe src='https://www.googletagmanager.com/ns.html?" + measurement_id + "' height='0' width='0' style='display:none;visibility:hidden'></iframe></noscript><!-- End Google Tag Manager (noscript) -->"

    $('head').prepend(ga_code_head);
    $('body').append(ga_code_body);
    // #endregion

});