{"id":4412,"date":"2020-06-08T19:00:16","date_gmt":"2020-06-08T16:00:16","guid":{"rendered":"https:\/\/trackingchef.com\/?p=4412"},"modified":"2020-12-14T19:25:36","modified_gmt":"2020-12-14T16:25:36","slug":"hubspot-pageview-tracking-in-single-page-applications","status":"publish","type":"post","link":"https:\/\/trackingchef.com\/google-tag-manager\/hubspot-pageview-tracking-in-single-page-applications\/","title":{"rendered":"Hubspot Pageview tracking in Single Page Applications"},"content":{"rendered":"\n

Following my previous post on Single Page Application (SPA) tracking with Google Tag Manager (GTM)<\/a>, I also wanted to share the process for the Hubspot pixel.<\/p>\n\n\n\n

The Hubspot pixel is relatively smarter and is able to identify the new route and page title for new pages loaded. All it requires is triggering the Hubspot pixel on every route change.<\/p>\n\n\n\n

Hubspot SPA tracking with GTM<\/h2>\n\n\n\n

This method integrates with the Generic SPA Tracking<\/a> method discussed on a separate post, please make sure you follow the instructions detailed there first.<\/p><\/blockquote>\n\n\n\n

If you’re using GTM, this can easily be done using the Custom Event for SPA.<\/p>\n\n\n\n

\"\"
Pageview Custom Event<\/figcaption><\/figure>\n\n\n\n

On each of these events, trigger the Hubspot pixel, usually set as Custom HTML tag. Note that the full tag isn’t required (learn why<\/a>) and only the Pageview event should be triggered. <\/p>\n\n\n\n

<script>\nvar _hsq = window._hsq = window._hsq || [];\n_hsq.push(['trackPageView']);\n<\/script><\/code><\/pre>\n\n\n\n
\"\"
The Hubspot Pageview event for SPA<\/figcaption><\/figure>\n\n\n\n

The full Hubspot tag should be loaded once, probably on the first page load, using the All Pages trigger.<\/p>\n\n\n\n

If the application doesn’t support route change, you can manually set the new path with this code:<\/p>\n\n\n\n

<script>\nvar _hsq = window._hsq = window._hsq || [];\n_hsq.push(['setPath', {{pagePath}}]);\n_hsq.push(['trackPageView']);\n<\/script><\/code><\/pre>\n\n\n\n

Hubspot SPA tracking without GTM<\/h2>\n\n\n\n

In the case that you’re not using GTM (seriously, what’s wrong with you?), you can still implement the Hubspot tag.<\/p>\n\n\n\n

In this case, you need to ask your developers to fire the Hubspot on each route change (or equivalent History Change).<\/p>\n\n\n\n

var _hsq = window._hsq = window._hsq || [];\n_hsq.push(['trackPageView']);<\/code><\/pre>\n\n\n\n

Similarly, the full Hubspot tag should be loaded once on the initial page load, so that consecutive events are able to fire.<\/p>\n\n\n\n

If the application doesn’t support route change, you can manually set the new path with this code:<\/p>\n\n\n\n

var _hsq = window._hsq = window._hsq || [];\n_hsq.push(['setPath', '\/#\/new-page']);\n_hsq.push(['trackPageView']);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Following my previous post on Single Page Application (SPA) tracking with Google Tag Manager (GTM), I also wanted to share the process for the Hubspot pixel. The Hubspot pixel is relatively smarter and is able to identify the new route and page title for new pages loaded. All it requires is triggering the Hubspot pixel […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,42],"tags":[],"_links":{"self":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4412"}],"collection":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/comments?post=4412"}],"version-history":[{"count":3,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4412\/revisions"}],"predecessor-version":[{"id":4803,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4412\/revisions\/4803"}],"wp:attachment":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media?parent=4412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/categories?post=4412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/tags?post=4412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}