Note
This feature is only available on the Plus and Business Plan.
What are JavaScript triggers?
JavaScript triggers are lines of code which you add to your site in order to trigger a Hotjar feature at a specific moment during your visitor's session.
This feature is also available for Heatmaps, Polls, Surveys, and Recruiters.
Why would you need JavaScript triggers?
Here are a few examples of how JavaScript triggers could be used:
- You want to start a Recording after your visitor has reached a specific part of the page.
- You want the Recording to appear as soon as your visitors have started their order.
Triggers and other targeting rules
If a trigger is present on a page, it will cause a widget, a Poll, Survey, Incoming Feedback or Recruiter, to show regardless of any other rules present. Triggers take precedence over other targeting rules.
Using JavaScript triggers
Click on Visit a specific page or a JavaScript trigger fires.
Select JavaScript trigger from your page targeting panel.
Enter a name you would like to use as your trigger.
Enter the name of the trigger. You can select the '+' icon if you would like to add another targeting rule
Only alphanumeric characters, dashes and underscores can be used in the trigger name.
Click Done.
Add the trigger code to your website.
In the example above, you've created a trigger called check_out. Next, you will need to add the trigger code to your website:
hj('trigger', 'check_out');
Note
This code must be added at any point 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.
Example:
function newsletterSignup() { ... hj('trigger', 'signup-poll'); }
Important
If there is a chance that the code will be run before the Hotjar script has loaded, you must add this line of code just before:
window.hj=window.hj||function(){(hj.q=hj.q||[]).push(arguments)};