TLDR: Stape’s HubSpot server-side tag, when using the ‘trackPageView’ event, sends the wrong user ID when using GA4’s event data (or Stape’s Data Tag/Client). It sends Google’s client_id as the user param to HubSpot’s tracking URL, when it should be sending the value of the hubspotutk cookie, and it doesn’t look possible to fix without forking Stape’s HubSpot template.
Details:
I am using a simple sGTM setup - one Google Tag in the web container sending the page_view event to the server. I am using the same origin setup/Cloudflare/Cookie Keeper. All works fine.
I need to send page view events to HubSpot, ideally server-side. So, I installed Stape’s sGTM HubSpot template, created a tag from it, and chose the ‘Track Page View’ for the tag’s Type. It works: I see the outgoing HTTP request to HubSpot’s tracking server.
But, the issue is that the user information encoded in the parameters of this call is incorrect if you use the default page_view event data sent from the Google Tag (or Stape’s Data Tag). By default, the Stape HubSpot code uses the event data’s client_id value for the user param to HubSpot, when it should be sending the value of the hubspotutk/__hstc cookie(s), and it doesn’t look like there’s any way to change this.
Here’s the relevant code from the Stape HubSpot template:
function trackPageViewEvent() {
let url =
‘``https://track.hubspot.com/__ptq.gif?k=1&v=1.1&ct=’`` + encodeUriComponent(‘standard-page’);
const clientId = eventData.client_id;
if (data.accountId) url = url + ‘&a=’ + encodeUriComponent(data.accountId);
if (clientId) {
url = url + ‘&vi=’ + encodeUriComponent(clientId) + ‘&u=’ + encodeUriComponent(clientId);
}
Note that it’s taking the value of eventData.client_id - which is GOOGLE’s client_id, NOT the one HubSpot needs, and there’s no way to set this in the tag that I can see. I guess I could create my own, separate tag to fire a different event to the server, but I was hoping I didn’t have to.
Here’s the same request from the web client using a custom HTML tag to load the HubSpot tracking script, triggered on All Pages/Page View:
May be hard to see, but the query params include both a ‘vi’ and ‘u’ parameter that contain the value from the hubspotutk cookie for the vi parameter, and the value of the __hstc cookie in the u parameter.
Here’s the value of those same parameters on the outgoing request to HubSpot from the sGTM container via the Stape HubSpot tag:
https://track.hubspot.com/__ptq.gif?k=1&v=1.1&ct=standard-page&a=xxxx&vi=833694887.1747068061&u=833694887.1747068061&b=…
They are incorrect; they are sending the ‘vi’ and ‘u’ params set with Google’s client_id, NOT the value of the hubspotutk/__hstc cookies, which effectively breaks server-side ‘Track Page View’ capabilities when using this tag, because HubSpot will try to associate these page views to a user it knows nothing about. Unless I’m missing something…
Is this a correct assumption here? Will I have to fork the template to read these cookie values myself on the server (it’s passed in the initial Request Headers, so I saved it to a server-side Cookie Value variable)?
Thanks

