@@ -14,6 +14,9 @@ const TELEMETRY_CATEGORY = "lockboxv1";
1414// which seems like a code smell, while the action / middleware approach solves
1515// this nicely.
1616
17+ let enabled = false ;
18+ function getTelemetryEnabled ( ) { return enabled ; }
19+
1720function registerEvents ( ) {
1821 const events = {
1922 "startup" : {
@@ -146,6 +149,10 @@ function registerScalars() {
146149
147150async function recordEvent ( { method, object, extra = null , value = null } ) {
148151 let result ;
152+ if ( ! enabled ) {
153+ return result ;
154+ }
155+
149156 // Note: 'extra' objects must have string values. Replace null with empty
150157 // string, and convert numbers to strings.
151158 if ( extra ) {
@@ -178,14 +185,19 @@ async function recordEvent({ method, object, extra = null, value = null }) {
178185}
179186
180187function scalarSet ( { name, value } ) {
181- return browser . telemetry . scalarSet ( `${ TELEMETRY_CATEGORY } .${ name } ` , value ) ;
188+ return enabled && browser . telemetry . scalarSet ( `${ TELEMETRY_CATEGORY } .${ name } ` , value ) ;
182189}
183190
184191function scalarAdd ( { name, value } ) {
185- return browser . telemetry . scalarAdd ( `${ TELEMETRY_CATEGORY } .${ name } ` , value ) ;
192+ return enabled && browser . telemetry . scalarAdd ( `${ TELEMETRY_CATEGORY } .${ name } ` , value ) ;
186193}
187194
188- export function initializeTelemetry ( ) {
195+ export function initializeTelemetry ( force ) {
196+ if ( ! enabled && ! force ) {
197+ return ;
198+ }
199+
200+ enabled = true ;
189201 registerEvents ( ) ;
190202 registerScalars ( ) ;
191203
@@ -195,5 +207,5 @@ export function initializeTelemetry() {
195207 } ) ;
196208}
197209
198- const exported = { recordEvent, scalarSet, scalarAdd } ;
210+ const exported = { getTelemetryEnabled , recordEvent, scalarSet, scalarAdd } ;
199211export default exported ;
0 commit comments