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. This is a little more complicated than subdirectories, so you will need to verify certain settings. Completely separate domains (ex. 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.


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 crazy, 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.


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.


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.


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).

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.


Jon Meck is our Director of Marketing & Training, promoting our services and trainings to the world. He has a jack-of-all-trades background, working for companies large and small in social media, website design and maintenance, and analytics. He is an Excel enthusiast, he loves efficiency, and he is strong proponent of the “Work Smarter, Not Harder” mantra. Jon is also the author of two number puzzle books.

  • Gorka Insausti Marina

    Hi, Jon! Great post as always! I have a question. I’m not using Hubspot but Instapage, a similar lead gen tool. So I’ve got my main website and then a few “instapages”. What would you recommed for proper tracking? One property for all or a property for each (one for the main web, another for instapage #1, another for instapage # 2…)?? Everything is oriented to generate leads. So because they have a similar goal I wonder if it’s necessary to have them separate from each other and the main site. Thanks!!

    • Hey Gorka, Taylen here from Instapage. You can probably keep all of the data on one Google Analytics property instead of separating for each landing page. Now, if your business spans across many different industries or sectors it might be worth separating into different properties. Or, if you have different subdomains for different “websites” that cover different aspects of your business it could be beneficial to separate them by subdomain, but I wouldn’t recommend it if each subdomain is only used for a single landing page.

      If you need to get more granular with the data, you can then separate within GA or come into the Instapage dashboard to views the page data within the Instapage platform. Good luck with your marketing!

  • Future_Vision

    I’m working through the part of this tutorial where you create the custom field in Hubspot. I’ve created one called GA Client ID(ga_client_id) and added under the “Contact” lit of fields. I’ve set it to hidden. I’m not sure what the next step is. You list some jQuery code but where does that go?

    • Future_Vision


      • Hi there – do you have access to add JavaScript to the page anywhere? Perhaps this can go in a footer module. If you have Google Tag Manager, this could be included in a Custom HTML tag inside of Script tags, or it could be added to the site’s JavaScript. Unfortunately, not sure how your particular site is set up or your technical ability – you might need to check in with someone who can help you make modifications to your site scripts.

        • Future_Vision

          GTM all the way. That shouldn’t be an issue to add. I was mainly concerned when this needed to fire.

  • Future_Vision

    What does this code look like? I’ve asked a developer and they thought the GA Client ID was automatically pushed into GA but it sounds like it needs to be captured separately.

    “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.”

    • Future_Vision


      • Sorry, I’m unclear what your question is. The GA Client ID is used by GA to stitch together sessions, but it is not easily accessible as a Dimension inside of Google Analytics. So, in order to make it easily accessible, you add to Google Analytics as a Custom Dimension, then you also add it to your form as a hidden field.

        What does the code look like? It will look very similar to the code directly above that section, as I called out. You’ll need to tweak that and make that work. If you’re using GTM, you can add a custom JS variable that return the client ID.

        Something like:

        function() {
        var clientID = “”;
        ga(function() {
        clientId = ga.getAll()[0].get(‘clientId’);
        return clientID;

        Then this would be piped into your custom dimension field on your Pageview tag or in your GA Settings variable.

  • Future_Vision

    Surprised there is no TOS violation dis dussion here. I’ve heard two sides of the story here. Any word on what the latest is on setting up an integration like this?

  • PHDM3

    Do you have a preference for usings the Google Analytics client ID or the HubSpot Visitor ID identify users? What are the benefits of one vs the other?

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187