Adding Google Analytics to the Site
I decided to add Google Analytics to this site, luckily the Clarity theme makes this quite easy. This post details the update required to make Google Analytics work.
One of the features I quite liked about Blogger was the ability to see site traffic for my blog posts. I never did this for vanity reasons, I always knew my posts wouldn’t attract much attention, in 11 years my most read post has has 1908 views so my ego would have had quite a drubbing 🤣. The interest for me was always in where the traffic was coming from rather than how much of it. The times when I did check the stats for my site, I found a lot of the traffic came from Russia and that a good proportion was directed from search engines.
At some point in the past, the detailed stats that I could view in Blogger have gotten removed, now I only see the number of views of posts per day. With the move to a Hugo based blog, I have initially lost site of any page views, however this can be rectified with adding Google Analytics.
The Hugo help docs include a section on integrating with Google Analytics. I think that the idea is the googleAnalytics
property can be filled out and then used in themes, layout partials etc. After a bit of digging though I found that the Clarity theme I use has its own property, ga_analytics, which can be populated with the tracking ID and then analytics just work.
I populated the property with my tracking ID:
ga_analytics = "G-BN8PXXV3V7"
I learnt a couple of things after adding my ID:
- I don’t know whether it’s Hugo or the Clarity theme but the tracking ID isn’t included in locally served version of the site. This screenshot shows that the localhost version of the site is missing the JavaScript that makes tracking work. This is awesome as it means I can still test all my content locally without skewing the stats with where the clicks are coming from.
- Google Analytics doesn’t register your own activity on your site. Again, I think this is awesome as I can use Chrome to browse the hosted site and not see skewed stats. This did throw me at first but a quick test in incognito mode and my page views started to show up.
Indexing the site
Whilst looking at adding analytics, I also investigated the last time Google had indexed my Hugo site, this can be done using the Google search console. Even though the first post was published on 13th October 2021 would you believe it wasn’t in the index 😮, the detail Google gave me about the Hugo site was as follows:
This meant any searches for words used in my posts would not appear in search results:
Why isn’t Google excited about the handful of traffic it’s missing? I could see that my old blog was last indexed in September 2021 and posts could be found doing Google searches:
To rectify this, I clicked the REQUEST INDEXING
button on the URL inspection result and waited. After having some supper I ran another URL inspection, this time I could see that this Hugo site has been indexed by Google now:
This meant any searches for words used in my posts would do appear in search results:
Now that my site content is discoverable by the outside world, and I have Google Analytics integrated with my site I’m waiting for the page views to roll in… In the last 24 hours I have had 1 page view and this was my test in incognito mode, I don’t think I’ll be giving up my day job and banking on being a writer just yet.