@@ -14,6 +14,7 @@ export type SignalsSettingsConfig = Pick<
1414 | 'flushAt'
1515 | 'flushInterval'
1616 | 'disableSignalsRedaction'
17+ | 'signalsIngestion'
1718 | 'networkSignalsAllowList'
1819 | 'networkSignalsDisallowList'
1920 | 'networkSignalsAllowSameDomain'
@@ -34,6 +35,7 @@ export class SignalGlobalSettings {
3435 network : NetworkSettingsConfig
3536
3637 private redaction = new SignalRedactionSettings ( )
38+ private ingestion = new SignalIngestionSettings ( )
3739
3840 constructor ( settings : SignalsSettingsConfig ) {
3941 if ( settings . maxBufferSize && settings . signalStorage ) {
@@ -55,6 +57,7 @@ export class SignalGlobalSettings {
5557 flushAt : settings . flushAt ,
5658 flushInterval : settings . flushInterval ,
5759 shouldDisableSignalRedaction : this . redaction . getDisableSignalRedaction ,
60+ signalIngestion : this . ingestion . getSignalIngestion ,
5861 }
5962 this . sandbox = {
6063 functionHost : settings . functionHost ,
@@ -139,3 +142,54 @@ class SignalRedactionSettings {
139142 return false
140143 }
141144}
145+
146+ class SignalIngestionSettings {
147+ private static ingestionKey = 'segment_signals_debug_ingestion_enabled'
148+ constructor ( initialValue ?: boolean ) {
149+ if ( typeof initialValue === 'boolean' ) {
150+ this . setSignalIngestion ( initialValue )
151+ }
152+
153+ // setting ?segment_signals_debug=true will disable redaction, and set a key in local storage
154+ // this setting will persist across page loads (even if there is no query string)
155+ // in order to clear the setting, user must set ?segment_signals_debug=false
156+ const debugModeInQs = parseDebugModeQueryString ( )
157+ logger . debug ( 'debugMode is set to true via query string' )
158+ if ( typeof debugModeInQs === 'boolean' ) {
159+ this . setSignalIngestion ( debugModeInQs )
160+ }
161+ }
162+
163+ setSignalIngestion ( shouldEnable : boolean ) {
164+ try {
165+ if ( shouldEnable ) {
166+ window . sessionStorage . setItem (
167+ SignalIngestionSettings . ingestionKey ,
168+ 'true'
169+ )
170+ } else {
171+ logger . debug ( 'Removing ingestion key from storage' )
172+ window . sessionStorage . removeItem ( SignalIngestionSettings . ingestionKey )
173+ }
174+ } catch ( e ) {
175+ logger . debug ( 'Storage error' , e )
176+ }
177+ }
178+
179+ getSignalIngestion ( ) {
180+ try {
181+ const isEnabled = Boolean (
182+ window . sessionStorage . getItem ( SignalIngestionSettings . ingestionKey )
183+ )
184+ if ( isEnabled ) {
185+ logger . debug (
186+ `${ SignalIngestionSettings . ingestionKey } =true (app. storage)`
187+ )
188+ return true
189+ }
190+ } catch ( e ) {
191+ logger . debug ( 'Storage error' , e )
192+ }
193+ return false
194+ }
195+ }
0 commit comments