Capturing Hotjar User ID in Google Tag Manager & Google Analytics: This is How You Can Enhance User Tracking
In the ever-evolving world of web analytics, understanding user behaviour plays a crucial role in refining website and marketing strategies, and ultimately in achieving business objectives. While there are numerous tools available to track and analyze user behaviour, Hotjar, Google Tag Manager (GTM), and Google Analytics (GA) are among the most popular and versatile ones.
These platforms offer complementary insights into how users interact with a site. Yet, many marketers and analysts are not making the most out of them. This is where the power of integration comes into play. In this comprehensive guide, we will explore how to capture Hotjar User ID in GTM and GA, and why this integration can lead to more actionable data for improving your website’s performance.
What is Hotjar, Google Tag Manager, and Google Analytics?
Before delving into the integration process, let’s briefly discuss what these tools are and how they add value to website analytics.
Hotjar
Hotjar is a powerful web analytics and user feedback tool that offers website owners heatmaps, session recordings, and conversion funnel analysis, empowering them to understand user behaviour and areas for improvement. One of Hotjar’s unique features is assigning a unique User ID for each visitor, allowing analysts to track individual user behaviour throughout their website journey.
Google Tag Manager
Google Tag Manager (GTM) is a popular tag management system enabling users to manage and deploy marketing tags (snippets of code or tracking pixels) on their websites without requiring technical integrations. GTM simplifies tracking across different platforms, providing a unified way of code implementation, thus reducing chances of errors and improving site performance.
Google Analytics
Google Analytics (GA) is a widely-used web analytics service that tracks and reports website traffic, offering insights on user behaviour, audience demographics, conversions, and other key information to guide data-driven decision-making.
Now with a clear picture of these three tools let’s move on to the integration process, enabling you to extract the maximum value from your analytics setup.
Capturing Hotjar User ID in Google Tag Manager and Google Analytics
To begin the integration, follow the steps outlined below to capture Hotjar User ID in GTM and GA:
Get a Free AI Website Audit
Automatically identify UX and content issues affecting your conversion rates with Flowpoint's comprehensive AI-driven website audit.
1. Enable Hotjar User ID
The first step is ensuring that your Hotjar account has the User ID feature enabled. To do this, follow these steps:
- Log in to your Hotjar account.
- Select the appropriate site from the dropdown menu in the top-left corner.
- Navigate to the ‘Settings’ tab, and then go to the ‘Advanced’ sub-tab.
- Locate the ‘User ID Tracking’ section and activate the feature by toggling it on.
2. Create a Custom JavaScript Variable in GTM
The next step involves creating a Custom JavaScript Variable in GTM to store the Hotjar User ID:
- Log in to your Google Tag Manager account.
- Select the appropriate GTM container for your website.
- Navigate to ‘Variables’ and click ‘New’ to create a new variable.
- Name the variable, e.g., ‘Hotjar User ID’.
- Choose ‘Custom JavaScript’ as the variable type.
- Add the following code snippet to the ‘Custom JavaScript’ field:
function() {
if (typeof hj === 'function' && hj('state') === 'hj.loaded') {
return hj('state', 'userId');
} else {
return undefined;
}
}
- Save the variable.
3. Add Custom Dimension in Google Analytics
After capturing the Hotjar User ID in GTM, it needs to be sent as a custom dimension in GA. To do this, follow these steps:
- Log in to your Google Analytics account.
- Select the appropriate GA property.
- Navigate to ‘Admin’ from the bottom-left corner.
- Under ‘Property’, select ‘Custom Definitions’ and then ‘Custom Dimensions’.
- Click ‘New Custom Dimension’ and name it ‘Hotjar User ID’.
- Set the ‘Scope’ to ‘User’ and save the custom dimension.
Note down the ‘Index’ value for the ‘Hotjar User ID’ dimension as it will be required in the next step.
4. Modify Google Analytics Pageview Tag in GTM
Finally, the Hotjar User ID needs to be appended to the GA Pageview Tag in GTM:
- Back in your Google Tag Manager account, navigate to ‘Tags’.
- Locate and edit your existing GA Pageview Tag (or create a new one if necessary).
- In the ‘Configure Tag’ section, select ‘Enable overriding settings in this tag’.
- Expand ‘More Settings’ and then ‘Custom Dimensions’.
- Click ‘Add Row’ and enter the ‘Index’ value noted earlier for the ‘Hotjar User ID’ custom dimension.
- In the ‘Dimension Value’ field, insert the Hotjar User ID variable created in GTM, e.g., .
- Save the tag and publish your changes in GTM.
With these steps completed, you should now be tracking Hotjar User ID in both GTM and GA, allowing you to enhance user tracking and generate more actionable insights from your analytics data.
Why You Should Integrate Hotjar, GTM, and GA
This integration brings forth several key benefits:
- More granular user tracking: Combining Hotjar User ID with GA data enables you to track individual users across multiple sessions, providing richer insights.
- Improve conversion funnels: Correlate heatmap data with user behaviours in GA to better identify areas of on-site friction.
- Optimized campaigns: Track the impact of your marketing campaigns on user behaviour by connecting Hotjar and GA data.
- Personalization opportunities: Leverage the combined data to create more personalized experiences for your users, boosting conversions.
For an even more powerful analytical setup, consider adding Flowpoint.ai to your marketing analytics stack. Flowpoint leverages AI and machine learning to provide valuable recommendations on improvements in your conversion funnels, user behaviour, and overall website performance – giving your analytics initiatives a significant boost.
In conclusion, integrating Hotjar, GTM, and GA can greatly improve your understanding of user behaviour, empowering you to make data-driven decisions that optimize website performance and lead to a better user experience.