@rankmathseo/nodejs-mixpanel
v1.0.11
Published
Standardized Node.js library that wraps Mixpanel's tracking functionality, providing a consistent interface for all teams to use across projects.
Readme
nodejs-mixpanel
Standardized Node.js wrapper for Mixpanel that enforces consistent tracking behavior, anonymization, and cache key generation.
Installation
npm i @rankmathseo/nodejs-mixpanelUsage
Import and initialize
import { MixpanelTracker } from '@rankmathseo/nodejs-mixpanel';
const mixpanel = new MixpanelTracker('your-mixpanel-token', {
host: 'api-eu.mixpanel.com', // optional override
path: '/track/?ip=0', // optional override
// ... other configration properties
});Track an Event
mixpanel.track('The Event Name', 'the_distinct_id_for_this_event' {
brand: 'Your Brand',
product: 'Your Product',
// ... other event properties
});Return the User ID hash
const userIdHash = mixpanel.identify('[email protected]'); // hashes internallyUtility Functions
Hash Sensitive Values
Hashes the given value using SHA224.
import { hash } from '@rankmathseo/nodejs-mixpanel';
const hashed = hash('[email protected]');Generate Cache Keys
Generates a consistent Redis cache key for user-based tracking.
import { getCacheKey } from '@rankmathseo/nodejs-mixpanel';
const key = getCacheKey('[email protected]', '/api/user/profile');
// → mixpanel:user:<hashed_email>:_api_user_profile