On this page

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

For front-end engineers5 minBeginner

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

  1. Install

    Install the Browser Unified SDK

    Run one of these commands in your project directory. Choose the package manager your project already uses.

    bash
    npm install @amplitude/unified
    
  2. Initialize

    Initialize Amplitude at app load

    Import and call initAll once when your app starts:

    javascript
    import { initAll } from "@amplitude/unified";
    
    initAll("AMPLITUDE_API_KEY");
    
  3. Track

    Track your first event

    Call track anywhere in your app:

    javascript
    import { track } from "@amplitude/unified";
    
    track("Button Clicked", { buttonId: "signup" });
    
  4. Confirm

    Confirm data in Amplitude

    Open the Amplitude Debugger and check that the Button Clicked event reaches your project.

For full configuration options, refer to Browser Unified SDK.

Was this helpful?