APIs & Integrations

onvista
Contributor

Tracking Code - Issues when document.readystate is "interactive"

Hey guys,

 

we run an application which permanently shows real-time data on our website. You can toggle this feature on an off. During the last weeks we recognized severe tracking issues with a lot of page visits not being tracked at all.

 

Option A - Real-time data is on:

HubSpot Tracking Script //js.hs-analytics.net/analytics/1600758600000/our_id.js is loaded, but no tracking requests can be found in Chrome Devtools Network tab.

A tracking request can be recognized as follows:
https://track.hubspot.com/__ptq.gif?k=1&sd=2560x1440&cd=24-bit&cs=UTF-8&ln=de-de&bfp=4261286402&v......)

 

Option B - Real-time data is off:

HubSpot Tracking Script is loaded and tracking works perfectly.

 

Reason for the tracking issues:

When real-time data is toggled on, the document status is "interactive" as data is continuously being loaded from the backend. It never switches to document.readystate "complete" or "loaded".

 

BUT: HubSpots Tracking library //js.hs-analytics.net/analytics/1600758600000/our_id.js calls a function named loadHstc() at the bottom of the file. This function checks the documents status (via document.readystate) and starts the tracker. Unfortunately, it does not check for status "interactive" to initialize a tracker, so tracking does not happen when the document has this status 😞

Now to my question:
Is there any way to start the tracking manually even when document.readystate is "interactive"?

2 Replies 2
SimRobin
Member

Tracking Code - Issues when document.readystate is "interactive"

Hello ! 

I'm also interested in this question.

 

I don't understand why the loadHstc function does not run when the document.readyState is interactive

Complete readyState can happen late on most websites because some third-party resources (images, iframes, scripts or stylesheets) can take some time to load.

 

Do you know if we can find a modified version of the tracking script listening to the interactive state instead of the complete state? 

Or is there a way (like in the initial question) to tell Hubspot to execute its code?

Since everything is encapsulated in an IIFE (immediately invoked function expression), I can't interact with any variable not mapped to the window object. 

 

I'll be glad to provide more context or information about this topic.

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Tracking Code - Issues when document.readystate is "interactive"

Hey @onvista ,

This is a great question!  

I wanted to add some people to this conversation who may have some ideas.  Very curious about the answer to this myself!

 

@Mike_Eastwood , @JonPayne   what do you think about manually starting the tracking when interactive?  The last section of the post really sums it up well  

 

Thanks in advance for any thoughts!

d