How can I log a pageview without using the Hubspot Javascript?
SOLVE
How can I log a pageview without using the Hubspot Javascript?
I can log events using https://developers.hubspot.com/docs/methods/enterprise_events/http_api just fine (both from our back-end and our own javascript), but they show up as "Analytics activity" (event) under "Activity" in my contacts; I want them to show up as "Page View". I can't find any documentation on how to use a tracking pixel or similar to log page views.
What I found so far is that the tracking pixel for page views seems to be https://track.hubspot.com/__ptq.gif?k=1, but just using that doesn't work, at least the hubid is missing, and the parameters seem very obscure.
I know I can run the hubspot javascript on a separate domain in a hidden iframe to isolate it from our page, but I'd rather not go that route. Tracking a page view using a tracking pixel seems such basic functionality that I can hardly believe that it isn't possible somehow, but maybe I'm just overlooking something.
How can I log a pageview without using the Hubspot Javascript?
SOLVE
In case anyone stumbles over this, we've set up a Caddy (simple web server) in Kubernetes on a special domain (hubspot-data-forwarder.example.com) with the following configuration:
Now whenever we want to track something we can embed a hidden iframe into the page, like this:
$(document).ready(function () {
var data = $('script#hubspot').data();
data['url'] = window.location.href;
var i = document.createElement('iframe');
i.style.display = 'none';
i.src='https://hubspot-data-forwarder.example.com/?' + $.param(data);
document.body.appendChild(i);
});
That way the Hubspot Javascript can't interfere with our page.
It's not perfect but mostly does what we want. The links you get in Hubspot don't work, but that could be fixed by adding a URL forwarding to the Caddy config.
Now, of course it would be much preferred if Hubspot could provide:
* Easy-to-use tracking pixels for page views
* An API that allows to do everything from our backend and not just events
How can I log a pageview without using the Hubspot Javascript?
SOLVE
In case anyone stumbles over this, we've set up a Caddy (simple web server) in Kubernetes on a special domain (hubspot-data-forwarder.example.com) with the following configuration:
Now whenever we want to track something we can embed a hidden iframe into the page, like this:
$(document).ready(function () {
var data = $('script#hubspot').data();
data['url'] = window.location.href;
var i = document.createElement('iframe');
i.style.display = 'none';
i.src='https://hubspot-data-forwarder.example.com/?' + $.param(data);
document.body.appendChild(i);
});
That way the Hubspot Javascript can't interfere with our page.
It's not perfect but mostly does what we want. The links you get in Hubspot don't work, but that could be fixed by adding a URL forwarding to the Caddy config.
Now, of course it would be much preferred if Hubspot could provide:
* Easy-to-use tracking pixels for page views
* An API that allows to do everything from our backend and not just events
Just to confirm, you've reviewed our Track page views endpoint which is called when the tracking code is loaded on a page, but you can also manually call this function to track subsequent views too.
See our documentation here. We can see that once you're able to identify a customer, you can use the following code to manually track a page view:
var _hsq = window._hsq = window._hsq || [];
// Track the page view for the new page
_hsq.push(['trackPageView']);