Reporting & Analytics

skirkpatrick
Contributor

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Hello Everyone!

 

We are integrating the HubSpot tracking code into our SPA. While iterating in development, our workflow fires up a local environment with live reload, etc, and it all works using localhost. There does not appear to be a way to track page views for test users in HubSpot when the tracking code loads and fires events from localhost. Is there a way to do this?

 

My current workaround personally is a fake subdomain (dev.<root domain>) in my local hosts file that points to localhost and that fake subdomain is configured within HubSpot's reporting advanced tracking as an external site domain, but we'd prefer to not change our current development workflow to accommodate that workaround.

2 Accepted solutions
Derek_Gervais
Solution
HubSpot Alumni
HubSpot Alumni

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Hey @skirkpatrick ,

 

There shouldn't be any setting preventing this by default; the only other thing that might interfere would be if you had the "Limit tracking to these domains" setting turned on, but I can see that you do not.

 

I actually spun up my local server and internally logged into your portal, and I was able to trigger some analytics page view info to appear with localhost info. Can you take a look at the contact record below and let me know if this is showing the data like you'd expect?

 

https://app.hubspot.com/contacts/2058700/contact/152151/

View solution in original post

0 Upvotes
skirkpatrick
Solution
Contributor

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

I can now confirm that I am seeing my page views when firing from localhost. I wish I could say with certainty what was preventing them in my earlier attempts, but I can point at a couple of improvements to my tracking code integration testing that developed along the way:

 

1. I discovered that I was not, in fact, identifying my user by email properly in the tracking code.

 

2. I had a Chrome extension intermittently causing trouble (DuckDuckGo privacy essentials) that I realized I was better off disabling to ensure the page view call to hubspot.com made it through every time.

 

Thanks for all the help and keeping me honest, Derek! It was super helpful to find out that it should work and now it is!

View solution in original post

8 Replies 8
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Hey @skirkpatrick ,

 

I'm not sure I'm clear on the issue here. Is the problem that page views aren't registering in HubSpot? I set up a simple webserver that loads a page with the HubSpot tracking code, and it appears to work just fine. Is it possible that your office's IP address is being filtered from your analytics? (see below)

 

https://knowledge.hubspot.com/articles/kcs_article/reports/exclude-traffic-from-your-site-analytics

skirkpatrick
Contributor

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

That's correct. When I run the web server in a local dev environment and visit the page via https://localhost:8001 (we run on port 8001 in dev) the page views are not registering in HubSpot for an existing HubSpot contact. I add an 'identify' action to the tracking code queue with the corresponding email address. This all works when using a placeholder site domain. It does not reflect on the HubSpot contact activity when loading the tracking code while accessing the page on localhost.

0 Upvotes
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Hey @skirkpatrick ,

 

That's definitely strange; I'm able to get page views from localhost to appear in HubSpot. Did you rule out the office IP filtering? That's a fairly common stumbling block.

 

Also, you mention that you're triggering an 'identify' function call, but that function actually just stores the identity information in the tracker. There needs to be a subsequent 'trackPageView' or 'trackEvent' call to actually push the data into HubSpot. Are you doing that as well?

0 Upvotes
skirkpatrick
Contributor

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Hey @Derek_Gervais ,

 

Thanks for continuing to look - and apologies for not mentioning in my last reply that we are not applying any IP filtering at the moment. So unfortunately, I think we can rule that out as the culprit.

 

I should have also mentioned that we are making the `trackPageView` call within our SPA after each page change to ensure that we are tracking the desired user views within our front end. We fire the `trackPageView` explicitly after the initial js load and that page view has been tracked.

 

Perhaps there is a setting on the HubSpot side that I need to toggle to get the localhost views to work? Everything works great when using that dev subdomain that I registered...

 

-Sean

 

0 Upvotes
Derek_Gervais
Solution
HubSpot Alumni
HubSpot Alumni

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Hey @skirkpatrick ,

 

There shouldn't be any setting preventing this by default; the only other thing that might interfere would be if you had the "Limit tracking to these domains" setting turned on, but I can see that you do not.

 

I actually spun up my local server and internally logged into your portal, and I was able to trigger some analytics page view info to appear with localhost info. Can you take a look at the contact record below and let me know if this is showing the data like you'd expect?

 

https://app.hubspot.com/contacts/2058700/contact/152151/

0 Upvotes
skirkpatrick
Contributor

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Awesome!! That looks perfect. I'm going to reset my dev environment and try again.

skirkpatrick
Solution
Contributor

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

I can now confirm that I am seeing my page views when firing from localhost. I wish I could say with certainty what was preventing them in my earlier attempts, but I can point at a couple of improvements to my tracking code integration testing that developed along the way:

 

1. I discovered that I was not, in fact, identifying my user by email properly in the tracking code.

 

2. I had a Chrome extension intermittently causing trouble (DuckDuckGo privacy essentials) that I realized I was better off disabling to ensure the page view call to hubspot.com made it through every time.

 

Thanks for all the help and keeping me honest, Derek! It was super helpful to find out that it should work and now it is!

Derek_Gervais
HubSpot Alumni
HubSpot Alumni

HubSpot Tracking Code usage in SPA development on localhost

SOLVE

Hey @skirkpatrick,

 

That's great to hear! I've had privacy extensions interfere with my testing more times than I can count, so I totally hear you on that one. Let me know if there's anything more I can help with!

0 Upvotes