Google Analytics is an analytics service that enables you to measure traffic and engagement across your websites and apps.

Using Google Analytics GA4 with CSP

Don’t forget to update your Content-Security-Policy HTTP response header when using Google Analytics. See an example

Prerequisites

To follow this guide, you’ll need an existing Thulite site and a Google Analytics 4 property.

Add script

Add to layouts/partials/head/script-header.html:

{{ template "_internal/google_analytics.html" . }}

Add tracking ID

Add your tracking ID to config/_default/hugo.toml:

[services]
  [services.googleAnalytics]
    ID = 'G-MEASUREMENT_ID'

Resources