このページでは

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

Product support by installation method

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:

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:

html
<script src="https://cdn.amplitude.com/script/AMPLITUDE_API_KEY.js"></script>

To set options in code, call init() yourself after the script:

html
<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:

html
<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:

  1. Open your Amplitude tag in GTM.
  2. In the tag configuration, select Session Replay.
  3. Select Guides & Surveys.
  4. Save and publish your changes.

For configuration options, go to the Google Tag Manager documentation.

これは役に立ちましたか?