feat: add google analytics setup
All checks were successful
Deploy / build-and-deploy (push) Successful in 59s
All checks were successful
Deploy / build-and-deploy (push) Successful in 59s
This commit is contained in:
parent
91a243e114
commit
e7fdea5375
3 changed files with 22 additions and 0 deletions
|
|
@ -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>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue