Track custom events

{!sdk/tracking-intro.md!} here.

Tracking events

You can use the track SDK method to record your custom events.

To track a custom event, you need to name it:

const Sqreen = require('sqreen');
Sqreen.track(event.name)

Our SDK supports optional parameters, such as properties:

const Sqreen = require('sqreen');
Sqreen.track(event.name, {properties: {foo: 'bar'}})

When creating automation playbooks using this event, you can use those properties to group events and apply conditions and detections.

{!sdk/tracking-default-properties.md!}

Track method definition

const Sqreen = require('sqreen');
Sqreen.track(event_name, [options])

{!sdk/track-method-definition.md!}

{!sdk/user-tracking.md!}

{!sdk/tracking-send-past-events.md!}

const Sqreen = require('sqreen');

const event_date = new Date(2018, 3, 15, 14, 42, 0)
Sqreen.track(event.name, {
    properties: {foo: 'bar'},
    timestamp: event_date
})

Integration with Express

Sqreen provides middleware to simplify the integration with Express. Here is an example:

const Sqreen = require('sqreen');

// Register the Sqreen Express middleware in the app
app.use(Sqreen.middleware)

app.get('/path/:parameter', (req, res, next) => {
    req.sqreen.track('foobar', {
        properties: {
            prop1: 'value1',
            prop2: 'value2'
        }
    });
    // rest of the code goes here
});

{!sdk/tracking-next-steps.md!}

{!sdk/tracking-error-handling.md!}