Skip to content

Implements the Mixpanel tracking call using the HTTP API.

Notifications You must be signed in to change notification settings

manbearshark/node-call-mixpanel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mixpanel from Node

This project is an example implementation of the Mixpanel HTTP API.

See it in action:

Mixpanel HTTP Node

Setup

  1. yarn install
  2. export MIXPANEL_API_TOKEN = [YOUR-MIXPANEL-API-TOKEN]
  3. yarn run compile
  4. yarn run start

The API token is required for this to work, obvi. You can get yours from the Mixpanel project setup screen (copy it from the init call in the script they give you).

Not sure if this is intentional or a bug, but it looks like the Mixpanel HTTP API allows you to pass any token value and still get a 1 back from the API; looks like they do not validate the token in each request, but just return success and ignore your request.

Overview

This project runs in node, using isomorphic-fetch to call the Mixpanel HTTP API. This reads a JSON payload from data.json, adds your Mixpanel token from the environment settings (see above), base64 encodes the payload (as per the Mixpanel spec) and then sends a HTTP POST request to the Mixpanel API endpoint, which is configured in ./src/api/index.js under API_SERVER_URL.

The majority of the work is done in this code:

  let stringJSON = JSON.stringify(data);
  let stringData = (new Buffer(stringJSON)).toString('base64');
  let url = `${API_SERVER_URL}/?data=${stringData}`;
  console.log("Sending: ", stringJSON);
  return callApi(url, { method: 'POST' });

callAPi returns a promise, that is resolved once the call to fetch completes successfully.

There is some simple error checking. This project was a take-home assignment for Segment, which you should be using instead of hacking up HTTP API calls on your own.

About

Implements the Mixpanel tracking call using the HTTP API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published