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.
Install the Browser Unified SDK with npm or yarn
The Browser Unified SDK (@amplitude/unified) adds Amplitude to a JavaScript web app that uses a bundler. Install it with npm or yarn, call initAll once at app load, then call track to send events. If your site has no build step, use the script snippet instead.
Prerequisites
- An Amplitude project and its API key. Create a free Amplitude account if you need one.
- A JavaScript web app that installs packages with npm or yarn.
Install and initialize the SDK
Install
Install the Browser Unified SDK
Run one of these commands in your project directory. Choose the package manager your project already uses.
bashnpm install @amplitude/unifiedInitialize
Initialize Amplitude at app load
Import and call
initAllonce when your app starts:javascriptimport { initAll } from "@amplitude/unified"; initAll("AMPLITUDE_API_KEY");Track
Track your first event
Call
trackanywhere in your app:javascriptimport { track } from "@amplitude/unified"; track("Button Clicked", { buttonId: "signup" });Confirm
Confirm data in Amplitude
Open the Amplitude Debugger and check that the
Button Clickedevent reaches your project.
For full configuration options, refer to Browser Unified SDK.
Was this helpful?