POST
/
setPath
Set the current page path
curl --request POST \
  --url https://js.hs-scripts.com/setPath \
  --header 'Content-Type: application/javascript' \
  --data '"_hsq.push(['\''setPath'\'', '\''/about-us'\'']);"'
Set the path for tracking in single-page applications. Use before calling trackPageView to track the correct page.

Usage

var _hsq = window._hsq = window._hsq || [];
_hsq.push(['setPath', '/about-us']);

Single-Page Application Example

<!-- 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>

Notes

  • Essential for tracking page views in single-page applications
  • Always call setPath before trackPageView to ensure accurate tracking
  • The path should start with a forward slash (/)

Body

application/javascript

Path data

The body is of type object.

Response

200

Path set successfully