feat: add google analytics setup
All checks were successful
Deploy / build-and-deploy (push) Successful in 59s

This commit is contained in:
juancwu 2026-02-10 16:52:35 +00:00
commit e7fdea5375
3 changed files with 22 additions and 0 deletions

View file

@ -56,6 +56,10 @@ templ Base(props ...SEOProps) {
@smoothScrollScript()
// HTMX CSRF configuration
@htmxCSRFScript()
// Google Analytics
if cfg := ctxkeys.Config(ctx); cfg != nil && cfg.GoogleMeasuringID != "" {
@googleAnalyticsScript(cfg.GoogleMeasuringID)
}
</head>
<body class="min-h-screen">
{ children... }
@ -113,3 +117,14 @@ templ smoothScrollScript() {
templ htmxCSRFScript() {
<script src="/assets/js/htmx-csrf.js"></script>
}
templ googleAnalyticsScript(id string) {
<script async src={ "https://www.googletagmanager.com/gtag/js?id=" + id }></script>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
window.gtag = gtag;
gtag('js', new Date());
gtag('config', {{ id }});
</script>
}