{"id":16625504,"url":"https://github.com/aleclarson/mixpa","last_synced_at":"2025-07-06T04:33:31.362Z","repository":{"id":55051161,"uuid":"329105812","full_name":"aleclarson/mixpa","owner":"aleclarson","description":"Tiny, isomorphic client for Mixpanel","archived":false,"fork":false,"pushed_at":"2021-07-02T22:13:18.000Z","size":76,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-13T04:05:55.229Z","etag":null,"topics":["isomorphic","mixpanel","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aleclarson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-12T20:35:37.000Z","updated_at":"2024-10-07T13:06:40.000Z","dependencies_parsed_at":"2022-08-14T10:10:29.139Z","dependency_job_id":null,"html_url":"https://github.com/aleclarson/mixpa","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fmixpa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fmixpa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fmixpa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fmixpa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleclarson","download_url":"https://codeload.github.com/aleclarson/mixpa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220108227,"owners_count":16595730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["isomorphic","mixpanel","typescript"],"created_at":"2024-10-12T04:05:56.665Z","updated_at":"2024-10-17T16:55:52.576Z","avatar_url":"https://github.com/aleclarson.png","language":"TypeScript","funding_links":["https://paypal.me/alecdotbiz"],"categories":[],"sub_categories":[],"readme":"# mixpa\n\n[![npm](https://img.shields.io/npm/v/mixpa.svg)](https://www.npmjs.com/package/mixpa)\n[![Bundle size](https://badgen.net/bundlephobia/min/mixpa)](https://bundlephobia.com/result?p=mixpa)\n[![Code style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/alecdotbiz)\n\nTiny, isomorphic client for Mixpanel\n\n## Usage\n\n```ts\nimport { create } from 'mixpa'\n\nexport const mp = create({\n  token: '2418e6a0238911541536b590a76e2b01',\n})\n```\n\n### Options\n\n- `token: string`  \n  Your project token.\n\n- `baseUrl?: string`  \n  The domain to send requests to.\n\n- `debug?: 0 | 1 | 2 | 3`  \n  Debug your requests. Higher values inherit the effects of lower values.\n\n  - 1: Log requests to the console.\n  - 2: Enable verbose error messages.\n  - 3: Skip sending requests entirely.\n\n- `onError?: (error: Error, req: MixpaRequest) =\u003e void`  \n   Control what happens when a request fails. You can rethrow the error to force the original caller to handle it, but rethrown errors for non-critical requests are just logged to the console.\n\n- `queueSend?: (send: () =\u003e void, method: string, data: object) =\u003e void`  \n  Control when each request is sent. For example, you might wait for a network connection.  \n  By default, requests are sent immediately.\n\n\u0026nbsp;\n\n### Event Types\n\nTracked events can be strongly typed.\n\n```ts\ntype Events = {\n  openApp: void\n  sharePost: { postId: string }\n}\n\nexport const mp = create\u003cEvents\u003e({ ... })\n\nmp.track('sharePost') // Error: \"sharePost\" is not assignable to \"openApp\"\n```\n\n\u0026nbsp;\n\n### Automatic Retries\n\nUsing the `onError` option, you can implement logic for automatically retrying a failed request.\n\nHere's an example that uses `backo2` for exponential backoff:\n\n```ts\nimport { MixpaRequest, noRetryStatus } from 'mixpa'\nimport Backoff from 'backo2'\n\nfunction onError(error: Error, req: MixpaRequest) {\n  // If this error is from a retried request, rethrow it so the retry\n  // handler is notified. Otherwise, rethrow it only when it's obviously\n  // not a network disconnection.\n  if (req.isRetry || (req.status == noRetryStatus \u0026\u0026 navigator.onLine)) {\n    throw error\n  }\n  return new Promise\u003cvoid\u003e((resolve, reject) =\u003e {\n    const backoff = new Backoff()\n\n    function scheduleRetry() {\n      if (backoff.attempts == 10) {\n        // For critical requests, this will reject their promise.\n        // Otherwise, the error is just logged to console.\n        return reject(error)\n      }\n      setTimeout(() =\u003e {\n        req.retry().then(resolve, scheduleRetry)\n      }, backoff.duration())\n    }\n\n    scheduleRetry()\n  })\n}\n```\n\n\u0026nbsp;\n\n### Notes\n\n- No properties are ever set automatically.\n- You'll want to call `setState` with \"reserved\" properties (eg: `$device_id`) before you track any events.\n- You must've called `setUser` with a string before you can call `setUserProps`.\n\n\u0026nbsp;\n\n### API\n\nTo track an event:\n\n```ts\nmp.track('My Event', { ... })\n```\n\n\u0026nbsp;\n\nTo identify the user:\n\n```ts\nmp.setUser('6ab86a11-9958-4afd-bf01-7a06d8d3f8a4')\n```\n\n\u0026nbsp;\n\nTo forget the user:\n\n```ts\nmp.setUser(null)\n```\n\n\u0026nbsp;\n\nTo update user-specific properties:\n\n```ts\nmp.setUserProps({ ... })\n```\n\n\u0026nbsp;\n\nTo send properties with every `track` call:\n\n```ts\nmp.setState({ ... })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Fmixpa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleclarson%2Fmixpa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Fmixpa/lists"}