Skip to content

Commit 8ffaeda

Browse files
committed
a
1 parent 7b66f39 commit 8ffaeda

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ additional-js = [
2323
"theme/sponsor.js",
2424
"theme/ai.js"
2525
]
26+
google-analytics = "G-DSTYJWERH0"
2627
no-section-label = true
2728
preferred-dark-theme = "hacktricks-dark"
2829
default-theme = "hacktricks-light"

theme/index.hbs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,21 +343,17 @@
343343
{{/if}}
344344

345345
{{#if google_analytics}}
346-
<!-- Google Analytics Tag -->
346+
<!-- Google Analytics Tag (GA4) -->
347347
<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);
361357
</script>
362358
{{/if}}
363359

0 commit comments

Comments
 (0)