Single Page Applications (SPAs) allow your users to browse different pages on your site without having to reload the page completely. In most cases, a SPA website will change the URL in the browser, even though the page is not being reloaded.
By default, Hotjar is usually able to detect and track these SPA URL changes automatically. If a user visits a new page on your SPA site and the URL doesn't change, or fragments are added to the URL that need to be tracked by Hotjar, then you may need to update your Hotjar settings to ensure that Hotjar will correctly track page state changes.
Below are the three URL tracking options that we have available:
- Track changes automatically, excluding fragments (default)
- Track changes automatically, including fragments
- Track changes manually
We have a dedicated article providing more detail on these three URL tracking options.
For more information on each of these options, check out our article: Hotjar Settings for URL Changes
Having trouble getting Hotjar to work on your Single Page Application?
If you're here because you've already set up Hotjar, but some of the tools aren't working as expected, check out our Troubleshooting tips section at the bottom of this article!
The steps outlined below show how you can update the 'Tracking URL' settings.
Click on Settings, then Sites & Organizations.
Click the settings cog icon to open the Site settings for the Site you would like to change.
Under Session targeting & tracking, select the tracking option that works best for your site.
If you are unsure of which tracking options work best for your site, take a look at Hotjar Settings for URL Changes for help.
Click Save Changes.
Troubleshooting tips
Almost all issues that occur on Single Page Application (SPA) sites are solved by one or more of the following solutions:
- Send state changes manually to Hotjar and switch URL tracking to manual ideally.
- If using Events or User Attributes for targeting, send the Event or User Attribute on every route where you want it to take effect (a route is essentially the same as a 'page' on SPAs).
- If you're going to use any sort of automatic URL tracking, target your tools based on URLs only (instead of targeting based on Events or User Attributes), or do one of the steps above.
- Consider using Automatic Tracking with Fragments if your site uses fragments or queries for URL changes. Definitely use this if you're including those queries/fragments in your targeting criteria.