0

Hubspot Analytics & Single Page Apps

Does Segment handle passing the subsequent page views for single-page apps per Hubspot's SPA recommendations?

Here is their recommendation:

Tracking in single-page applications

The HubSpot tracking code will automatically record a page view when the code is first loaded, but you can also manually track page views in a single-page application without reloading the tracking code. You can use the setPath and trackPageView functions to update and track the current page:

<!-- Set up the path for the initial page view -->
<script>
  var _hsq = window._hsq = window._hsq || [];
  _hsq.push(['setPath', '/home']);
</script>

<!-- Load the HubSpot tracking code -->
<!-- Start of HubSpot Embed Code -->
  <script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/{hubId}.js"></script>
<!-- End of HubSpot Embed Code -->

<!-- Tracking subsequent page views -->
<script>
  var _hsq = window._hsq = window._hsq || [];
  _hsq.push(['setPath', '/about-us']);
  _hsq.push(['trackPageView']);
</script>

See the documentation for setPath and trackPageView for more details on those functions.

1reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Mike,

    Yes, Segment's analytics.js library can handle subsequent page calls for SPA. Every analytics.page() call will trigger a page view in Hubspot. I would recommend moving the analytics.page() method from the JS snippet into your router method, so that a page call is fired every time a new page is rendered.

    Best,

    Xavier

    Reply Upvote
reply to topic