0.0.17 • Published 2 years ago

mixpanel-node v0.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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

2 years ago

0.0.16

2 years ago

0.0.14

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago