Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Google Analytics setup for hugo is not working

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.

like image 900
sisternight438 Avatar asked Oct 14 '22 23:10

sisternight438


1 Answers

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

like image 152
Michele Pisani Avatar answered Oct 21 '22 04:10

Michele Pisani