@@ -5,6 +5,7 @@ import { SignalsIngestSettingsConfig } from '../client'
55import { SandboxSettingsConfig } from '../processor/sandbox'
66import { NetworkSettingsConfig } from '../signal-generators/network-gen'
77import { SignalsPluginSettingsConfig } from '../../types'
8+ import { DebugStorage } from '../../lib/storage/debug-storage'
89
910export type SignalsSettingsConfig = Pick <
1011 SignalsPluginSettingsConfig ,
@@ -33,9 +34,9 @@ export class SignalGlobalSettings {
3334 signalBuffer : SignalBufferSettingsConfig
3435 ingestClient : SignalsIngestSettingsConfig
3536 network : NetworkSettingsConfig
37+ signalsDebug : SignalsDebugSettings
3638
3739 private sampleSuccess = false
38- private signalsDebug = new SignalsDebugSettings ( )
3940
4041 constructor ( settings : SignalsSettingsConfig ) {
4142 if ( settings . maxBufferSize && settings . signalStorage ) {
@@ -110,68 +111,49 @@ export class SignalGlobalSettings {
110111 }
111112}
112113
113- class SignalsDebugSettings {
114+ export class SignalsDebugSettings {
114115 private static redactionKey = 'segment_signals_debug_redaction_disabled'
115116 private static ingestionKey = 'segment_signals_debug_ingestion_enabled'
117+ private static logSignals = 'segment_signals_log_signals_enabled'
118+ storage : DebugStorage
119+
116120 constructor ( disableRedaction ?: boolean , enableIngestion ?: boolean ) {
121+ this . storage = new DebugStorage ( 'sessionStorage' )
117122 if ( typeof disableRedaction === 'boolean' ) {
118- this . setDebugKey ( SignalsDebugSettings . redactionKey , disableRedaction )
123+ this . storage . setDebugKey (
124+ SignalsDebugSettings . redactionKey ,
125+ disableRedaction
126+ )
119127 }
120128 if ( typeof enableIngestion === 'boolean' ) {
121- this . setDebugKey ( SignalsDebugSettings . ingestionKey , enableIngestion )
129+ this . storage . setDebugKey (
130+ SignalsDebugSettings . ingestionKey ,
131+ enableIngestion
132+ )
122133 }
123134
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
127135 const debugModeInQs = parseDebugModeQueryString ( )
128136 logger . debug ( 'debugMode is set to true via query string' )
129137 if ( typeof debugModeInQs === 'boolean' ) {
130- this . setDebugKey ( SignalsDebugSettings . redactionKey , debugModeInQs )
131- this . setDebugKey ( SignalsDebugSettings . ingestionKey , debugModeInQs )
138+ this . setAllDebugging ( debugModeInQs )
132139 }
133140 }
134141
135- setDebugKey ( key : string , enable : boolean ) {
136- try {
137- if ( enable ) {
138- window . sessionStorage . setItem ( key , 'true' )
139- } else {
140- logger . debug ( `Removing debug key ${ key } from storage` )
141- window . sessionStorage . removeItem ( key )
142- }
143- } catch ( e ) {
144- logger . debug ( 'Storage error' , e )
145- }
142+ setAllDebugging = ( boolean : boolean ) => {
143+ this . storage . setDebugKey ( SignalsDebugSettings . redactionKey , boolean )
144+ this . storage . setDebugKey ( SignalsDebugSettings . ingestionKey , boolean )
145+ this . storage . setDebugKey ( SignalsDebugSettings . logSignals , boolean )
146146 }
147147
148- getDisableSignalsRedaction ( ) {
149- try {
150- const isEnabled = Boolean (
151- window . sessionStorage . getItem ( SignalsDebugSettings . redactionKey )
152- )
153- if ( isEnabled ) {
154- logger . debug ( `${ SignalsDebugSettings . redactionKey } =true (app. storage)` )
155- return true
156- }
157- } catch ( e ) {
158- logger . debug ( 'Storage error' , e )
159- }
160- return false
148+ getDisableSignalsRedaction = ( ) : boolean => {
149+ return this . storage . getDebugKey ( SignalsDebugSettings . redactionKey )
161150 }
162151
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
152+ getEnableSignalsIngestion = ( ) : boolean => {
153+ return this . storage . getDebugKey ( SignalsDebugSettings . ingestionKey )
154+ }
155+
156+ getEnableLogSignals = ( ) : boolean => {
157+ return this . storage . getDebugKey ( SignalsDebugSettings . logSignals )
176158 }
177159}
0 commit comments