Track Page View

_hsq.push(['trackPageView']);

Track a page view. This function is called when the tracking code is loaded on a page, but you can manually call this function to track subsequent views in a single page application.

This function does not support any arguments. The page information is collected automatically:

  • The URL tracked is based on the Referer HTTP header in the request being made by the visitor's browser to HubSpot's tracking servers (modifying the browser history state would update the value used for that header)
  • The title tracked will be the current value of document.title

Note - There are a few things to keep in mind when using this function:
  • As mentioned above, this function is automatically called when the tracking code loads, and there is not a way to prevent that initial call. Calling this function manually before or during the initial page load could lead to duplicate views being tracked. 
  • Currently, trackPageView will not track URL fragments (anything after the # in the URL).
  • If your page uses <link rel="canonical"> tags, the HubSpot tracker grabs that canonical URL in the href attribute of that tag, and will include that canonical URL with any page tracking requests. HubSpot treats the included canonical URL as the true URL of the page, so this tag should not be included if you're manually calling trackPageView to prevent all tracked page views from counting towards the canonical URL.