|
343 | 343 | {{/if}} |
344 | 344 |
|
345 | 345 | {{#if google_analytics}} |
346 | | - <!-- Google Analytics Tag --> |
| 346 | + <!-- Google Analytics Tag (GA4) --> |
347 | 347 | <script> |
348 | | - var localAddrs = ["localhost", "127.0.0.1", ""]; |
349 | | -
|
350 | | - // make sure we don't activate google analytics if the developer is |
351 | | - // inspecting the book locally... |
352 | | - if (localAddrs.indexOf(document.location.hostname) === -1) { |
353 | | - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
354 | | - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
355 | | - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
356 | | - })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); |
357 | | -
|
358 | | - ga('create', '{{google_analytics}}', 'auto'); |
359 | | - ga('send', 'pageview'); |
360 | | - } |
| 348 | + window.dataLayer = window.dataLayer || []; |
| 349 | + function gtag(){dataLayer.push(arguments);} |
| 350 | + gtag('js', new Date()); |
| 351 | + gtag('config', '{{google_analytics}}'); |
| 352 | +
|
| 353 | + var gtagScript = document.createElement('script'); |
| 354 | + gtagScript.async = true; |
| 355 | + gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id={{google_analytics}}'; |
| 356 | + document.head.appendChild(gtagScript); |
361 | 357 | </script> |
362 | 358 | {{/if}} |
363 | 359 |
|
|
0 commit comments