Skip to content

anhtumai/mixpanel-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mixpanel SDK

A type-safe TypeScript library provides stateless async functions to access Mixpanel API. These functions should be easy to test and easy to mock (in case you need to write unit test for your application).

It is created to replace https://github.com/mixpanel/mixpanel-node, which is weakly-typed, complicated and buggy. To fix these problems, this project is written entirely in TypeScript, generates types directly from Mixpanel OpenAPI schema and stays close to the API.

Installation

npm install mixpanel-node

Quick start

Sample usage:

import { ImportEventItem } from "mixpanel-node/types/ingestion/event";

import { configureMixpanelRegion, mixpanelIngestion } from "mixpanel-node";

configureMixpanelRegion("us");

console.log(mixpanelIngestion.profile);

async function main() {
  const importEvent: ImportEventItem = {
    event: "random-event",
    properties: {
      time: Date.now(),
      distinct_id: "sample-distinct_id",
      $insert_id: "sample-insert-id",
    },
  };
  const strictResponse = await mixpanelIngestion.event.importEvents({
    projectId: "sample-project-id",
    auth: {
      username: "username",
      password: "password",
    },
    events: [importEvent],
    strict: 1,
  });
  // type of strictResponse is StrictImportEventResponseData
  console.log(strictResponse.code);
  console.log(strictResponse.status);
  console.log(strictResponse.num_records_imported);

  const nonstrictResponse = await mixpanelIngestion.event.importEvents({
    projectId: "sample-project-id",
    auth: {
      username: "username",
      password: "password",
    },
    events: [importEvent],
  });
  // type of nonstrictResponse is 0 | 1
}

Documentation

Code

List of functions:

Types are imported from mixpanel-node/types

Configure

To configure mixpanel region:

import { configureMixpanelRegion, mixpanelIngestion } from "mixpanel-node";
configureMixpanelRegion("eu"); // value can either be `eu` or `us`

To configure axios, you can import mixpanelAxios from mixpanel-node

import axiosRetry from "axios-retry";

import { mixpanelAxios } from "mixpanel-node";

axiosRetry(mixpanelAxios, { retries: 3 });

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published