@amplitude/unified
Official Amplitude SDK for Web analytics, experiment, session replay, Guides and Surveys, and more.
Full Amplitude Unified SDK Documentation lives at (https://amplitude.com/docs/sdks/analytics/browser/browser-unified-sdk)
Installation
This package is published on NPM registry and is available to be installed using npm and yarn.
# npm
npm install @amplitude/unified
# yarn
yarn add @amplitude/unified
Usage
The Unified SDK provides a single entry point for all Amplitude features, including Analytics, Experiment, and Session Replay. It simplifies the integration process by handling the initialization and configuration of all components.
1. Initialize Amplitude Unified SDK
import { Identify, experiment, identify, initAll, sessionReplay, track } from '@amplitude/unified';
await initAll('YOUR_API_KEY', {
// Shared options for all SDKs (optional)
serverZone: 'US', // or 'EU'
instanceName: 'my-instance',
// Analytics options
analytics: {
// Analytics configuration options
},
// Session Replay options
sessionReplay: {
// Session Replay configuration options
},
// Experiment options
experiment: {
// Experiment configuration options
},
// Guides and Surveys options
engagement: {
// Guides and Surveys configuration options
},
});
2. Access SDK Features
The Unified SDK provides access to all Amplitude features through a single interface:
// Track events
track('Button Clicked', { buttonName: 'Sign Up' });
// Identify users
identify(new Identify().set('userType', 'premium'));
// Access Experiment features
const experimentClient = experiment();
if (experimentClient) {
await experimentClient.fetch();
const variant = experimentClient.variant('experiment-key');
}
// Access Session Replay features
await sessionReplay()?.flush(false);
// Access Guides and Surveys features via engagement global
const activeGuidesAndSurveys = window.engagement.gs.list();
Configuration Options
Shared Options
| Name | Type | Default | Description |
|---|---|---|---|
serverZone | 'US' or 'EU' | 'US' | The server zone to use for all SDKs. |
instanceName | string | undefined | A unique name for this instance of the SDK. |
Analytics Options
All options from @amplitude/analytics-browser are supported. See the Analytics Browser SDK documentation for details.
Session Replay Options
All options from @amplitude/plugin-session-replay-browser are supported. See the Session Replay plugin documentation for details.
Experiment Options
All options from @amplitude/plugin-experiment-browser are supported. See the Experiment documentation for details.
Guides and Surveys Options
All options from @amplitude/engagement-browser are supported. See the Guides and Surveys documentation for details.