| [ Web Proxy ] |
| Viewing: https://amplitude.com/docs/en/feature-experiment/experiment-quick-start | [Back] [Original] |
Products
For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.
Experiment is a workflow-driven behavioral experimentation platform that speeds up creating variants of features and websites for testing.
With Experiment, you can modify and configure product experiences for unique audiences through:
Experiment supports experimentation through either Feature Experiment or Web Experiment:
For more information about the use cases for each type of experimentation, go to Feature and Web Experiment use cases.
This page splits the quick start into Feature Experiment and Web Experiment. Select the tab for the experiment type you want to set up.
This quick start guide contains only the basic information needed to implement Experiment. Review the entire set of Experiment documentation to understand the full complexity of the product.
Experiments and feature flags use the Amplitude Experiment SDK or REST API to communicate with Amplitude Experiment.
Setting up an experiment is a multi-stage process with these procedures:
Before you start using experiments:
Install the Amplitude SDK with the Experiment client. For example:
npm install @amplitude/analytics-browser @amplitude/experiment-js-client
import * as amplitude from "@amplitude/analytics-browser";
import { Experiment } from "@amplitude/experiment-js-client";
amplitude.init("AMPLITUDE_API_KEY");
const experiment = Experiment.initialize("DEPLOYMENT_API_KEY");
await experiment.start();
Experiment uses the same projects as Amplitude Analytics. As a best practice, create one project for each product and each environment. Because flags, experiments, and deployments only exist within a single project, you must duplicate these objects across projects within the same product.
In Amplitude Experiment, a deployment serves a group of flags or experiments for use in an application. Each project has a deployment using the project API key as the deployment key, available by default. On creation, Experiment assigns a randomly generated deployment key to each deployment. Experiment uses the deployment key to identify the deployment and authorize requests to the evaluation servers.
Client vs. server deployments
Deployments are either client or server deployments. Use client-side deployments to initialize client-side SDKs, and server-side deployments to initialize server-side SDKs or authorize requests to the Evaluation API.
Deployments belong to Amplitude Analytics projects, and a project can have multiple deployments. Amplitude recommends that you name deployments after the platform (client-side) or service (server-side) to which Experiment serves variants (for example: android, ios, web). The default project API key deployment is useful for getting started. Use explicit deployments for each platform or service in larger organizations or teams that may share the same Amplitude project across multiple platforms for the same application. Each deployment receives a unique key for use in your application.
A flag lets you enable or disable a function or feature in your product without deploying new code each time. Flags drive both experiments and feature rollouts. Flags work well for launching experiments and ending them after you collect enough data, and for rolling out new features (and rolling them back, if needed).
The best bucketing unit is typically the user. In some B2B use cases, you might want to use company ID or city as the bucketing unit. For example, bucketing by company ID ensures all users in a particular company have the same user experience. Confirm the Stable Unit Treatment Value Assumption holds for whichever unit you choose.
Ifyou change the bucketing salt, users can switch between variants in your experiment. For that reason, Amplitude recommends not changing the bucketing salt unless you know what youre doing. For more information, go to How randomization works in Amplitude Experiment.
A variant exists within a flag or an experiment, and represents a variable experience for a user. Variants comprise the A/B changes you want to test. All feature flags must contain at least one variant. You can add as many variants as you want to a flag.
You can send a payload with your variant. A payload is a JSON-coded set of variables that can remotely change flags and experiments without a manual code change. Because you can send a payload with your control, you dont need to create a variant for the control itself.
Add JSON content to the Payload field when creating a variant. Payload content resembles:
{
"layout": "cards",
"titlePosition": "above",
"gradient": false,
"showDescription": true,
"cardCount": 3
}
In the Assignment section, define the user segments you want to experience your new feature. Defining a user segment limits your rollout to users in specific geographical locations, certain demographic groups, or who meet certain usage thresholds in your product (for example, power users). For more information on segmenting, go to Define your audience.
After you set up the flag, associate it with a deployment, set up your variants or payloads, and target your users, finalize the feature flag. Finalizing the flag activates the flag and makes it available.
You can create an experiment directly or convert an existing flag to an experiment.
When designing your experiment:
Adding goals (or metrics) lets you track the success rate of your experiment. All experiments should have at least one metric. Tell Amplitude Experiment what you want your primary metric to be, and define any secondary metrics. The primary metric determines whether Amplitude accepts or rejects your hypothesis, and therefore whether your experiment succeeded or failed.
To create more variations and payloads, repeat the steps in Create variations in your flag.
After you finish designing your experiment, select Start Experiment to begin.
The following code examples show the code for a feature flag and a JSON payload.
import { useState, useEffect } from 'react';
import { getBlogLayoutFlag } from '../services/featureFlags'; // Adjust to wherever you fetch your Amplitude flag
import type { BlogPost } from '../types';
type LayoutFlag = {
layout: 'cards' | 'list' | 'carousel';
titlePosition: 'above' | 'below' | 'center';
gradient: boolean;
showDescription: boolean;
cardCount: number;
};
export default function BlogPostLayoutClient({ posts }: { posts: BlogPost[] }) {
const [layoutFlag, setLayoutFlag] = useState<LayoutFlag | null>(null);
useEffect(() => {
getBlogLayoutFlag().then((flag) => {
console.log(':magic_wand: Received Flag from Amplitude:', flag);
if (flag) {
setLayoutFlag(flag);
} else {
console.log(':warning: No flag returned, falling back to default layout');
setLayoutFlag({
layout: 'cards',
titlePosition: 'above',
gradient: false,
showDescription: true,
cardCount: 3,
});
}
});
}, []);
if (!layoutFlag) {
// You might render a loader here
return null;
}
// Render your posts according to layoutFlag...
return (
<div>
{/* e.g. layoutFlag.layout === 'cards' ? <CardGrid posts={posts} /> : ... */}
</div>
);
}
Was this helpful?
On this page
Platform
Resources
Partners & Support
20122026 Amplitude, Inc.. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.
| Web Proxy Viewer | New URL | Original Page |