Skip to main content

Send events via SDKs

If you're not yet confortable with the "SDK" notion, don't hesitate to consult the Implementation methods article.

Our SDKs offer methods to manage properties and send events.

Tagging methods

The main method you will use is to send an event with properties.

Method: pa.sendEvent(eventName[, eventData, options])

ParametersTypeDescription
eventNamestringName of the event
eventData (optional)objectObject of properties
options (optional)objectObject of options
options.onBeforeBuild(PianoAnalytics, model, next)functionCallback plugged before the event is built. PianoAnalytics is the tracker reference, model is the model of the event, next calls the next step
options.onBeforeSend(PianoAnalytics, model, next)functionCallback plugged before the event is sent. PianoAnalytics is the tracker reference, model is the model of the event, next calls the next step
pa.sendEvent('page.display', {
'page': 'Page name',
'page_premium': false,
'page_authors': ['Clark Kent', 'John Cena']
});

In the following example, we are updating the site ID for the current event:

pa.sendEvent('page.display', {
'page': 'Page name',
'page_premium': false,
'page_authors': ['Clark Kent', 'John Cena']
},{
onBeforeBuild: function (PianoAnalytics, model, next) {
model.setConfiguration('site','123456789');
next();
},
});

You can also send several events using one method:

Method: pa.sendEvents(eventsArray[, options])

ParametersTypeDescription
eventsArrayarrayArray of event objects
options (optional)objectObject of options
options.onBeforeBuild(PianoAnalytics, model, next)functionCallback plugged before the event is built. PianoAnalytics is the tracker reference, model is the model of the event, next calls the next step
options.onBeforeSend(PianoAnalytics, model, next)functionCallback plugged before the event is sent. PianoAnalytics is the tracker reference, model is the model of the event, next calls the next step
pa.sendEvents([ 
{
'name': 'page.display',
'data': { ... }
},{
'name': 'page.scroll',
'data': { ... }
}
]);
tip

In your Data Model, a property is tied to a specific type. When you tag your properties, this type must be the same.

The JSON type is automatically assigned to the property. If you want to assign a specific type to a property, please consult the dedicated ressource in our Collection API article.

Add properties to events

You can add properties to subsequent events, by using specific methods.

Add one property to subsequent events

Method: pa.setProperty(propertyName, propertyValue[, options])

ParametersTypeDescription
propertyNamestringName of the property
propertyValuestring, number, boolean, array (string, boolean, number)Value of the property
options (optional)objectOptions
options.persistentbooleanIndicates whether the property should be sent on all subsequent events (true) or just the next event sent (false - default)
options.eventsstring, arrayEvent names the property will be sent on (all events by default)
pa.setProperty('page_premium', false, {
'persistent': true,
'events': ['page.*', 'click.navigation']
});

This example sends page_premium property on all subsequent page.* and click.navigation events.

Add multiple properties to subsequent events

Method: pa.setProperties(propertiesObject[, options])

ParametersTypeDescription
propertiesObjectobjectKey value pairs of event name and event value
options (optional)objectOptions
options.persistentbooleanIndicates whether the property should be sent on all subsequent events (true) or just the next event sent (false) (default: false)
options.eventsstring, arrayEvent names the property will be sent on (all events by default)
pa.setProperties({
'page_premium': false,
'page_authors': ['Clark Kent', 'John Cena']
}, {
'persistent': true,
'events': ['page.*', 'click.navigation']
});

This example sends page_premium and page_authors properties on all subsequent page.* and click.navigation events.