This feature is only available on the Plus and Business plan.
To see if one of our paid plans suits your site better, check out everything our Plus and Business plans have to offer in Hotjar Plans.
Starting Recordings with JavaScript triggers are useful for when you want Recordings to start capturing after your visitor has reached a specific part of the page you are targeting.
This feature is also available for Feedback Widgets and Heatmaps.
Open up your Site Settings
For more information, read our guide to configuring Site settings.
Choose the specific page or JavaScript trigger option in Session targeting and tracking.
Add the trigger name to a JavaScript trigger rule.
You can select the '+' icon if you would like to add another targeting rule. Only alphanumeric characters (a-z, A-Z, 0-9), underscores (_), and dashes (-) can be used in the trigger name.
Triggers and other targeting rules
If a trigger is present on a page, it will take priority over any other rules present. Triggers take precedence over URL targeting rules.
Click Done.
Add the trigger code to your website.
In the example above, you've created a trigger called checkout_out. Next, you will need to add the trigger code to your website:
hj('trigger', 'checkout_out');
The trigger needs to be added after the Hotjar Tracking Code
If it is added before, a JavaScript error will occur.
If you wanted the Recording to trigger when the user completed a specific action, you would add this line of code to one of your JavaScript functions:
function yourSignupFunction() { ... your code here ... hj('trigger', 'signup-survey'); }
//Remember that this function needs to be called for the trigger to be
executed i.e. yourSignupFunction();
Important
If there is a chance that the code will be run before the Hotjar script has loaded, you must add the following line of code just before the trigger function:
window.hj=window.hj||function(){(hj.q=hj.q||[]).push(arguments)};
You can also set up JavaScript Triggers through Google Tag Manager.
If you use Google Tag Manager to load the Hotjar script on your site, you can set up JavaScript Triggers on the GTM tag that fires the Hotjar tracking code. Check out this guide on how to set up JavaScript Triggers in GTM.