Adding content grouping to Google Analytics integrated in blog via ga()

Hello!

We’re wanting to integrate Google Analytics content grouping in our blog and I’m looking for the best possible method for dropping in a snippet that calls ga() on page load.

Example:

ga('set', 'contentGroup3', 'My Group Name');

We’re using the integrated Google Analytics option in our blog (eg. via Settings > Website > Pages > Tracking integrations

So using that - I don’t think ga() is readily available because it goes through _hsp (I tried calling ga(function() {}) and ga is undefined.

These are two ideas that I had in mind:

1. Rip out GA from the Tracking integrations and put it as a footer snippet customization - we will probably lose a lot of the things that are connected to the integration option so this doesn’t feel like the right thing to do

2. setTimeout() - ugly and not guaranteed

Are there other options? Like is there something that I could call via _hsp?

TIA for the help!

Hey @shaynek

Thank you for the information provided. I’ll tag a few contributors that can share their expertise with you.

Hey @Mike_Eastwood @Aakar @Ben_M any thoughts you can share with @shaynek about this?

Thanks

Sharon

When I’ve worked on this type of request with clients in the past, I would usually recommend removal of the Google Analytics raw code from the Hubspot pages and opting for a tag manager (Google Tag Manager/Adobe Tag Manager) and let that load the analytics on your pages, but also it gives you a much cleaner and more efficient way to fire events for GA in a system like Hubspot then trying to include it on page with their system.

Thanks Ben, I’ll try the GTM approach!