Note that Google Universal Analytics are deprecated (#1770)

Co-authored-by: Christian Oliff <christianoliff@pm.me>
This commit is contained in:
Patrice Chalin 2022-10-17 23:36:06 -04:00 committed by GitHub
parent 385fa77c60
commit 54c253ab03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,31 +27,40 @@ While the following internal templates are called similar to partials, they do *
## Google Analytics
Hugo ships with internal templates for Google Analytics tracking, including both synchronous and asynchronous tracking codes. As well as support for both v3 and v4 of Google Analytics.
Hugo ships with internal templates supporting Google Analytics, both [Google Analytics 4][GA4] (GA4) and Universal Analytics.
**Note:** Universal Analytics are deprecated. For details, see [Universal Analytics will be going away][].
[GA4]: https://support.google.com/analytics/answer/10089681
[Universal Analytics will be going away]: https://support.google.com/analytics/answer/11583528
### Configure Google Analytics
Provide your tracking id in your configuration file:
Provide your tracking ID in your configuration file:
**Google Analytics v3 (analytics.js)**
{{< code-toggle file="config" >}}
googleAnalytics = "UA-PROPERTY_ID"
{{</ code-toggle >}}
**Google Analytics v4 (gtag.js)**
**Google Analytics 4 (gtag.js)**
{{< code-toggle file="config" >}}
googleAnalytics = "G-MEASUREMENT_ID"
{{</ code-toggle >}}
**Google Universal Analytics (analytics.js)**
{{< code-toggle file="config" >}}
googleAnalytics = "UA-PROPERTY_ID"
{{</ code-toggle >}}
### Use the Google Analytics Template
You can then include the Google Analytics internal template your template:
You can then include the Google Analytics internal template:
```go-html-template
{{ if hugo.IsProduction }}
{{ template "_internal/google_analytics.html" . }}
{{ end }}
```
```
{{ template "_internal/google_analytics_async.html" . }}
```
**Note:** The async template is _not_ suitable for Google Analytics 4.
```
{{ template "_internal/google_analytics.html" . }}
```
If you want to create your own template, you can access the configured ID with `{{ site.Config.Services.GoogleAnalytics.ID }}`.