Developers
The mParticle platform supports many different types of “events,” and the web SDK is a stateful HTTP client for the mParticle Events API. The SDK maintains a current user state (as mentioned in the IDSync and user guides)
The web SDK will queue uploads until the first MPID has been resolved via IDSync, otherwise all uploads are performed immediately on invocation of an API such as logEvent()
. When the SDK performs an upload it does so as an XHR HTTP POST containing:
Please see the events API reference for more information on the schema of mParticle uploads.
An “event” can represent almost any form of activity on your site. Some events are collected automatically by the SDK whereas others must be collected manually.
The following events are collected automatically by the web SDK without needing to write any code:
The following are a subset of the events that must be instrumented manually on your site:
It’s important to use the appropriate event type to track each activity in your app, since event types drive the behavior of mParticle’s integrations. For example, a particular integration might increment the revenue associated with a user in response to a purchase-type event. When you record a purchase as an mParticle “commerce” event, mParticle knows to trigger the partner’s respective revenue APIs. When you record the purchase as a custom event, a record of the purchase may still be forwarded, but the revenue associated with a user may not be incremented, since mParticle will not identify the event as a purchase.
The remainder of this page is concerned only with custom events.
A basic custom event contains:
Custom events are just one type of mParticle event and can themselves be further categorized with a “custom event type.” In most cases, custom event types do not affect how custom events are forwarded to integration partners and the same mapping will be applied across all custom events. However, they can be a useful way to organize your data if you collect a lot of events. For example, data filters in the mParticle dashboard organize custom events by type, allowing you to manage events of the same type in bulk.
EventType = {
Navigation: 1,
Location: 2,
Search: 3,
Transaction: 4,
UserContent: 5,
UserPreference: 6,
Social: 7,
Other: 8
}
You can quickly log a simple event as follows:
mParticle.logEvent(
'Video Watched',
mParticle.EventType.Navigation,
{'category':'Destination Intro','title':'Paris'}
);
Custom flags are used to send partner-specific data points:
Reference the guide for each integration and ask your solutions consultant to see if you need custom flags.
mParticle.logEvent(
'Set Category',
mParticle.EventType.UserPreference,
{},
{'Google.Category': 'Music'}
);
If you have a high-volume event that you would like to forward to kits but exclude from uploading to mParticle, set the Boolean flag shouldUploadEvent
per event.
logCommerceEvent
.mParticle.logEvent(
'Set Interest',
mParticle.EventType.UserPreference,
{},
{},
{shouldUploadEvent: false}
);
Was this page helpful?