Event Tracking
Last updated: 12th July, 2024
- Part 1: What is Event Tracking?
- Part 2: Example Code
- Part 3: ➡️ Video Tutorial ⬅️ on setting up an Example Event
What is Event Tracking?
Event tracking allows you to track important actions on your site, such as when a user updates their payment plan, or uses a particular product feature.
Tracked events show on the profile view in GoSquared Contacts, and your top events also show up in the Events widget in the Trends dashboard.
What events can I track?
You can track an event for any action that happens on your site, or on your back-end system. You can name them anything you like, but it’s best to use a clear, concise name.
What can I do with event tracking data?
Once you have event tracking set up you can:
- View your most popular events over a given time frame in the Events widget in Trends.
- Filter profiles in Contacts based on who has triggered a particular event, and use that filter to build a Smart Group.
- Use Smart Group Notifications to receive an alert whenever one of your users triggers a specific event.
How many different event names/types can I track?
Each GoSquared project can track up to 1000 custom events. Above this limit, events with new names will be ignored.
Example Code
The following examples show event tracking using the JavaScript Tracking Code. If you haven’t installed this yet, view our guide to installing GoSquared. For further examples including event tracking using server-side SDKs, see our Event API documentation.
Basic event tracking
Track a single event with a custom name:
_gs('event', 'Name of the event');
Event properties
You can include extra details with the event, which will be shown in the profile view of Customer Data Hub
gs('event', 'Event name', {
extra: 'details',
here: true
})
Inline event tracking
A minimal way to add event tracking is to use an inline handler, such as onclick
, to trigger the event when a user clicks on a particular element.
The following example will track an event for every click on a button;
<button onclick="_gs('event', 'Clicked like button')">Like</button>
You’re not just limited to using the onclick
event — this pattern will work with any of the available DOM Events such as form submissions, media playback, or scrolling.
Tracking events on links
You can also track an event for when a user clicks an outbound link on your site, such as downloading a resource. Since a direct link would cause your site to unload from the user’s browser before triggering the event, we recommend always including the target="_blank"
attribute for these links.
<a href="pdfdownloadlink.pdf" onclick="_gs('event', 'Downloaded PDF')">Download PDF here</a>
Check it works
Once you’ve tracked some events, check the Events widget in Trends to see a summary of the top-fired events within a particular time frame.
Example Video Tutorial
Server-side event tracking
You can also track events against profiles on the server side, using our Tracking API or any of our SDKs. Check out our Event API documentation for further details.