@@ -33,9 +33,9 @@ export class SignalGlobalSettings {
3333 signalBuffer : SignalBufferSettingsConfig
3434 ingestClient : SignalsIngestSettingsConfig
3535 network : NetworkSettingsConfig
36+ signalsDebug : SignalsDebugSettings
3637
3738 private sampleSuccess = false
38- private signalsDebug = new SignalsDebugSettings ( )
3939
4040 constructor ( settings : SignalsSettingsConfig ) {
4141 if ( settings . maxBufferSize && settings . signalStorage ) {
@@ -110,9 +110,11 @@ export class SignalGlobalSettings {
110110 }
111111}
112112
113- class SignalsDebugSettings {
113+ export class SignalsDebugSettings {
114+ private storageType = 'sessionStorage' as const
114115 private static redactionKey = 'segment_signals_debug_redaction_disabled'
115116 private static ingestionKey = 'segment_signals_debug_ingestion_enabled'
117+
116118 constructor ( disableRedaction ?: boolean , enableIngestion ?: boolean ) {
117119 if ( typeof disableRedaction === 'boolean' ) {
118120 this . setDebugKey ( SignalsDebugSettings . redactionKey , disableRedaction )
@@ -121,21 +123,22 @@ class SignalsDebugSettings {
121123 this . setDebugKey ( SignalsDebugSettings . ingestionKey , enableIngestion )
122124 }
123125
124- // setting ?segment_signals_debug=true will disable redaction, enable ingestion, and set keys in local storage
125- // this setting will persist across page loads (even if there is no query string)
126- // in order to clear the setting, user must set ?segment_signals_debug=false
127126 const debugModeInQs = parseDebugModeQueryString ( )
128127 logger . debug ( 'debugMode is set to true via query string' )
129128 if ( typeof debugModeInQs === 'boolean' ) {
130- this . setDebugKey ( SignalsDebugSettings . redactionKey , debugModeInQs )
131- this . setDebugKey ( SignalsDebugSettings . ingestionKey , debugModeInQs )
129+ this . setAllDebugging ( debugModeInQs )
132130 }
133131 }
134132
135- setDebugKey ( key : string , enable : boolean ) {
133+ setAllDebugging ( boolean : boolean ) {
134+ this . setDebugKey ( SignalsDebugSettings . redactionKey , boolean )
135+ this . setDebugKey ( SignalsDebugSettings . ingestionKey , boolean )
136+ }
137+
138+ private setDebugKey ( key : string , enable : boolean ) {
136139 try {
137140 if ( enable ) {
138- window . sessionStorage . setItem ( key , 'true' )
141+ window [ this . storageType ] . setItem ( key , 'true' )
139142 } else {
140143 logger . debug ( `Removing debug key ${ key } from storage` )
141144 window . sessionStorage . removeItem ( key )
@@ -145,13 +148,11 @@ class SignalsDebugSettings {
145148 }
146149 }
147150
148- getDisableSignalsRedaction ( ) {
151+ private getDebugKey ( key : string ) : boolean {
149152 try {
150- const isEnabled = Boolean (
151- window . sessionStorage . getItem ( SignalsDebugSettings . redactionKey )
152- )
153+ const isEnabled = Boolean ( window [ this . storageType ] . getItem ( key ) )
153154 if ( isEnabled ) {
154- logger . debug ( `${ SignalsDebugSettings . redactionKey } =true (app. storage)` )
155+ logger . debug ( `${ key } =true (app. storage)` )
155156 return true
156157 }
157158 } catch ( e ) {
@@ -160,18 +161,11 @@ class SignalsDebugSettings {
160161 return false
161162 }
162163
163- getEnableSignalsIngestion ( ) {
164- try {
165- const isEnabled = Boolean (
166- window . sessionStorage . getItem ( SignalsDebugSettings . ingestionKey )
167- )
168- if ( isEnabled ) {
169- logger . debug ( `${ SignalsDebugSettings . ingestionKey } =true (app. storage)` )
170- return true
171- }
172- } catch ( e ) {
173- logger . debug ( 'Storage error' , e )
174- }
175- return false
164+ getDisableSignalsRedaction ( ) : boolean {
165+ return this . getDebugKey ( SignalsDebugSettings . redactionKey )
166+ }
167+
168+ getEnableSignalsIngestion ( ) : boolean {
169+ return this . getDebugKey ( SignalsDebugSettings . ingestionKey )
176170 }
177171}
0 commit comments