Create a Custom Feed on the Setup page to generate server-to-server API credentials.
Install the Node SDK via npm:
npm install mparticle
Integrate mparticle in your Node app.
var mParticle = require('mparticle');
var api = new mParticle.EventsApi(new mParticle.Configuration(
'YOUR_API_KEY',
'YOUR_API_SECRET'));
var batch = new mParticle.Batch(mParticle.Batch.Environment.development);
batch.user_identities = new mParticle.UserIdentities();
batch.user_identities.customerid = '123456' // identify the user (required)
batch.user_attributes = {'hair color': 'brown'}
var event = new mParticle.AppEvent(mParticle.AppEvent.CustomEventType.navigation,
'Hello World');
batch.addEvent(event);
var body = [batch]; // {[Batch]} Up to 100 Batch objects
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully.');
}
};
api.bulkUploadEvents(body, callback);
Go to the Live Stream and watch new events come in as you run your script.
Congrats on sending your first event to mParticle!
Some suggestions on what to do next:
Was this page helpful?