Learn business growth with Google Analytics 4 Forums Google Analytics 4 Google Analytics GA4: How to get it working with Hugo

  • Google Analytics GA4: How to get it working with Hugo

    Posted by Devin on 14 October 2022 at 3:35 pm

    Hey folks, I need a hand with my website. I’m currently using Hugo with a hugo-renga theme (check this out: https://github.com/nanxstats/hugo-renga/blob/master/exampleSite/config.toml). Google Analytics has been great, but I’ve been trying to move to Google Analytics 4 and I’m running into some roadblocks. I’ve updated the tag in my config.yaml file:

    googleAnalytics: ...
    

    …but that doesn’t seem to be making any difference. Google Analytics isn’t picking up anything from my site.

    I also gave this a try:

    googleAnalyticsID: ...
    

    But no luck with this either. Any ideas on how I can make it work? Any help would be much appreciated!

    Blair replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Liam

    Member
    12 November 2022 at 2:56 pm

    Alright friend, let’s take a deep breath and tackle this!

    Firstly, double-check your config file is set with googleAnalytics="G-XXXXX". Make sure that “G-XXXXX” is your specific measurement id from Google Analytics 4. You can assign it on the Google Analytics site.

    Next, deploy your site with this new change. Once it’s up and running, clear your cache and refresh your site while the Network tab of your Developer tools is open in your browser.

    In the Network tab, apply a filter for “collect”. Look for this term in any calls that show up.

    You’re trying to find your measurement id, that “G-XXXXX”, in the tid property of these calls.

    If your id pops up, you’re golden! It can take a day or two sometimes but soon you should start seeing data show up in your Google Analytics reports. You can also view real-time reports to check it more promptly.

    If it doesn’t, looks like your theme might not recognise the Google Analytics 4 configuration. It could be hard-coded to ignore it. Here’s what we can do about it: tweak your theme to use the correct code, either from the settings or by hardcoding the correct Google Analytics 4 code yourself. Or, stick with your current tracking code (a.k.a. UA tracking code) and use Google’s setup assistant to convert it to Google Analytics 4.

    Honestly, if tracking is a big deal for your site, consider dropping this UA/GA4 setup and use Google Tag Manager instead. It might be more efficient if you’re looking to track more than your typical pageviews.

    Hope this helps, mate! Let me know if you have any more questions.

  • Blair

    Member
    22 December 2022 at 11:53 am

    It sounds like you’re having a bit of trouble integrating Google Analytics 4 with your Hugo site. The issue might be related to the theme’s built-in support. Hugo themes usually support Universal Analytics and not Google Analytics 4. I’d suggest manually inserting the Google Analytics 4 script tag into your site’s header. Make sure to replace the existing Google Analytics tag in the head partial under the layouts directory. Do give it a stab!

Log in to reply.