### Install Mixpanel OpenFeature Provider Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Install the provider package along with the OpenFeature Server SDK and Mixpanel Node.js SDK. ```bash npm install @mixpanel/openfeature-server-provider npm install @openfeature/server-sdk mixpanel ``` -------------------------------- ### Quick Start with Local Evaluation Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Register the local evaluation provider and get a client to evaluate boolean flags with user context. ```typescript import { OpenFeature } from "@openfeature/server-sdk"; import { MixpanelProvider } from "@mixpanel/openfeature-server-provider"; // 1. Create and register the provider with local evaluation const provider = MixpanelProvider.createLocal("YOUR_PROJECT_TOKEN"); await OpenFeature.setProviderAndWait(provider); // 2. Get a client and evaluate flags const client = OpenFeature.getClient(); const showNewFeature = await client.getBooleanValue("new-feature-flag", false, { distinct_id: "user-123", }); if (showNewFeature) { console.log("New feature is enabled!"); } ``` -------------------------------- ### Install Mixpanel-node Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Use npm to install the mixpanel package for your server-side project. ```bash npm install mixpanel ``` -------------------------------- ### Evaluate Basic Boolean Flag Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Get a boolean flag value using the OpenFeature client, providing a flag key, a default value, and user context. ```typescript const client = OpenFeature.getClient(); // Get a boolean flag with a default value const isFeatureEnabled = await client.getBooleanValue("my-feature", false, { distinct_id: "user-123", }); if (isFeatureEnabled) { // Show the new feature } ``` -------------------------------- ### Handle TYPE_MISMATCH Error in OpenFeature Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md When a flag's configured type in Mixpanel does not match the type requested during evaluation, a TYPE_MISMATCH error is returned. This example shows how to check for and handle this specific error code. ```typescript const details = await client.getBooleanDetails("my-flag", false, context); if (details.errorCode === "TYPE_MISMATCH") { console.log("Flag is not a boolean, using default value"); } ``` -------------------------------- ### Get Full Resolution Details for Flag Evaluation Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Retrieve detailed information about a flag evaluation, including the resolved value, variant, reason, and error code if applicable. This is useful for debugging and understanding evaluation outcomes. ```typescript const client = OpenFeature.getClient(); const details = await client.getBooleanDetails("my-feature", false, { distinct_id: "user-123", }); console.log(details.value); // The resolved value console.log(details.variant); // The variant key from Mixpanel console.log(details.reason); // Why this value was returned console.log(details.errorCode); // Error code if evaluation failed ``` -------------------------------- ### Initialization Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Initialize the Mixpanel client with your project token and optional configuration. ```APIDOC ## Initialization ### Description Initialize the Mixpanel client with your project token. You can also configure options like protocol, keepAlive, and debugging. ### Method `Mixpanel.init(token, [options])` ### Parameters - **token** (string) - Required - Your Mixpanel project token. - **options** (object) - Optional - Configuration options: - **protocol** (string) - 'http' or 'https' (default: 'https'). - **keepAlive** (boolean) - Whether to use keep-alive connections (default: true). - **debug** (boolean) - Enable debug logging (default: false). - **logger** (object) - A custom logger instance (e.g., pino, bunyan). ### Request Example ```javascript // Basic initialization var mixpanel = Mixpanel.init(""); // With options var mixpanel = Mixpanel.init("", { protocol: "http", keepAlive: false, debug: true, logger: pinoLogger }); ``` ``` -------------------------------- ### Initialize Mixpanel Client Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Initialize the Mixpanel client with your project API key. This is the first step before sending any events. ```javascript const Mixpanel = require('mixpanel'); const mixpanel = Mixpanel.init('YOUR_PROJECT_API_KEY', { // Optional: configure your options here // api_host: 'https://api.mixpanel.com' }); console.log('Mixpanel client initialized.'); ``` -------------------------------- ### Initialize Mixpanel Client Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Initialize the Mixpanel client with your project API key. This is required before sending any events. ```javascript const Mixpanel = require('mixpanel'); const mixpanel = Mixpanel.init('YOUR_PROJECT_API_KEY', { // optional: set custom host, etc. }); ``` -------------------------------- ### Initialize Mixpanel Client Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Initialize the Mixpanel client with your project token. Options can be provided to customize the connection protocol, disable keep-alive, or specify a custom logger. ```javascript var Mixpanel = require("mixpanel"); var mixpanel = Mixpanel.init(""); ``` ```javascript var mixpanel = Mixpanel.init("", { protocol: "http", }); ``` ```javascript var mixpanel = Mixpanel.init("", { keepAlive: false, }); ``` ```javascript var mixpanel = Mixpanel.init("", { debug: true, logger: pinoLogger, }); ``` -------------------------------- ### Initialize Mixpanel Client Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Initializes the Mixpanel client with your project token. Options can be provided to configure protocol, keepAlive, and debugging with a custom logger. ```APIDOC ## Initialize Mixpanel Client ### Description Initializes the Mixpanel client with your project token. Options can be provided to configure protocol, keepAlive, and debugging with a custom logger. ### Method `Mixpanel.init(token, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Basic initialization var mixpanel = Mixpanel.init(""); // With options var mixpanel = Mixpanel.init("", { protocol: "http", keepAlive: false, debug: true, logger: pinoLogger }); ``` ### Response None (returns a Mixpanel client instance) ### Error Handling Errors during initialization are typically thrown or handled by the provided logger if debug is enabled. ``` -------------------------------- ### Import Batch Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Import multiple historical events simultaneously. ```APIDOC ## Import Batch ### Description Import multiple historical events into Mixpanel in a single request. This is more efficient for bulk imports. ### Method `mixpanel_importer.import_batch(events, [callback])` ### Parameters - **events** (array) - Required - An array of event objects. Each object should have an `event` name and a `properties` object, including a `time` property. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Initialize importer with token and secret var mixpanel_importer = Mixpanel.init("valid mixpanel token", { secret: "valid api secret for project" }); // Import multiple historical events mixpanel_importer.import_batch([ { event: "old event", properties: { time: new Date(2012, 4, 20, 12, 34, 56), distinct_id: "billybob", gender: "male" } }, { event: "another old event", properties: { time: new Date(2012, 4, 21, 11, 33, 55), distinct_id: "billybob", color: "red" } } ]); ``` ``` -------------------------------- ### Initialize Provider with Existing Mixpanel Instance Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Wrap an existing Mixpanel flags provider with the OpenFeature provider. This is useful if your application already has a Mixpanel instance configured. ```typescript import Mixpanel from "mixpanel"; // Your existing Mixpanel instance const mixpanel = Mixpanel.init("YOUR_PROJECT_TOKEN", { local_flags_config: {}, }); const localFlags = mixpanel.local_flags!; localFlags.startPollingForDefinitions(); // Wrap the existing flags provider with OpenFeature const provider = new MixpanelProvider(localFlags); ``` -------------------------------- ### Track an Event Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Track a user event with optional properties. Ensure the client is initialized before tracking. ```javascript mixpanel.track('Signed Up', { "user_id": 123, "plan": "Free", "source": "Google" }); ``` -------------------------------- ### Initialize Local Evaluation Provider Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Create a provider for local evaluation, which polls flag definitions from Mixpanel in the background. This is recommended for minimizing latency. ```typescript const provider = MixpanelProvider.createLocal("YOUR_PROJECT_TOKEN"); ``` -------------------------------- ### People.set Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Create or update a user profile in Mixpanel Engage with a set of properties. ```APIDOC ## People.set ### Description Create or update a user profile in Mixpanel Engage. This method sets specific properties for a given distinct ID. It can also accept options to control behavior like ignoring time updates or setting IP/location. ### Method `mixpanel.people.set(distinctId, [properties], [options], [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user. - **properties** (object or string) - Required - Either an object containing key-value pairs of properties to set, or a single property name (string) to set. - **options** (object) - Optional - Options to control the update behavior. Common options include `$ignore_time`, `$ip`, `$latitude`, `$longitude`. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Set multiple properties for a user mixpanel.people.set("billybob", { "$first_name": "Billy", "$last_name": "Bob", "$created": new Date("jan 1 2013").toISOString(), "plan": "premium", "games_played": 1, "points": 0 }); // Set properties, ignoring $last_seen update mixpanel.people.set("billybob", { plan: "premium", games_played: 1 }, { "$ignore_time": true }); // Set properties with IP address for geolocation mixpanel.people.set("billybob", { plan: "premium", games_played: 1 }, { "$ip": "127.0.0.1" }); // Set properties with latitude and longitude mixpanel.people.set("billybob", { plan: "premium", games_played: 1 }, { "$latitude": 40.7127753, "$longitude": -74.0059728 }); // Set a single property mixpanel.people.set("billybob", "plan", "free"); ``` ``` -------------------------------- ### Import Event Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Import historical events into Mixpanel. ```APIDOC ## Import Event ### Description Import historical events into Mixpanel. This requires initializing the client with a `secret` in addition to the token. Events imported this way must be in the past. ### Method `mixpanel_importer.import(eventName, timestamp, properties, [callback])` ### Parameters - **eventName** (string) - Required - The name of the event. - **timestamp** (Date) - Required - The date and time the event occurred. - **properties** (object) - Required - An object containing event properties, including `distinct_id`. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Initialize importer with token and secret var mixpanel_importer = Mixpanel.init("valid mixpanel token", { secret: "valid api secret for project" }); // Import a single historical event mixpanel_importer.import("old event", new Date(2012, 4, 20, 12, 34, 56), { distinct_id: "billybob", gender: "male" }); ``` ``` -------------------------------- ### Import Old Events Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Initialize a separate Mixpanel client with API secret for importing historical data. Events older than 5 days must be imported using this method. ```javascript var mixpanel_importer = Mixpanel.init("valid mixpanel token", { secret: "valid api secret for project", }); mixpanel_importer.track("old event", { gender: "" }); ``` ```javascript mixpanel_importer.import("old event", new Date(2012, 4, 20, 12, 34, 56), { distinct_id: "billybob", gender: "male", }); ``` -------------------------------- ### Manage User Profiles (People) Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Set or update user profiles with various properties, including names, creation dates, plan details, and game statistics. Options can be provided to ignore time updates or set IP/location for geolocation. ```javascript mixpanel.people.set("billybob", { $first_name: "Billy", $last_name: "Bob", $created: new Date("jan 1 2013").toISOString(), plan: "premium", games_played: 1, points: 0, }); ``` ```javascript mixpanel.people.set( "billybob", { plan: "premium", games_played: 1, }, { $ignore_time: true, }, ); ``` ```javascript mixpanel.people.set( "billybob", { plan: "premium", games_played: 1, }, { $ip: "127.0.0.1", }, ); ``` ```javascript mixpanel.people.set( "billybob", { plan: "premium", games_played: 1, }, { $latitude: 40.7127753, $longitude: -74.0059728, }, ); ``` ```javascript mixpanel.people.set("billybob", "plan", "free"); ``` ```javascript mixpanel.people.set_once( "billybob", "first_game_play", new Date("jan 1 2013").toISOString(), ); ``` -------------------------------- ### Import Multiple Events in Batch Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Import multiple historical events at once using the `import_batch` method. Ensure each event includes a `time` property for accurate historical tracking. ```javascript mixpanel_importer.import_batch([ { event: "old event", properties: { time: new Date(2012, 4, 20, 12, 34, 56), distinct_id: "billybob", gender: "male", }, }, { event: "another old event", properties: { time: new Date(2012, 4, 21, 11, 33, 55), distinct_id: "billybob", color: "red", }, }, ]); ``` -------------------------------- ### Initialize Remote Evaluation Provider Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Create a provider for remote evaluation, which makes a request to Mixpanel's servers for each flag evaluation. Use this for real-time flag values. ```typescript const provider = MixpanelProvider.createRemote("YOUR_PROJECT_TOKEN"); ``` -------------------------------- ### Send Events in Bulk Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Send multiple events in a single request for efficiency. This is recommended for high-volume event tracking. ```javascript const events = [ { event: 'Viewed Page', properties: { 'page': '/home', 'distinct_id': 'user123' } }, { event: 'Clicked Button', properties: { 'button_name': 'Learn More', 'distinct_id': 'user123' } } ]; mixpanel.import_(events); console.log('Bulk events imported.'); ``` -------------------------------- ### Send Data with Callbacks and Batch Tracking Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md All functions sending data to Mixpanel accept an optional callback for error handling. Batch tracking allows sending multiple events in a single request. ```javascript // all functions that send data to mixpanel take an optional // callback as the last argument mixpanel.track("test", function (err) { if (err) throw err; }); ``` ```javascript // track multiple events at once mixpanel.track_batch([ { event: "recent event", properties: { time: new Date(), distinct_id: "billybob", gender: "male", }, }, { event: "another recent event", properties: { distinct_id: "billybob", color: "red", }, }, ]); ``` -------------------------------- ### Create Aliases and Handle Callbacks Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Create an alias for a distinct ID. All functions that send data to Mixpanel accept an optional callback function as the last argument to handle errors. ```javascript mixpanel.alias("distinct_id", "your_alias"); ``` ```javascript mixpanel.track("test", function (err) { if (err) throw err; }); ``` -------------------------------- ### Track Multiple Events in Batch Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Send multiple events to Mixpanel simultaneously using the `track_batch` method. Each event can have its own set of properties. ```javascript mixpanel.track_batch([ { event: "recent event", properties: { time: new Date(), distinct_id: "billybob", gender: "male", }, }, { event: "another recent event", properties: { distinct_id: "billybob", color: "red", }, }, ]); ``` -------------------------------- ### Import Historical Data Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Initialize a separate Mixpanel client with a secret for importing historical data. Events can be imported individually or in batches, specifying timestamps and properties. ```javascript // import an old event var mixpanel_importer = Mixpanel.init("valid mixpanel token", { secret: "valid api secret for project", }); // needs to be in the system once for it to show up in the interface mixpanel_importer.track("old event", { gender: "" }); ``` ```javascript mixpanel_importer.import("old event", new Date(2012, 4, 20, 12, 34, 56), { distinct_id: "billybob", gender: "male", }); ``` ```javascript // import multiple events at once mixpanel_importer.import_batch([ { event: "old event", properties: { time: new Date(2012, 4, 20, 12, 34, 56), distinct_id: "billybob", gender: "male", }, }, { event: "another old event", properties: { time: new Date(2012, 4, 21, 11, 33, 55), distinct_id: "billybob", color: "red", }, }, ]); ``` -------------------------------- ### Manage User Profiles (People) Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Create or update user profiles in Mixpanel Engage. This includes setting properties, optionally ignoring time updates, setting IP addresses for geolocation, and updating specific fields. ```javascript // create or update a user in Mixpanel Engage mixpanel.people.set("billybob", { $first_name: "Billy", $last_name: "Bob", $created: new Date("jan 1 2013").toISOString(), plan: "premium", games_played: 1, points: 0, }); ``` ```javascript // create or update a user in Mixpanel Engage without altering $last_seen // - pass option $ignore_time: true to prevent the $last_seen property from being updated mixpanel.people.set( "billybob", { plan: "premium", games_played: 1, }, { $ignore_time: true, }, ); ``` ```javascript // set a user profile's IP address to get automatic geolocation info mixpanel.people.set( "billybob", { plan: "premium", games_played: 1, }, { $ip: "127.0.0.1", }, ); ``` ```javascript // set a user profile's latitude and longitude to get automatic geolocation info mixpanel.people.set( "billybob", { plan: "premium", games_played: 1, }, { $latitude: 40.7127753, $longitude: -74.0059728, }, ); ``` ```javascript // set a single property on a user mixpanel.people.set("billybob", "plan", "free"); ``` ```javascript // set a single property on a user, don't override mixpanel.people.set_once( "billybob", "first_game_play", new Date("jan 1 2013").toISOString(), ); ``` ```javascript // increment a numeric property mixpanel.people.increment("billybob", "games_played"); ``` ```javascript // increment a numeric property by a different amount mixpanel.people.increment("billybob", "points", 15); ``` ```javascript // increment multiple properties mixpanel.people.increment("billybob", { points: 10, games_played: 1 }); ``` ```javascript // append value to a list mixpanel.people.append("billybob", "awards", "Great Player"); ``` ```javascript // append multiple values to a list mixpanel.people.append("billybob", { awards: "Great Player", levels_finished: "Level 4", }); ``` ```javascript // merge value to a list (ignoring duplicates) mixpanel.people.union("billybob", { browsers: "ie" }); ``` ```javascript // merge multiple values to a list (ignoring duplicates) mixpanel.people.union("billybob", { browsers: ["ie", "chrome"] }); ``` -------------------------------- ### Import Event Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Imports an event that occurred in the past. Requires a separate Mixpanel client initialized with a secret for import operations. ```APIDOC ## Import Event ### Description Imports an event that occurred in the past. Requires a separate Mixpanel client initialized with a secret for import operations. The event must have been tracked once previously for the project to recognize it. ### Method `mixpanelImporter.import(eventName, timestamp, properties)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Initialize importer client var mixpanelImporter = Mixpanel.init("valid mixpanel token", { secret: "valid api secret for project" }); // Track the event once to register it (optional but recommended) mixpanelImporter.track("old event", { gender: "" }); // Import the historical event mixpanelImporter.import("old event", new Date(2012, 4, 20, 12, 34, 56), { distinct_id: "billybob", gender: "male" }); ``` ### Response None (sends data to Mixpanel) ### Error Handling An optional callback can be provided as the last argument to handle errors. ``` -------------------------------- ### Track Batch Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Track multiple events simultaneously. ```APIDOC ## Track Batch ### Description Send multiple events to Mixpanel in a single request. This is more efficient than sending events individually when you have many events to record. ### Method `mixpanel.track_batch(events, [callback])` ### Parameters - **events** (array) - Required - An array of event objects. Each object should have an `event` name and a `properties` object. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript mixpanel.track_batch([ { event: "recent event", properties: { time: new Date(), distinct_id: "billybob", gender: "male" } }, { event: "another recent event", properties: { distinct_id: "billybob", color: "red" } } ]); ``` ``` -------------------------------- ### People.track_charge Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Record a transaction for revenue analytics. ```APIDOC ## People.track_charge ### Description Record a transaction for a user, which will be used for Mixpanel's revenue analytics. ### Method `mixpanel.people.track_charge(distinctId, amount, [properties], [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user. - **amount** (number) - Required - The amount of the transaction. - **properties** (object) - Optional - Additional properties for the transaction. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript mixpanel.people.track_charge("billybob", 39.99); ``` ``` -------------------------------- ### Set Evaluation Context Globally and Per-Evaluation Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Configure evaluation context either globally during provider initialization or on a per-evaluation basis. Per-evaluation context merges with and overrides global context. ```typescript // Global context (set during provider initialization) await OpenFeature.setProviderAndWait(provider); OpenFeature.setContext({ environment: "production" }); // Per-evaluation context (merged with and overrides global context) const value = await client.getBooleanValue("premium-feature", false, { distinct_id: "user-123", email: "user@example.com", plan: "premium", beta_tester: true, }); ``` -------------------------------- ### Track Events Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Track user events with optional properties, including distinct IDs for user identification, or set an IP address for automatic geolocation. ```javascript // track an event with optional properties mixpanel.track("my event", { distinct_id: "some unique client id", as: "many", properties: "as", you: "want", }); ``` ```javascript mixpanel.track("played_game"); ``` ```javascript // set an IP address to get automatic geolocation info mixpanel.track("my event", { ip: "127.0.0.1" }); ``` ```javascript // track an event with a specific timestamp (up to 5 days old; // use mixpanel.import() for older events) mixpanel.track("timed event", { time: new Date() }); ``` -------------------------------- ### Handle PROVIDER_NOT_READY Error Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md This error is returned when flags are evaluated before the local flags provider has finished loading flag definitions. It applies only when using local evaluation. Check the `errorCode` property of the details object. ```typescript const details = await client.getBooleanDetails("my-feature", false, context); if (details.errorCode === "PROVIDER_NOT_READY") { console.log("Provider still loading, using default value"); } ``` -------------------------------- ### People.set_once Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Set a user profile property only if it does not already exist. ```APIDOC ## People.set_once ### Description Set a user profile property only if it has not been set before for that user. This is useful for properties like the first time a user performed an action. ### Method `mixpanel.people.set_once(distinctId, propertyName, propertyValue, [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user. - **propertyName** (string) - Required - The name of the property to set. - **propertyValue** (any) - Required - The value of the property. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript mixpanel.people.set_once("billybob", "first_game_play", new Date("jan 1 2013").toISOString()); ``` ``` -------------------------------- ### Evaluate Mixpanel Flags with OpenFeature Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Use the appropriate OpenFeature evaluation method based on the Mixpanel flag type and its variant values. Ensure the client and context are properly initialized. ```typescript const client = OpenFeature.getClient(); const context = { distinct_id: "user-123" }; // Feature Gate - boolean variants const isFeatureOn = await client.getBooleanValue( "new-checkout", false, context, ); // Experiment with string variants const buttonColor = await client.getStringValue( "button-color-test", "blue", context, ); // Experiment with number variants const maxItems = await client.getNumberValue("max-items", 10, context); // Dynamic Config - JSON object variants const featureConfig = await client.getObjectValue( "homepage-layout", {}, context, ); ``` -------------------------------- ### Handle Transactions and User Deletion Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Record user transactions for revenue analytics, clear a user's transaction history, or delete a user. Deletion can optionally ignore time updates and alias resolution. ```javascript // record a transaction for revenue analytics mixpanel.people.track_charge("billybob", 39.99); ``` ```javascript // clear a users transaction history mixpanel.people.clear_charges("billybob"); ``` ```javascript // delete a user mixpanel.people.delete_user("billybob"); ``` ```javascript // delete a user in Mixpanel Engage without altering $last_seen or resolving aliases // - pass option $ignore_time: true to prevent the $last_seen property from being updated // (useful if you subsequently re-import data for the same distinct ID) mixpanel.people.delete_user("billybob", { $ignore_time: true, $ignore_alias: true, }); ``` -------------------------------- ### Track Event Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Track user events with optional properties, IP address, or timestamp. ```APIDOC ## Track Event ### Description Record an event that occurred in your application. You can include custom properties, an IP address for geolocation, or a specific timestamp. ### Method `mixpanel.track(eventName, [properties], [callback])` ### Parameters - **eventName** (string) - Required - The name of the event. - **properties** (object) - Optional - An object containing event properties. Can include `distinct_id`, `ip`, `time`, and any custom properties. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Track a simple event mixpanel.track("my event"); // Track with properties mixpanel.track("my event", { distinct_id: "some unique client id", as: "many", properties: "as", want: "as you want" }); // Track with IP address for geolocation mixpanel.track("my event", { ip: "127.0.0.1" }); // Track with a specific timestamp mixpanel.track("timed event", { time: new Date() }); // Track with a callback mixpanel.track("test", function (err) { if (err) throw err; }); ``` ``` -------------------------------- ### Import Multiple Events Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Imports multiple historical events in a single request. Each event object must include the event name, timestamp, and properties. ```APIDOC ## Import Multiple Events ### Description Imports multiple historical events in a single request. Each event object must include the event name, timestamp, and properties. ### Method `mixpanelImporter.import_batch(events)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body An array of event objects, where each object has an `event` name and a `properties` object including a `time` field. ### Request Example ```javascript // Initialize importer client (if not already done) var mixpanelImporter = Mixpanel.init("valid mixpanel token", { secret: "valid api secret for project" }); // Import multiple historical events mixpanelImporter.import_batch([ { event: "old event", properties: { time: new Date(2012, 4, 20, 12, 34, 56), distinct_id: "billybob", gender: "male" } }, { event: "another old event", properties: { time: new Date(2012, 4, 21, 11, 33, 55), distinct_id: "billybob", color: "red" } } ]); ``` ### Response None (sends data to Mixpanel) ### Error Handling An optional callback can be provided as the last argument to handle errors. ``` -------------------------------- ### Manage User Transactions and Deletion Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Record user transactions, clear transaction history, or delete user profiles. Options can be provided to ignore time updates or aliases during deletion. ```javascript mixpanel.people.track_charge("billybob", 39.99); ``` ```javascript mixpanel.people.clear_charges("billybob"); ``` ```javascript mixpanel.people.delete_user("billybob"); ``` ```javascript mixpanel.people.delete_user("billybob", { $ignore_time: true, $ignore_alias: true, }); ``` -------------------------------- ### Identify a User Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Identify a user with a distinct ID and optionally set user properties. This helps in tracking user behavior over time. ```javascript mixpanel.people.set('user123', { '$email': 'user@example.com', '$name': 'John Doe' }); console.log('User "user123" identified and properties set.'); ``` -------------------------------- ### Track Events Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Track user events with optional properties, including distinct ID, custom properties, IP address for geolocation, or a specific timestamp. ```javascript mixpanel.track("my event", { distinct_id: "some unique client id", as: "many", properties: "as", you: "want", }); ``` ```javascript mixpanel.track("played_game"); ``` ```javascript mixpanel.track("my event", { ip: "127.0.0.1" }); ``` ```javascript mixpanel.track("timed event", { time: new Date() }); ``` -------------------------------- ### Send Multiple Events Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Send multiple events in a single request for efficiency. Ensure all events are correctly formatted. ```javascript mixpanel.import(['event1', 'event2']); ``` -------------------------------- ### Track an Event Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Track a user event with optional properties. This is a fundamental operation for Mixpanel. ```javascript mixpanel.track('Signed Up', { 'plan': 'Free', 'distinct_id': 'user123' }); console.log('Event "Signed Up" tracked.'); ``` -------------------------------- ### Alias Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Create an alias for an existing distinct ID. ```APIDOC ## Alias ### Description Create an alias for an existing distinct ID. This is useful for merging user data when a user might have multiple distinct IDs (e.g., before and after login). ### Method `mixpanel.alias(originalDistinctId, newAlias, [callback])` ### Parameters - **originalDistinctId** (string) - Required - The existing distinct ID. - **newAlias** (string) - Required - The new alias to associate with the original ID. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript mixpanel.alias("distinct_id", "your_alias"); ``` ``` -------------------------------- ### Track Multiple Events Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Tracks multiple events in a single request for efficiency. Each event can have its own properties. ```APIDOC ## Track Multiple Events ### Description Tracks multiple events in a single request for efficiency. Each event can have its own properties. ### Method `mixpanel.track_batch(events)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body An array of event objects, where each object has an `event` name and an optional `properties` object. ### Request Example ```javascript mixpanel.track_batch([ { event: "recent event", properties: { time: new Date(), distinct_id: "billybob", gender: "male" } }, { event: "another recent event", properties: { distinct_id: "billybob", color: "red" } } ]); ``` ### Response None (sends data to Mixpanel) ### Error Handling An optional callback can be provided as the last argument to handle errors. ``` -------------------------------- ### Access Underlying Mixpanel Instance Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md If the provider was created with `createLocal` or `createRemote`, you can access the underlying Mixpanel instance to send events or update profiles. This property is undefined if the provider was constructed with a flags provider directly. ```typescript const mixpanel = provider.mixpanel; if (mixpanel) { mixpanel.track("button_clicked", { distinct_id: "user-123" }); } ``` -------------------------------- ### People.append Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Append a value to a list property on a user's profile. ```APIDOC ## People.append ### Description Append a value to a list property on a user's profile. If the property is not a list, it will be converted into one. You can append multiple values at once. ### Method `mixpanel.people.append(distinctId, propertyName, propertyValue, [callback])` or `mixpanel.people.append(distinctId, properties, [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user. - **propertyName** (string) - Required - The name of the list property to append to. - **propertyValue** (any or array) - Required - The value(s) to append. Can be a single value or an array of values. - **properties** (object) - Optional - An object where keys are property names and values are the values/arrays to append. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Append a single value to 'awards' mixpanel.people.append("billybob", "awards", "Great Player"); // Append multiple values to different properties mixpanel.people.append("billybob", { awards: "Great Player", levels_finished: "Level 4" }); ``` ``` -------------------------------- ### Create Alias Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Create an alias for an existing distinct ID, which is useful for merging user data from different sources. ```javascript // Create an alias for an existing distinct id mixpanel.alias("distinct_id", "your_alias"); ``` -------------------------------- ### Identify a User Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Identify a user with a distinct ID and set their properties. This is useful for user segmentation. ```javascript mixpanel.people.set('123', { "$email": "user@example.com", "$name": "John Doe" }); ``` -------------------------------- ### OpenFeature Context Mapping to Mixpanel Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md All properties in the OpenFeature `EvaluationContext` are passed directly to Mixpanel's feature flag evaluation without transformation or filtering. The `targetingKey` is not treated specially and is passed as a regular context property. ```typescript // This OpenFeature context... const context = { distinct_id: "user-123", email: "user@example.com", plan: "premium", }; // ...is passed to Mixpanel as-is for flag evaluation ``` -------------------------------- ### Alias a User Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Alias an anonymous user to a registered user. Use this when an anonymous user signs up. ```javascript mixpanel.alias('new_user_id', 'anonymous_user_id'); ``` -------------------------------- ### Handle FLAG_NOT_FOUND Error Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md This error is returned when the requested flag does not exist in Mixpanel. Check the `errorCode` property of the details object to identify this issue. ```typescript const details = await client.getBooleanDetails( "nonexistent-flag", false, context, ); if (details.errorCode === "FLAG_NOT_FOUND") { console.log("Flag does not exist, using default value"); } ``` -------------------------------- ### People.clear_charges Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Clear a user's transaction history. ```APIDOC ## People.clear_charges ### Description Remove all recorded transactions for a specific user. This action is irreversible. ### Method `mixpanel.people.clear_charges(distinctId, [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript mixpanel.people.clear_charges("billybob"); ``` ``` -------------------------------- ### Modify User Profile Properties Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Increment numeric properties, append values to lists, or merge unique values into list properties for user profiles. ```javascript mixpanel.people.increment("billybob", "games_played"); ``` ```javascript mixpanel.people.increment("billybob", "points", 15); ``` ```javascript mixpanel.people.increment("billybob", { points: 10, games_played: 1 }); ``` ```javascript mixpanel.people.append("billybob", "awards", "Great Player"); ``` ```javascript mixpanel.people.append("billybob", { awards: "Great Player", levels_finished: "Level 4", }); ``` ```javascript mixpanel.people.union("billybob", { browsers: "ie" }); ``` ```javascript mixpanel.people.union("billybob", { browsers: ["ie", "chrome"] }); ``` -------------------------------- ### People.union Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Merge values into a list property, ignoring duplicates. ```APIDOC ## People.union ### Description Merge values into a list property on a user's profile, ensuring that duplicate values are not added. This is useful for properties like a list of browsers a user has used. ### Method `mixpanel.people.union(distinctId, properties, [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user. - **properties** (object) - Required - An object where keys are property names and values are the values or arrays of values to merge into the list. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Merge a single value into the 'browsers' list mixpanel.people.union("billybob", { browsers: "ie" }); // Merge multiple values into the 'browsers' list mixpanel.people.union("billybob", { browsers: ["ie", "chrome"] }); ``` ``` -------------------------------- ### People.increment Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Increment a numeric user profile property. ```APIDOC ## People.increment ### Description Increment a numeric property on a user's profile. You can increment by a specific amount or by multiple properties at once. ### Method `mixpanel.people.increment(distinctId, propertyName, [amount], [callback])` or `mixpanel.people.increment(distinctId, properties, [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user. - **propertyName** (string) - Required - The name of the numeric property to increment. - **amount** (number) - Optional - The amount to increment by (default is 1). - **properties** (object) - Optional - An object where keys are property names and values are the amounts to increment by. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Increment 'games_played' by 1 mixpanel.people.increment("billybob", "games_played"); // Increment 'points' by 15 mixpanel.people.increment("billybob", "points", 15); // Increment multiple properties mixpanel.people.increment("billybob", { points: 10, games_played: 1 }); ``` ``` -------------------------------- ### People.delete_user Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Delete a user profile from Mixpanel. ```APIDOC ## People.delete_user ### Description Delete a user profile and all associated data from Mixpanel. Options can be provided to control whether to ignore time updates or alias resolution. ### Method `mixpanel.people.delete_user(distinctId, [options], [callback])` ### Parameters - **distinctId** (string) - Required - The unique identifier for the user to delete. - **options** (object) - Optional - Options to control the deletion process, such as `$ignore_time` and `$ignore_alias`. - **callback** (function) - Optional - A function to be called upon completion or error. ### Request Example ```javascript // Delete a user mixpanel.people.delete_user("billybob"); // Delete a user, ignoring time and alias updates mixpanel.people.delete_user("billybob", { "$ignore_time": true, "$ignore_alias": true }); ``` ``` -------------------------------- ### People.delete_user Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Deletes a user profile from Mixpanel. Options can be provided to ignore time updates or alias resolution. ```APIDOC ## People.delete_user ### Description Deletes a user profile from Mixpanel. Options can be provided to ignore time updates or alias resolution. ### Method `mixpanel.people.delete_user(distinctId, options)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Delete a user mixpanel.people.delete_user("billybob"); // Delete a user with options mixpanel.people.delete_user("billybob", { $ignore_time: true, $ignore_alias: true }); ``` ### Response None (sends data to Mixpanel) ### Error Handling An optional callback can be provided as the last argument to handle errors. ``` -------------------------------- ### Alias a User Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/mixpanel/readme.md Alias a previous distinct ID to a new distinct ID. This is useful when a user's identifier changes. ```javascript mixpanel.alias('new_user_id', 'old_user_id'); console.log('User aliased from "old_user_id" to "new_user_id".'); ``` -------------------------------- ### People.increment Source: https://github.com/mixpanel/mixpanel-node/blob/master/readme.md Increments a numeric user profile property by a specified amount. Can increment multiple properties at once. ```APIDOC ## People.increment ### Description Increments a numeric user profile property by a specified amount. Can increment multiple properties at once. ### Method `mixpanel.people.increment(distinctId, propertyName, incrementValue)` `mixpanel.people.increment(distinctId, properties)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Increment a single property by 1 mixpanel.people.increment("billybob", "games_played"); // Increment a single property by a specific value mixpanel.people.increment("billybob", "points", 15); // Increment multiple properties mixpanel.people.increment("billybob", { points: 10, games_played: 1 }); ``` ### Response None (sends data to Mixpanel) ### Error Handling An optional callback can be provided as the last argument to handle errors. ``` -------------------------------- ### Shutdown OpenFeature API Source: https://github.com/mixpanel/mixpanel-node/blob/master/packages/openfeature-server-provider/README.md Clean up resources by closing the OpenFeature API when your application is shutting down. ```typescript await OpenFeature.close(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.