@chamaeleonidae/amplitude-plugin
v1.0.0
Published
Amplitude Browser SDK destination plugin that syncs user attributes to Chameleon
Readme
@chamaeleonidae/amplitude-plugin
Amplitude Browser SDK destination plugin that intercepts $identify events and forwards user attributes to Chameleon via chmln.identify().
Install
npm install @chamaeleonidae/amplitude-pluginUsage
import * as amplitude from '@amplitude/analytics-browser';
import { ChameleonPlugin } from '@chamaeleonidae/amplitude-plugin';
amplitude.add(new ChameleonPlugin('YOUR_CHAMELEON_TOKEN'));
amplitude.init('YOUR_AMPLITUDE_API_KEY');The Chameleon SDK (chmln.js) must be loaded on the page. If window.chmln is not yet available when an $identify event fires, the plugin queues the call and polls with exponential backoff (~4 seconds total) until the SDK loads.
How it works
When Amplitude dispatches an $identify event, the plugin:
- Extracts
user_propertiesoperations ($set,$setOnce,$unset) - Merges them with the following precedence:
$unset>$set>$setOnce - Prefixes every key with
amplitude_(e.g.planbecomesamplitude_plan) - Calls
chmln.identify(user_id, prefixed_properties)
$unset handling
Keys in $unset are mapped to null, which tells Chameleon to clear those attributes. $unset has the highest precedence — if a key appears in both $set and $unset, it will be set to null.
Limitations
$addis not supported. Amplitude's$addoperation (increment numeric values) is silently ignored. Only$set,$setOnce, and$unsetare forwarded.- No backfill. The plugin only captures users who trigger a new
$identifycall after installation. Existing Amplitude user attributes are not retroactively synced. To backfill a specific user, trigger an identify call:
const identifyEvent = new amplitude.Identify();
identifyEvent.set('plan', 'enterprise');
amplitude.identify(identifyEvent);Development
bun install
bun run test
bun run build