My Google Analytics setup for hugo is not working
Asked Answered
L

2

6

I've added my tracking id to my config.toml and everything looks like its matching up. Yet I haven’t seen any realtime data come in when I launch https://analytics.google.com/

theme = "osprey-delight"
tags = ["personal", "homepage", "portfolio"]
# canonifyURLS = true
googleAnalytics = "G-SYJ123456"
disableKinds = ["taxonomy", "taxonomyTerm"] # This theme does not currently use "tag" and "category" taxonomies
enableEmoji = true
pygmentsUseClasses = true

I'm using a theme(osprey-delight) and in the layouts/partials directory, theres a head.html that contains template string, will paste below:

  {{ if .Site.GoogleAnalytics }}
    {{ template "_internal/google_analytics_async.html" . }}
  {{ end }}

When i deploy to firebase, i do see a script tag for ga in my main index.html file in /public directory, here it is below -

<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'G-12345689', 'auto');
    
    ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

What am I missing? I feel like I've don't everything right, but no luck yet.

Lottery answered 24/11, 2020 at 19:16 Comment(0)
P
3

Update February 2020

Below you can find the solution with Universal Analytics, alternatively you can try implementing the solution for Hugo to send data to your GA4 data stream: https://gist.github.com/zjeaton/42246742cdaf2fb46400d04c2eba9a8a#file-analytics-gtag-html


Solution with Universal Analytics

I suggest you create a Universal Analytics Property (as shown in following image) and use the relative identifier UA-XXXXXXX-X (easy way):

enter image description here

Alternatively, if you want to use GA4 Property you have to follow relative syntax: https://developers.google.com/analytics/devguides/collection/ga4

Pareu answered 24/11, 2020 at 23:57 Comment(3)
so i'd add the UA key in my config file?Lottery
Do you have to select this option during property setup or can you add this after the fact? I'm not seeing it in property settings.Witcher
You can find it when you create a new propertyPareu
L
1

Instead of creating a Universal Analytics Property, you can implement the solution for Hugo as proposed by Zachary Eaton and keep your GA4 property: https://gist.github.com/zjeaton/42246742cdaf2fb46400d04c2eba9a8a#file-analytics-gtag-html

Lathe answered 7/2, 2021 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.