Session Unification with User-ID

Use a system User-ID to unify tracking data across systems.

Google Analytics also allows you to pass a system based user ID to Google Analytics. This helps you link sessions together. Eg. if a user logs in to your system you can push their user ID to Google Analytics to connect all their activity together. More info here.

Unify analytics using the HubSpot Contact ID

If you do not have a login system you could also use the HubSpot contact ID to achieve the same things. When a contact is created in HubSpot they are assigned a unique ID by HubSpot.

If you are using the HubSpot CMS or landing pages you can output this into your template so it can push this ID to Google Analytics. 

The most powerful part about using the HubSpot Contact ID is if the user is cookied via a form submit or clicked on a HubSpot email link. HubSpot will know who these people are as they click around your website. 

There are a few different versions of the Google Analytics Tracking code. You will need to remove either

ga('set', 'userId', '{{ personalization_token('contact.hs_object_id', '') }'); //Universal Analytics Tracking Code (Remove one)

or

gtag('set', {'user_id': '{{ personalization_token('contact.hs_object_id', '') }'}); //Global Site Tag Tracking Code (Remove one)

From the script below: (download here - as we are using HubSpot for this FAQ it was swapping out the personalisation token in the code snippet)

userid_ga_for_hubspot_unification_txt

Note the:  personalization_token('contact.hs_object_id', '') this will insert the HubSpot Contact ID into the script. (this will only work on HubSpot generated pages)

{% set current_path = '@hubspot/themes/knowledge/components/_related_articles.html' %} {% set current_path = '@hubspot/themes/knowledge/templates/kb-article.html' %}