added Google Analytics support

This commit is contained in:
Chaoming Li 2024-11-30 22:31:23 +11:00
parent a89df57429
commit 425ed160f0
4 changed files with 19 additions and 0 deletions

View file

@ -19,6 +19,7 @@ A modern and elegant Hugo theme specifically designed for SaaS websites. Built w
- 🎯 Perfect for SaaS and business websites - 🎯 Perfect for SaaS and business websites
- 🛠 Easy to customize - 🛠 Easy to customize
- 📦 No jQuery, minimal JavaScript - 📦 No jQuery, minimal JavaScript
- 📊 Google Analytics support
## Requirements ## Requirements
@ -159,6 +160,8 @@ enableGitInfo = true # Enable Git info for lastmod
description = "Your site description" description = "Your site description"
author = "Your Name" author = "Your Name"
logo = "/images/logo.svg" # Path to your logo logo = "/images/logo.svg" # Path to your logo
# Google Analytics ID (e.g., "G-XXXXXXXXXX")
googleAnalytics = "G-XXXXXXXXXX" # Only enabled in production
# Header Configuration # Header Configuration
[params.header] [params.header]
@ -228,6 +231,7 @@ This configuration includes:
- Header configuration with logo and navigation - Header configuration with logo and navigation
- Call-to-action (CTA) sections - Call-to-action (CTA) sections
- Social media links - Social media links
- Google Analytics configuration (only enabled in production)
- **Navigation Menu**: Main menu structure with dropdown support - **Navigation Menu**: Main menu structure with dropdown support
## Development ## Development

View file

@ -28,6 +28,8 @@ paginatePath = "page"
description = "" description = ""
author = "Chaoming Li" author = "Chaoming Li"
logo = "/images/logo.svg" logo = "/images/logo.svg"
# Google Analytics ID (e.g., "G-XXXXXXXXXX")
# googleAnalytics = "G-XXXXXXXXXX"
# Global CTA Configuration # Global CTA Configuration
[params.cta] [params.cta]

View file

@ -4,6 +4,9 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Google Analytics -->
{{ partial "google-analytics" . }}
<!-- Title --> <!-- Title -->
<title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ .Title }} | {{ .Site.Title }}{{ end }}</title> <title>{{ if .IsHome }}{{ .Site.Title }}{{ else }}{{ .Title }} | {{ .Site.Title }}{{ end }}</title>

View file

@ -0,0 +1,10 @@
{{ if and hugo.IsProduction .Site.Params.googleAnalytics }}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .Site.Params.googleAnalytics }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ .Site.Params.googleAnalytics }}');
</script>
{{ end }}