Docs

Analytics

Posted on August 14, 2024  (Last modified on August 16, 2024) • 1 min read • 202 words
Share via

Enable analytics for your website to view usage statistics and more.

Configuration  

Hinode supports Google Analytics 4 out-of-the-box. Simply add your Google property (starting with G-) to the configuration in config/_default/hugo.toml.

[services]
  [services.googleAnalytics]
    ID = "G-xxxxxxxxxx"

Default Behavior  

Review the next sections to understand the default behavior when dealing with web analytics.

Anonymous Users  

Hinode anonymizes the visitor’s IP address when the client sends a Do Not Track request.

Local Development  

By default, analytics is disabled when running on a local machine to prevent pollution of the gathered insights. Modify the condition (not site.IsServer) as needed.

The file assets/js/analytics.js defines the JavaScript template that is ingested into the main bundle.

{{- $pc := .Site.Config.Privacy.GoogleAnalytics -}}
{{- if (and (not .Site.IsServer) (not $pc.Disable)) -}}
[...]
{{- end -}}

The partial layouts/partials/footer/scripts.html loads the Google Tag Manager if applicable.

{{- if and (not site.IsServer) $header -}}
[...]
{{- end -}}

Content Security Policy  

Google Analytics Requires Several Content Security Policies  to be set in the Server Headers. Hinode has enabled access for Google Analytics 4 by default. The following settings are added to config/_default/server.toml. Similar settings are defined in the netlify.toml file provided in the repository’s root when deploying to Netlify  .

script-src:  https://*.googletagmanager.com
img-src:     https://*.google-analytics.com https://*.googletagmanager.com
connect-src: https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com