🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

mixpanel-node

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mixpanel-node

Mixpanel API wrapper for Node.Js Typescript

0.0.17
latest
Source
npm
Version published
Weekly downloads
513
120.17%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

mixpanel

FAQs

Package last updated on 18 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts