Best Practices For Using HubSpot And Google Analytics Together

November 1, 2016 | Jon Meck
Best Practices For Using HubSpot And Google Analytics Together

HubSpot users love the automated marketing and sales platform for many reasons, including the ability to easily create landing pages, drive inbound campaigns, and connect directly with their customers. In addition, HubSpot offers some reporting options to help measure and track how your campaigns perform, how many leads you have driven, and which channels are driving the most traffic.

The tool can be used in a variety of ways and with varying amounts of time investment, and like most tools, we have found that pairing HubSpot with Google Analytics can enhance both tools. Google Analytics will not replace HubSpot, but rather will help you measure its impact on your site’s goals and help you to more clearly evaluate its efficacy in addition to your other traffic drivers.

Below, I’ll discuss a few best practices and some more advanced ways to integrate HubSpot and Google Analytics.

HubSpot Website Pages

One of the great features of HubSpot is the ability to create templated websites or branded landing pages for your website. Often, these special HubSpot pages will live on a subdomain or even an entirely different domain, and that means that Google Analytics tracking may not be exactly straightforward. Users may interact with your landing pages or they may interact with your website or they may interact with both. Proper Google Analytics implementation will be necessary to make sure these users are tracked consistently between the two.

Subdomain vs Subdirectory vs Different Domain?

The different subscription levels of HubSpot come with different options, so make sure you understand what your subscription level will include. If you have the choice, subdirectories have the least amount of extra setup required to work properly with Google Analytics. If you’re still planning your implementation, definitely choose this option for your blog if it’s an option!

Often, the custom landing pages will live on a separate subdomain (ex. info.bounteous.com). This is a little more complicated than subdirectories, so you will need to verify certain settings. Completely separate domains (ex. bounteousdownloads.com) will make tracking the two sites together inside of Google Analytics very complicated, so I wouldn’t recommend this without understanding all of the implications related to your analytics.

Basic Google Analytics Tracking

The first step is getting Google Analytics tracking on all of your site pages, regardless of whether they live in your CMS or are being loaded from HubSpot.

HubSpot has an easy setting to help with placing Google Analytics tracking code on page. Basic pageviews can be tracked by filling in your Google Analytics tracking ID into the settings. This is the easiest option, but perhaps not the most flexible.

Adding Google Tag Manager

HubSpot also allows you to edit the site’s header HTML, which will give us more options. Ideally, you’re already using a tool like Google Tag Manager to help with your tracking. If so, we can insert the top half of your Google Tag Manager snippet into the header HTML. This will work for all users that come to your site with JavaScript. The second portion of the Google Tag Manager snippet can be either placed in the footer HTML, or left off completely if you don’t require support for non-JavaScript enabled users.

gtm-snippet-head

Now that we’ve added Google Tag Manager, it’s pretty easy to add a Google Analytics tag across all of your pages. We won’t go into all of the details here, but a few things to check.

  • Make sure you only have Google Analytics tracking on your pages once. If you have filled in your GA tracking ID in the HubSpot settings, then do not also fire GA through Google Tag Manager.
  • If you are using the subdomains option, make sure you follow the steps to getting subdomain tracking working properly. This may involve updating the cookie domain settings in your Pageview tag.
  • If you have completely separate domains, you’ll need to tackle cross-domain tracking, but remember this only works if users click between the two websites.

Next Level Google Analytics Tracking

HubSpot landing pages are rich with information. Call-to-actions and forms are valuable drivers to get those leads, but they’re also opportunities to supplement your Google Analytics information.

Track. Everything.

Ok, maybe let’s not go too wild, but let’s see how many clicks those big download buttons get, and let’s capture the information that someone fills into a form and save that information into Google Analytics.

hubspot-form-ga

All of this is possible with Google Tag Manager on your page, and we have plenty of tutorials and recipes to help you get started!

Emails From HubSpot

When you send out emails and drive traffic to your HubSpot pages, whether you’re using HubSpot’s automated platform, a tool like MailChimp, or some other email platform, these emails absolutely need to be tagged with UTM parameters. This is information that YOU know, what email did you send, what was the campaign, etc. We tack on some extra text to the end of the URL to help us take credit for any traffic that is driven from that particular link.

Emails that come from HubSpot can be automatically tagged with UTM parameters, following this email tracking guide from HubSpot.

In fact, HubSpot has a pretty handy option here that gives you the choice when you’d like to add URL parameters. You definitely want to add tracking, and there’s a great option that will let you add parameters unless the links are already tagged.

hubspot-source-tracking

For emails that you’ll send out via other platforms, you’ll need to manually created tagged links to make sure they’re properly be tagged. HubSpot has a guide for that too, and it’s easy to create a link to your site with the appropriate parameters, or tracking URLs as HubSpot refers to them.

hubspot-tracking-url-builder

Custom Information In/Out of HubSpot

In addition to collecting information about how our HubSpot emails and landing pages are performing, we can also pass information back and forth that will give us the greatest amount of flexibility in the long run for connecting our different platforms. This is the advanced stuff.

We’ve written about the need for a common key before, a unique identifier that we can use that exists in two different systems. We’ve talked about it with SalesForce and Marketo. The same concept applies here. We’ll be pushing the Google Analytics client ID into both Google Analytics and HubSpot, though you can also go the other way and push the HubSpot Visitor ID into both systems.

Custom Properties allow storing information per contact or per company. We’ll make use of per-contact properties in our GA integration. HubSpot doesn’t use these properties internally, but keeps them with the contact record. A Custom Property could be used to store the Google Analytics Client ID so that we can later combine the client record in HubSpot and Google Analytics. The Google Analytics Client ID is, itself, an opaque identifier for each device which has accessed your site and does not itself contain any information about the device or visitor.

When using HubSpot Forms, a hidden field with the name of the custom HubSpot Property used to contain the Client ID must also be placed in the form. Before submitting the form to HubSpot, the Client ID must be extracted from Google Analytics and placed into the hidden form field manually. The following snippet of code is an example of how this may be accomplished (using jQuery).

$("#form-id").submit(function() {
    ga(function() { 
        var clientId = ga.getAll()[0].get('clientId');
         $("#hidden-client-id").val(clientId);
    });
})

Getting the Client ID into Google Analytics

You will need to simply create a new Custom Dimension, for example, “GA Client ID” and follow a similar method to the JavaScript above to grab the Client ID and pass it into Google Analytics when sending a hit, such as a pageview.

How to Combine the Data

Once the Client ID is stored, there is a link between the client record in HubSpot and in Google Analytics that we can use in many powerful ways. We are now able to connect specific web visitors on our site with their HubSpot profiles, and with some data manipulation begin to derive better insights.

To bring extra metadata into Google Analytics, we can now use the data import feature to export data from HubSpot and import the data into Google Analytics, keying off of the GA Client ID Custom Dimension we created.

In addition, the Client ID stored in HubSpot, you can begin to take advantage of the Measurement Protocol, passing hits to Google Analytics that occur offline. Purchases, conversions, or even activities like phone calls can be sent to Google Analytics and, because you now have the ability to pass the correct Client ID with the hit, you’ll connect to that particular user’s previous and future web history via the API or, for Analytics 360 customers, BigQuery.

As you’re setting up Google Analytics and HubSpot, remember to start with the basics. Make sure pageview tracking is implemented and working correctly. Follow best practices for tracking emails and other traffic drivers. And finally, consider more advanced integrations. With HubSpot and Google in lockstep, you will find boundless ideas of what can be done with your data, and how these two tools together can improve your marketing and prove your return on investment.