Skip to main content

Sending events

note

This part of the tag setup is entirely optional.

You can send custom events through the tag. For example, you may want to send an event when a button is clicked, or when a purchase is made. Custom events are shown in the activity of the session. If the custom event is classed as a conversion, the session will be converted too.

Before you can send custom events, you'll need to define them in the Hitprobe console. First, select a site (top left directly under the Hitprobe logo). Then select Manage site from the menu. In the Custom events section, click Manage. From there, you'll be able to add a new event.

To send an event, run this JavaScript code anywhere on the page after the Hitprobe tag has been declared:

hp('event', { name: '<custom_event_name>' });

Replace <custom_event_name> with the event name from the custom event you added in the Hitprobe console.

Remember to enclose in script tags if putting it into the body of the page:

<script>
hp('event', { name: '<custom_event_name>' });
</script>
info

If you're using Google Tag Manager, you can send the event using a Custom HTML tag type containing the script above.

tip

You can also send conversion events from your server using the HTTP API.

Using a callback

Often, you'll want to send an event before taking some other action. For example, you may want to register that a button has been clicked, before redirecting the user off to another page.

To make this easier, the event accepts a callback property that is a function that will be called after the event is sent. Use it like this:

hp('event', { name: '<custom_event_name>', callback: myCallbackFunction });

Or using an anonymous callback function like this:

hp('event', { name: '<custom_event_name>', callback: function() {
console.log("Event sent!")
}});
note

If the event fails to send for any reason, the callback will still trigger.