Event tracking with GoSquared

Events are a versatile way of tracking anything that is happening on your site or app. They are very simple, consisting of a name, and optionally a payload of data to store along with the event. Event payloads are not currently searchable, but they can be viewed on a per profile basis in People CRM.

Take some time to think about the name you give to your events. You can name them anything you like, but it’s best to use a clear, concise name.

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.

Track an event

_gs('event', 'Event Name', {
  extra: 'event',
  details: true
});
var GoSquared = require('gosquared');
var gosquared = new GoSquared({
  site_token: 'your-project-token',
  api_key: 'your-api-key'
});

gosquared.trackEvent('Event Name', {
  extra: 'event',
  details: true
});
require_once('gosquared-php-sdk/main.php');
$GS = new GoSquared(array(
  'site_token' => 'your-project-token',
  'api_key'    => 'your-api-key'
));

$result = $GS->track_event('Event Name', array(
  'extra' => 'event',
  'details' => true
));

Track events for a specific person

When an identified user triggers an event, you can track it with their user ID to associate it with their profile. Once tracked, you can search, filter and sort your users in People to find people who have triggered the event, as well as how many times and when they first and last triggered it.

// so long as the user has been identified `_gs('identify', 'user-id')`, exactly the same as above
_gs('event', 'Event Name', {
  extra: 'event',
  details: true
});
var GoSquared = require('gosquared');
var gosquared = new GoSquared({
  site_token: 'your-project-token',
  api_key: 'your-api-key'
});

var person = gosquared.createPerson('user-id');
person.trackEvent('Event Name', {
  any: 'custom',
  properties: 'here'
});
require_once('gosquared-php-sdk/main.php');
$GS = new GoSquared(array(
  'site_token' => 'your-project-token',
  'api_key'    => 'your-api-key'
));

$person = $GS->Person('user-id');
$result = $person->track_event('Event Name', array(
  'any' => 'custom',
  'properties' => 'here'
));

Track a click event with jQuery

If you’re using jQuery, you can track an event every time a certain button is clicked like so…

$('.my-button').on('click', function() {
  _gs('event', 'Clicked my button');
});

Note, this JavaScript snippet should be inserted as a second, independent snippet at the bottom of your page.

Track all elements with a data-event attribute

Using jQuery, you can automatically track all elements with a data-event attribute. This might make it easier to create and edit events.

$('[data-event]').on('click', function() {
  _gs('event', $(this).data('event'));
});

Note, this JavaScript snippet should be inserted as a second, independent snippet at the bottom of your page.

<!-- any elements can be used - every one with a data-event attribute will be tracked when it is clicked -->

<a data-event="Clicked this button">My button</a>
<button data-event="Clicked another button">Another button</button>

Next Steps