Node Quickstart

Welcome to mParticle! Let’s send your first event.

Step 1: Generate your API key

Create a Custom Feed on the Setup page to generate server-to-server API credentials.

Step 2: Install the Node SDK

Install the Node SDK via npm:

npm install mparticle

Step 3: Call the Events API

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);

Step 4: Verify installation

Go to the Live Stream and watch new events come in as you run your script.

Next Steps

πŸŽ‰πŸŽ‰πŸŽ‰ Congrats on sending your first event to mParticle!

Some ideas on what to do next:

Was this page helpful?