Subscribe to callbacks
This part of the tag setup is entirely optional.
You can subscribe (listen out for) events emitted by the agent. Currently, onReady and onBlock callbacks are available.
To do this, you'll need to register a function that will receive each event, right after the tag is declared. See this example for registering a callback for the onReady event:
<script>
(function(h,t,p,r,o,b,e){h['HitprobeObject']=o;h[o]=h[o]||function(){
(h[o].q=h[o].q||[]).push(arguments)},h[o].l=1*new Date();b=t.createElement(p),
e=t.getElementsByTagName(p)[0];b.async=1;b.src=r;e.parentNode.insertBefore(b,e)
})(window,document,'script','https://app.hitprobe.com/p/v1.js','hp');
hp('init', { siteKey: '<your_site_key>' });
hp('onReady', function(sessionId) {
console.log("Hitprobe ready", sessionId);
});
</script>
The highlighted code is the callback that's been added after the tag.
onReady
The onReady event fires once per page load, after the session has been registered (sent to Hitprobe). The function should receive only 1 argument, the sessionId
of the visit.
hp('onReady', function(sessionId) {
console.log("Hitprobe ready", sessionId);
});
onBlock
The onBlock event fires once per page load, only when the visit is blocked. It will fire for both the initial block event, and on each subsequent page load by a blocked visitor. The function should receive only 1 argument, the sessionId
of the visit.
hp('onBlock', function(sessionId) {
console.log("Hitprobe blocked this visit", sessionId);
});
Some events are also emitted as Google Tag Manager datalayer events. See our channel guide for Google Tag Manager to learn how to hook into these events through GTM.