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.
Browser Unified SDK reference
이 페이지는 아직 귀하의 언어로 번역되지 않았습니다. 현재 작업 중이므로 곧 다시 확인해 주십시오.
This reference documents every public export of @amplitude/unified and every option you can pass to initAll(), verified against version 1.1.43. That version bundles Browser SDK 2.48.1 (@amplitude/analytics-browser), so every analytics method behaves as the Browser SDK 2 reference describes. For changes between versions, go to the @amplitude/unified changelog.
import * as amplitude from "@amplitude/unified";
The top-level functions act on a default instance. Each instance from createInstance() has the same methods, plus init().
Exports
| Export | Description |
|---|---|
initAll, experiment, sessionReplay, createInstance | Specific to the Unified SDK. Documented on this page. |
track, logEvent, identify, groupIdentify, setGroup, revenue, flush, add, remove, setTransport, getUserId, setUserId, getDeviceId, setDeviceId, getIdentity, setIdentity, getSessionId, setSessionId, extendSession, reset, getOptOut, setOptOut | The Browser SDK 2 methods. Go to the Browser SDK 2 reference. |
Identify, Revenue, Types | Re-exported from Browser SDK 2. Go to Identify, Revenue, and Types. |
UnifiedOptions, UnifiedSharedOptions, UnifiedClient | TypeScript types only, with no runtime value. Go to UnifiedOptions and UnifiedClient. |
The top-level module doesn't export init(). Call initAll() instead.
Setup
initAll
Initializes Analytics, then adds Session Replay, Feature Experiment, and Guides and Surveys. Call it once per instance on each page load.
initAll(apiKey: string, unifiedOptions?: UnifiedOptions): Promise<void>
| Parameter | Type | Description |
|---|---|---|
apiKey | string | Your Amplitude project API key. |
unifiedOptions | UnifiedOptions | Optional. Go to UnifiedOptions. |
initAll() returns a plain Promise, not an AmplitudeReturn, so await it directly. It resolves after every product finishes setup. Calls made before it resolves wait in a queue and run in order afterward.
An initAll() call made while an earlier call is still pending returns the same promise. An initAll() call made after the earlier call resolves runs the full setup again. The repeat call initializes Analytics again, tracks another page view if page view tracking is on, and restarts Session Replay. It also logs Plugin with name @amplitude/unified-library-plugin already exists, skipping registration.
await amplitude.initAll("YOUR_API_KEY", {
serverZone: "EU",
sessionReplay: { sampleRate: 0.1 },
});
experiment
Returns the Feature Experiment client, or undefined before initAll() adds it.
experiment(): IExperimentClient | undefined
The client is the Experiment JavaScript SDK client. The client doesn't fetch flags during initAll(). Call fetch() before variant().
const experiment = amplitude.experiment();
await experiment?.fetch();
const variant = experiment?.variant("checkout-redesign");
sessionReplay
Returns the Session Replay client, or undefined before initAll() adds it.
sessionReplay(): AmplitudeSessionReplay | undefined
| Method | Description |
|---|---|
start(): AmplitudeReturn<void> | Starts or resumes recording. Recording still respects sample rate, targeting, opt-out, and remote capture settings. |
stop(): void | Pauses recording without tearing down the SDK. Call start() to resume. |
shutdown(): void | Stops recording and removes event listeners. |
flush(useRetry: boolean): Promise<void> | Uploads recorded data now. Pass true to retry failed uploads. |
getSessionReplayProperties(): { [key: string]: boolean | string | null } | Returns { "[Amplitude] Session Replay ID": "..." } while Session Replay records the session, and {} otherwise. |
getSessionId(): string | number | undefined | Returns the session ID that Session Replay records against. |
setSessionId(sessionId: string | number, deviceId?: string): AmplitudeReturn<void> | Sets the session ID that Session Replay records against. |
init, evaluateTargetingAndCapture | The plugin calls these during setup. Don't call them directly. |
const replay = amplitude.sessionReplay();
replay?.stop();
For recording options, go to Session Replay plugin.
createInstance
Creates an independent instance with its own Analytics configuration, identity, queue, and plugins.
createInstance(): UnifiedClient
const marketing = amplitude.createInstance();
await marketing.initAll("MARKETING_API_KEY", { instanceName: "marketing" });
marketing.track("Signup Completed");
Guides and Surveys initializes once per page. Instances that call initAll() after the first instance ignore their engagement options.
UnifiedClient
The interface that the default instance implements and createInstance() returns. It extends the Browser SDK 2 BrowserClient with these members:
| Member | Description |
|---|---|
initAll | Refer to initAll. |
experiment | Refer to experiment. |
sessionReplay | Refer to sessionReplay. |
init | Initializes Analytics only, as Browser SDK 2 init() does. Available on instances from createInstance(), not as a top-level export. |
UnifiedOptions
The options object you pass to initAll(). All options are optional.
Shared options
initAll() passes these options to every product and merges them over the same-named option in each product block. An unset shared option still overwrites the same-named product option with undefined.
| Option | Type | Default | Description |
|---|---|---|---|
serverZone | "US" or "EU" | "US" | The data center for every product. Set it here, not in analytics. |
instanceName | string | "$default_instance" | The instance name for every product. Use a distinct name for each instance from createInstance(). |
Product options
| Option | Type | Default | Description |
|---|---|---|---|
analytics | BrowserOptions | {} | Browser SDK 2 options. Go to Configuration options. |
sessionReplay | SessionReplayOptions, without the shared options | {} | Session Replay plugin options. sampleRate defaults to 0, which records nothing. Go to Session Replay plugin. |
experiment | ExperimentPluginConfig, without the shared options | {} | Experiment JavaScript SDK options, plus deploymentKey. Go to experiment options. |
engagement | Guides and Surveys InitOptions, without the shared options | {} | Guides and Surveys options, plus skip. Go to engagement options. |
experiment options
| Option | Type | Default | Description |
|---|---|---|---|
deploymentKey | string | The project API key | The Experiment client deployment key. |
| Other options | Varies | Varies | Every Experiment JavaScript SDK option. Version 1.1.43 includes @amplitude/plugin-experiment-browser 1.0.0-beta.51, a beta release. |
engagement options
| Option | Type | Default | Description |
|---|---|---|---|
skip | boolean | false | When true, Guides and Surveys downloads nothing, makes no requests, and writes nothing to storage. Requires @amplitude/unified 1.1.11 or later. |
| Other options | Varies | Varies | Every Guides and Surveys option. |
이 내용이 도움이 되었나요?