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
|
|
@ -21,3 +21,5 @@ MAILER_PASSWORD=
|
||||||
MAILER_EMAIL_FROM=
|
MAILER_EMAIL_FROM=
|
||||||
|
|
||||||
SUPPORT_EMAIL=
|
SUPPORT_EMAIL=
|
||||||
|
|
||||||
|
GOOGLE_MEASURING_ID=
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ type Config struct {
|
||||||
|
|
||||||
SupportEmail string
|
SupportEmail string
|
||||||
|
|
||||||
|
GoogleMeasuringID string
|
||||||
|
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,6 +70,8 @@ func Load(version string) *Config {
|
||||||
|
|
||||||
SupportEmail: envString("SUPPORT_EMAIL", ""),
|
SupportEmail: envString("SUPPORT_EMAIL", ""),
|
||||||
|
|
||||||
|
GoogleMeasuringID: envString("GOOGLE_MEASURING_ID", ""),
|
||||||
|
|
||||||
Version: version,
|
Version: version,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,6 +95,7 @@ func (c *Config) Sanitized() *Config {
|
||||||
|
|
||||||
MailerEmailFrom: c.MailerEmailFrom,
|
MailerEmailFrom: c.MailerEmailFrom,
|
||||||
SupportEmail: c.SupportEmail,
|
SupportEmail: c.SupportEmail,
|
||||||
|
GoogleMeasuringID: c.GoogleMeasuringID,
|
||||||
|
|
||||||
Version: c.Version,
|
Version: c.Version,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,10 @@ templ Base(props ...SEOProps) {
|
||||||
@smoothScrollScript()
|
@smoothScrollScript()
|
||||||
// HTMX CSRF configuration
|
// HTMX CSRF configuration
|
||||||
@htmxCSRFScript()
|
@htmxCSRFScript()
|
||||||
|
// Google Analytics
|
||||||
|
if cfg := ctxkeys.Config(ctx); cfg != nil && cfg.GoogleMeasuringID != "" {
|
||||||
|
@googleAnalyticsScript(cfg.GoogleMeasuringID)
|
||||||
|
}
|
||||||
</head>
|
</head>
|
||||||
<body class="min-h-screen">
|
<body class="min-h-screen">
|
||||||
{ children... }
|
{ children... }
|
||||||
|
|
@ -113,3 +117,14 @@ templ smoothScrollScript() {
|
||||||
templ htmxCSRFScript() {
|
templ htmxCSRFScript() {
|
||||||
<script src="/assets/js/htmx-csrf.js"></script>
|
<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