Recording Events with SparkPage Javascript

Although we usually recommend our API, or an integration partner like Segment, if your primary user interaction is through a web app it can be easier to implement event tracking with our Javascript snippet.

There are two key steps to Javascript event tracking.

Embed the JS Snippet

You can find your JS Snippet in Settings > Javascript

Paste this into the header of your HTML just before </head>. Be sure to modify the user data to match the logged in user. User Id is the only mandatory field (so that we know which user is doing the event), every other field is optional.

You can see more details on this part of the process  here.

Track an Event

Next you want to record a user action as an Event in SparkPage. The most common event to track is when someone clicks on a link, which you would track with the following code:

<a href="google.com" onClick="_spk.track('Clicked Link')">Visit Google</a>

As you can see the _spk.track('Event Name') is the method you need to call. Clicked Link is an example of an Event name. This will appear visible in the SparkPage dashboard and can be used to Trigger individual messages or entire message journeys.

Track Custom Properties

Method Description
_spk.track('Clicked Link') Track an event "Clicked Link" as having happened
_spk.track('Clicked Link', {destination: 'Google', type: 'Button'}) Track an event "Clicked Link" with the properties "Destination = Google" and "Type = Button"

Still need help? Contact Us Contact Us