Amplitude
Introduction
ConfigDirector works with Amplitude in two ways, and you can use either or both:
- Mark experiment runs on your charts. ConfigDirector posts a marker to Amplitude when an experiment's run starts, its split changes, a variation is shipped or the run is stopped. You set this up in the dashboard, with no code.
- Send exposures from your application. Your application tells Amplitude which variation each user saw, so you can compare the variations next to the events you already track there. You add a handler to your code once.
Mark experiment runs on your charts
An Amplitude integration posts a marker for each run event. The marker shows on every chart of the Amplitude project: its label is the config key and the environment name, and its details say what happened and who did it.
Settings
| Setting | Value |
|---|---|
| Data center | US, or EU when the Amplitude project lives in the EU data center |
| API key and Secret key | The project's, from Settings > Projects > your project in Amplitude |
Create the integration
- Open Integrations at the bottom of the dashboard's navigation and pick the tool, or click Add integration when you already have one.
- Give the integration a name, or keep the tool's name.
- Fill in the settings above and paste the credential you created in the tool. Credentials are stored encrypted and never shown again.
- Narrow it down with the Projects, Environments and Tags filters, or leave them empty to mark every run. A run is marked when its project, its environment and its config's tags pass every filter you set; an empty filter lets everything through. An integration filtered to Production marks Production runs only.
- Keep Enabled on. A disabled integration marks nothing, and runs that start or end while it is disabled are not marked later.
- Save. The integration's page shows the tool's settings and the address it posts to.
- Click Send test marker and confirm. A marker titled ConfigDirector test is posted to the tool right away, at the current time, and shows under Deliveries with the tool's response, so you can see where run markers will land.
The Analytics overview explains what each marker says, how deliveries are retried and what happens when the tool stops accepting markers.
What ConfigDirector posts
The integration posts to https://amplitude.com/api/3/annotations, or https://analytics.eu.amplitude.com/api/3/annotations on the EU data center, authenticated with the two keys as HTTP Basic credentials. Set an endpoint URL under Advanced only to post somewhere else.
The body sent is { "label", "start", "details" }, with start in ISO 8601; no chart_id is sent, so the annotation is project-wide. Amplitude's documentation: Chart Annotations API.
Send exposures from your application
To compare an experiment's variations in Amplitude, your application tells Amplitude which variation each user saw. You add a handler once, and Amplitude joins those exposures to the events you already send it.
These exposures go straight from your application to Amplitude, so nothing passes through ConfigDirector.
What Amplitude reads
Amplitude's experiment analysis reads an $exposure event with two properties:
| Property | What you send | Example |
|---|---|---|
flag_key | The config key | checkout-cta-copy |
variant | The variation's name | treatment-a |
When it receives the event, Amplitude renames it [Experiment] Exposure and sets the user property [Experiment] checkout-cta-copy to the variation's name.
Add the handler
Add a handler for the configEvaluated hook where you create the client, in the browser or in Node.js:
import * as amplitude from "@amplitude/analytics-browser";
import { createClient } from "@configdirector/client-sdk";
amplitude.init("YOUR-AMPLITUDE-API-KEY");
export const client = createClient("YOUR-CLIENT-SDK-KEY", {
hooks: {
configEvaluated: ({ evaluation }) => {
const variationName = evaluation.variation?.name;
if (!variationName) return;
amplitude.track("$exposure", { flag_key: evaluation.key, variant: variationName });
},
},
});
await client.initialize({ id: "user-42" });
import { init, track } from "@amplitude/analytics-node";
import { createClient } from "@configdirector/server-sdk";
init("YOUR-AMPLITUDE-API-KEY");
export const client = createClient("YOUR-SERVER-SDK-KEY", {
hooks: {
configEvaluated: ({ evaluation }) => {
const variationName = evaluation.variation?.name;
const userId = evaluation.context?.id;
if (!variationName || !userId) return;
track("$exposure", { flag_key: evaluation.key, variant: variationName }, { user_id: userId });
},
},
});
await client.initialize();
Only an experiment's evaluations carry a variation, so the check skips every other config, along with the in-code default value. It also skips a variation without a name, so name each one. Never send an exposure without a variant, because Amplitude takes that user out of the experiment.
In the browser, Amplitude attaches the exposure to the user you have identified to it. In Node.js, the handler passes the context's id as the user ID, so it has to be the ID your other Amplitude events use. A context without an id is skipped, since it does not take part in the split on a server.
The handler needs version 1.11.0 or later of the JavaScript SDK, or 1.13.0 or later of the Node.js SDK. React, Vue and React Native take the same handler in their hooks. The Experiments guide lists the hook for every other SDK.
With OpenFeature
In an OpenFeature application, a hook does the same job, with the variant as the variation's name. Every config has a variant, not only experiments: on any other config it is ConfigDirector's ID for the value. So attach the hook to the reads of your experiments instead of registering it for every read:
import * as amplitude from "@amplitude/analytics-browser";
import { OpenFeature, type Hook } from "@openfeature/web-sdk";
amplitude.init("YOUR-AMPLITUDE-API-KEY");
const reportExposure: Hook = {
after: (hookContext, details) => {
if (!details.variant) return;
amplitude.track("$exposure", { flag_key: hookContext.flagKey, variant: details.variant });
},
};
const client = OpenFeature.getClient();
const buttonLabel = client.getStringValue("checkout-cta-copy", "Start free trial", {
hooks: [reportExposure],
});
import { init, track } from "@amplitude/analytics-node";
import { OpenFeature, type Hook } from "@openfeature/server-sdk";
init("YOUR-AMPLITUDE-API-KEY");
const reportExposure: Hook = {
after: (hookContext, details) => {
const userId = hookContext.context.targetingKey;
if (!details.variant || !userId) return;
track("$exposure", { flag_key: hookContext.flagKey, variant: details.variant }, { user_id: userId });
},
};
const client = OpenFeature.getClient();
const buttonLabel = await client.getStringValue(
"checkout-cta-copy",
"Start free trial",
{ targetingKey: "user-42" },
{ hooks: [reportExposure] },
);
A variation without a name also has ConfigDirector's ID for the value as its variant, so name each one. The hook needs version 1.11.0 or later of the Web provider, or 1.13.0 or later of the Node.js provider.
When the handler runs
The handler runs once per evaluation, whenever your application reads the config. So read an experiment where the user reaches the change rather than at startup, or users who never see it count as exposed.
A config read on every render sends an event each time. That does not skew the results or add to your bill: Amplitude counts each user once per variant, and exposure events do not count toward your event volume or Monthly Tracked Users.
Compare the variations
The outcomes you compare are the events your application already sends to Amplitude, so there is nothing more to add to your code.
An Experiment Results chart, available on Amplitude's Growth and Enterprise plans, compares them per variation:
- Go to Create > Chart > Experiment Results.
- In the Metrics module, add the event you want to compare.
- In the Exposure module, add
[Experiment] Exposure, where[Experiment] Flag Keyis your config key. - In the Variants performed by module, add a variant for each variation, using the user property
[Experiment] checkout-cta-copy.
The handler also runs outside the split: before the run starts, after you ship and when a conditional rule serves a variation. So set the chart to the dates of the run, which the Experiment tab lists. A conditional rule above the split can still make Amplitude's numbers higher than the Exposures card, which counts only the contexts the split served.
Keep each variation's name for the length of the run, because Amplitude treats a new name as a new variant.
Overview
Use ConfigDirector with your analytics tool. Send exposures from your application to compare an experiment's variations there, and mark every experiment run on the tool's charts. Which tools support which, what a marker says, delivery, and what happens when a tool stops accepting the markers.
Datadog
Mark every experiment run in Datadog with a ConfigDirector integration. The settings it needs, how to create it, and where the markers appear.