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.
Choose a browser installation
You can add Amplitude to a website in four ways. The methods differ in which products they include and who controls the SDK version. Use one method per page. Two Amplitude entry points on the same page create two instances, which can send events twice.
Choose an installation method
| Method | Products | Version control | Best for |
|---|---|---|---|
| Browser SDK 2 (npm or script loader) | Analytics. Add other products as separate packages. | You | Teams that need Analytics only, or the smallest bundle |
| Browser Unified SDK (npm) | Analytics, Session Replay, Feature Experiment, Guides and Surveys | You | Teams that bundle their JavaScript and need reproducible builds |
| Unified Script (CDN) | Analytics, Session Replay, Web Experiment | Amplitude | Quick setup with automatic updates |
| Google Tag Manager template | Analytics, with optional Session Replay and Guides and Surveys | The template version | Teams that manage tags in Google Tag Manager |
Product support by installation method
| Product | Browser SDK 2 | Unified SDK (npm) | Unified Script (CDN) | GTM template |
|---|---|---|---|---|
Analytics (@amplitude/analytics-browser) | ✅ Included | ✅ Included | ✅ Included | ✅ Included |
| Session Replay | ➕ Separate package | ✅ Included | ✅ Included | ✅ Optional (checkbox) |
| Guides and Surveys | ➕ Separate package | ✅ Included | ⚠️ Separate script | ✅ Optional (checkbox) |
Web Experiment (@amplitude/experiment-tag) | ➕ Separate script | ❌ Not included | ✅ Included | ❌ Not supported |
Feature Experiment (@amplitude/experiment-js-client) | ➕ Separate package | ✅ Included | ❌ Not included | ❌ Not supported |
Web Experiment compared with Feature Experiment
- Web Experiment: uses visual editing for no-code A/B testing on web pages. The Unified Script includes it.
- Feature Experiment: uses code-based feature flags with the Experiment JavaScript SDK. The Unified SDK includes it.
To choose the right Experiment package for each integration surface, go to Install in the Experiment JavaScript SDK documentation.
Choose between Browser SDK 2 and the Unified SDK
The Unified SDK (@amplitude/unified) bundles Browser SDK 2 (@amplitude/analytics-browser), so tracking, identity, and autocapture work the same in both. Choose by the products you need:
- Analytics only or a small bundle: install Browser SDK 2. Add products one at a time as you need them:
- Two or more products configured with one call: install the Unified SDK.
Unified Script (CDN)
The Unified Script is one script tag that loads Amplitude browser products from Amplitude's CDN. Amplitude controls the versions of the underlying SDKs, so Amplitude can patch bugs or improve performance without a release from your team.
- Includes Web Experiment (visual editor), not Feature Experiment.
- Turns on Session Replay and Web Experiment with default settings.
- Requires a separate script for Guides and Surveys, because the Guides and Surveys code is large.
Install the Unified Script
Add this script tag to the <head> of your site, and replace AMPLITUDE_API_KEY with your project's API key:
<script src="https://cdn.amplitude.com/script/AMPLITUDE_API_KEY.js"></script>
To set options in code, call init() yourself after the script:
<script src="https://cdn.amplitude.com/script/AMPLITUDE_API_KEY.js"></script>
<script>
window.amplitude.init("AMPLITUDE_API_KEY", {
autocapture: true,
fetchRemoteConfig: true,
});
// sampleRate: 1 records every session for testing. Lower it before production. The default, 0, records nothing.
window.amplitude.add(window.sessionReplay.plugin({ sampleRate: 1 }));
</script>
window.amplitude is Browser SDK 2, so its options are the Browser SDK 2 options.
Add Guides and Surveys to the Unified Script
Add the Guides and Surveys script after the Unified Script:
<script src="https://cdn.amplitude.com/script/AMPLITUDE_API_KEY.js"></script>
<script src="https://cdn.amplitude.com/script/AMPLITUDE_API_KEY.engagement.js"></script>
<script>
window.amplitude.add(window.engagement.plugin());
window.amplitude.init("AMPLITUDE_API_KEY", {
fetchRemoteConfig: true,
autocapture: true,
});
</script>
For configuration options, go to the Guides and Surveys SDK documentation.
Google Tag Manager
The Amplitude GTM template wraps Browser SDK 2 (@amplitude/analytics-browser) directly. It doesn't use the Unified SDK or the Unified Script.
- The template version determines the SDK version.
- The template supports Analytics, Session Replay, and Guides and Surveys. The template doesn't support Web Experiment or Feature Experiment.
- Session Replay and Guides and Surveys are off by default.
To turn on Session Replay and Guides and Surveys:
- Open your Amplitude tag in GTM.
- In the tag configuration, select Session Replay.
- Select Guides & Surveys.
- Save and publish your changes.
For configuration options, go to the Google Tag Manager documentation.
Was this helpful?