@@ -10,9 +10,11 @@ import { ampli } from './ampli';
1010import { AMP_COOKIES_KEY } from './constants' ;
1111import { contextEnrichmentPlugin } from './plugins/contextEnrichmentPlugin' ;
1212
13- const IS_ENABLED =
14- process . env . NEXT_PUBLIC_BUILD_ENV === 'production' &&
15- process . env . NEXT_PUBLIC_AMPLITUDE_ENABLED === 'true' ;
13+ // Dev note: do not change, production-only gate (Session Replay must never run outside prod)
14+ const IS_PRODUCTION = process . env . NEXT_PUBLIC_BUILD_ENV === 'production' ;
15+
16+ // Dev note: set IS_ENABLED=true to test Amplitude events locally
17+ const IS_ENABLED = IS_PRODUCTION && process . env . NEXT_PUBLIC_AMPLITUDE_ENABLED === 'true' ;
1618
1719/**
1820 * Check if user has previously given consent for cookies/tracking.
@@ -67,19 +69,22 @@ export async function initAmplitude() {
6769 // Add context enrichment plugin to add page context to all events
6870 if ( IS_ENABLED ) {
6971 ampli . client . add ( contextEnrichmentPlugin ( ) ) ;
70- const sessionReplayTracking = sessionReplayPlugin ( {
71- sampleRate : 1 , // set to 1 to capture all sessions; adjust as needed (e.g., 0.1 for 10%)
72- privacyConfig : {
73- defaultMaskLevel : 'medium' ,
74- maskSelector : [
75- '.amp-obfuscation' , // any element with this class will be masked according to the defaultMaskLevel
76- // specific selectors for the dropdown menu (comes from @iota/dapp-kit) to ensure it's fully masked
77- '[data-radix-popper-content-wrapper]' ,
78- '[class*="AccountDropdownMenu"]' ,
79- ] ,
80- } ,
81- } ) ;
82- ampli . client . add ( sessionReplayTracking ) ;
72+ // Session Replay runs only in production (safety gate to avoid polluting recordings)
73+ if ( IS_PRODUCTION ) {
74+ const sessionReplayTracking = sessionReplayPlugin ( {
75+ sampleRate : 1 , // set to 1 to capture all sessions; adjust as needed (e.g., 0.1 for 10%)
76+ privacyConfig : {
77+ defaultMaskLevel : 'medium' ,
78+ maskSelector : [
79+ '.amp-obfuscation' , // any element with this class will be masked according to the defaultMaskLevel
80+ // specific selectors for the dropdown menu (comes from @iota/dapp-kit) to ensure it's fully masked
81+ '[data-radix-popper-content-wrapper]' ,
82+ '[class*="AccountDropdownMenu"]' ,
83+ ] ,
84+ } ,
85+ } ) ;
86+ ampli . client . add ( sessionReplayTracking ) ;
87+ }
8388 }
8489 } catch ( error ) {
8590 console . error ( '[Amplitude] Initialization failed:' , error ) ;
0 commit comments