Plan availability
Available for Recordings and Heatmaps with Observe or Observe
Available for Recordings and Heatmaps with Observe
Available for Surveys with Ask or Ask
User Attributes are data about your users sent to Hotjar. They can be used for filtering collected Recordings and Heatmap data, triggering Surveys, or for looking up and deleting user data by user ID. See our guide on What are User Attributes for more details.
With Google Tag Manager (GTM) installed on your live site, you can use a Custom HTML tag and GTM's data layer to send attributes to Hotjar. This enables you to get up and running with User Attributes without manually placing additional code on your site. If you don't have GTM installed on your live site yet, you'll need to get that set up first. Use Google's Setup and install Tag Manager article to learn how.
In this article, we’ll step through sending User Attributes to Hotjar with GTM.
Sending User Attributes with GTM's data layer
The data layer is GTM's repository for structured data. It will need to be set up in GTM before you can send attributes from the data layer to Hotjar. See Google's data layer guide and data layer developer documentation for help with setting up or making changes to your data layer.
Confirm the attributes you're interested in are available in GTM's data layer on your site.
You can check your data layer from your live site by using your browser's developer console and typing dataLayer, then pressing return or enter. You should then see the data layer array appear, which you can be expanded to show what's available in your data layer.
Create a new data layer variable in GTM for the attribute you're interested in.
Data layer variables allow you to pass values from your data layer to GTM tags. You'll find the steps for creating a data layer variable in the Set up the data layer variable section of Google's data layer guide.
You'll need to repeat this step for each attribute you're intending to send to Hotjar from the data layer. Take a note of the name you give each data layer variable to use in the next step.
Create a Custom HTML tag that includes the data layer variable.
To create a Custom HTML tag, follow the steps in the section below called Sending User Attributes with GTM's Custom HTML tag. Include the data layer variable in the Custom HTML tag text field by writing it without quotes and using curly braces.
Sending User Attributes with GTM's Custom HTML tag
From the GTM Overview page, click Add a new tag.
Click on Tag Configuration, then choose Custom HTML.
Include the script that will send the attributes to Hotjar in the HTML field.
Below is an example script included in the HTML field of the Custom HTML tag. These attributes will be sent to Hotjar via our Identify API. If you're using GTM's data layer, you can include the data layer variable using curly braces and without quotes, for example: 'Signed up': {{dlv - Signed up}}.
<script>
window.hj=window.hj||function(){(hj.q=hj.q||[]).push(arguments);};
// Install this entire snippet AFTER the Hotjar tracking code.
var userId = your_user_id || null; // Replace your_user_id with your own variable.
window.hj('identify', userId, {// Add your own custom attributes here. Some EXAMPLES:
// 'Signed up': '2019—06-20Z', // Signup date in ISO-8601 format.
// 'Last purchase category': 'Electronics', // Send strings with quotes around them.
// 'Total purchases': 15, // Send numbers without quotes.
// 'Last purchase date': '2019-06-20Z', // Send dates in ISO-8601 format.
// 'Last refund date': null, // Send null when no value exists for a user.
});
</script>
The Hotjar Tracking Code will need to be loaded on your page before your User Attributes code
If there's a chance that your event would fire on the page before your Hotjar Tracking Code, you will need to add this line of code right before your User Attribute code:
window.hj=window.hj||function(){(hj.q=hj.q||[]).push(arguments);};
Click on Triggering, then select All Pages.
This will send your attributes to Hotjar using GTM on every page view where GTM and Hotjar are installed.
We recommend sending your attributes on every page view
This gives you maximum flexibility for using the attributes for other purposes in the future. It also helps ensure that the most up-to-date attribute values are available inside Hotjar.
Give your tag a name and then click Save.
Confirm the workspace change in GTM by clicking Submit and then clicking Publish.
Ensure you're publishing to your Live Environment in GTM
When submitting changes to your GTM workspace, double-check that the Publish to Environment is set to Live.
Give GTM a moment to update the GTM container on your live site with the changes. Your attributes will be listed on your User Attributes page when they are successfully being sent to Hotjar. You can also follow our guide on manually checking attributes are being sent on your live site.