1.3.1 • Published 1 day ago

@amplitude/session-replay-browser v1.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 day ago

@amplitude/session-replay-browser

Official Session Replay SDK

Installation

This package is published on NPM registry and is available to be installed using npm and yarn.

# npm
npm install @amplitude/session-replay-browser

# yarn
yarn add @amplitude/session-replay-browser

Usage

This SDK provides access to the Amplitude Session Replay product.

This plugin requires that default tracking for sessions is enabled. If default tracking for sessions is not enabled in the config, the plugin will automatically enable it.

1. Import Amplitude packages

  • @amplitude/session-replay-browser
import * as sessionReplay from '@amplitude/session-replay-browser';

2. Initialize session replay collection

The SDK must be configured via the following code. This call kicks off collection of replays for the user.

sessionReplay.init(API_KEY, {
  deviceId: DEVICE_ID,
  sessionId: SESSION_ID,
  sampleRate: 0.5,
});

3. Get session replay event properties

Any event that occurs within the span of a session replay must be tagged with properties that signal to Amplitude to include it in the scope of the replay. The following shows an example of how to use the properties

const sessionReplayProperties = sessionReplay.getSessionReplayProperties();
track(EVENT_NAME, {
  ...eventProperties,
  ...sessionReplayProperties
})

4. Update session id

Any time that the session id for the user changes, the session replay SDK must be notified of that change. Update the session id via the following method:

sessionReplay.setSessionId(UNIX_TIMESTAMP)

You can optionally pass a new device id as a second argument as well:

sessionReplay.setSessionId(UNIX_TIMESTAMP, deviceId)

5. Shutdown (optional)

If at any point you would like to discontinue collection of session replays, for example in a part of your application where you would not like sessions to be collected, you can use the following method to stop collection and remove collection event listeners.

sessionReplay.shutdown()

Options

NameTypeRequiredDefaultDescription
deviceIdstringYesundefinedSets an identifier for the device running your application.
sessionIdnumberYesundefinedSets an identifier for the users current session. The value must be in milliseconds since epoch (Unix Timestamp).
sampleRatenumberNo0Use this option to control how many sessions will be selected for replay collection. A selected session will be collected for replay, while sessions that are not selected will not. The number should be a decimal between 0 and 1, ie 0.01, representing the fraction of sessions you would like to have randomly selected for replay collection. Over a large number of sessions, 0.01 would select 1% of those sessions.
optOutbooleanNofalseSets permission to collect replays for sessions. Setting a value of true prevents Amplitude from collecting session replays.
flushMaxRetriesnumberNo5Sets the maximum number of retries for failed upload attempts. This is only applicable to retryable errors.
logLevelnumberNoLogLevel.WarnLogLevel.None or LogLevel.Error or LogLevel.Warn or LogLevel.Verbose or LogLevel.Debug. Sets the log level.
loggerProviderLoggerNoLoggerSets a custom loggerProvider class from the Logger to emit log messages to desired destination.
serverZonestringNoUSEU or US. Sets the Amplitude server zone. Set this to EU for Amplitude projects created in EU data center.
privacyConfigobjectNoundefinedSupports advanced masking configs with CSS selectors.
debugModebooleanNofalseAdds additional debug event property to help debug instrumentation issues (such as mismatching apps). Only recommended for debugging initial setup, and not recommended for production.

Privacy

By default, the session replay will mask all inputs, meaning the text in inputs will appear in a session replay as asterisks: ***. You may require more specific masking controls based on your use case, so we offer the following controls:

1. Unmask inputs

In your application code, add the class .amp-unmask to any input whose text you'd like to have unmasked in the replay. In the session replay, it will be possible to read the exact text entered into an input with this class, the text will not be converted to asterisks.

2. Mask non-input elements

In your application code, add the class .amp-mask to any non-input element whose text you'd like to have masked from the replay. The text in the element, as well as it's children, will all be converted to asterisks.

3. Block non-text elements

In your application code, add the class .amp-block to any element you would like to have blocked from the collection of the replay. The element will appear in the replay as a placeholder with the same dimensions.

4. Block elements by CSS selectors.

In the SDK initialization code, you can configure the SDK to block elements based on CSS selectors.

sessionReplay.init(AMPLITUDE_API_KEY, {
  sampleRate: 0.01, 
  privacyConfig: {
      blockSelector: ['.ignoreClass', '#ignoreId']
  }
})
1.3.1

1 day ago

1.3.0

5 days ago

1.2.8

18 days ago

1.2.7

19 days ago

1.2.6

23 days ago

1.2.5

26 days ago

1.2.4

29 days ago

1.2.3

1 month ago

1.2.2

1 month ago

1.2.1

1 month ago

1.2.0

2 months ago

1.1.0

2 months ago

1.1.0-beta.0

2 months ago

1.0.2

3 months ago

1.0.1

3 months ago

0.8.0-beta.0

3 months ago

0.7.2

4 months ago

0.7.1

5 months ago

0.7.0

5 months ago

0.6.0

5 months ago

0.5.0-beta.0

6 months ago

0.5.0

6 months ago

0.4.0

6 months ago

0.3.1

7 months ago

0.3.0

7 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.1

8 months ago

0.1.0

9 months ago