Add telemetry opt-in to the Firefox add-on
Created by: marekweb
Closes #13377
Background
For policy compliance, the Sourcegraph for Firefox add-on must provide a control mechanism for the user to control data collection. Our current interpretation of the add-on policy is that we can make data collection (telemetry) an opt-in feature on Firefox, and this will bring us into compliance. Our collection of data falls under the "User interactions & technical data" category in the policies.
Another possible method for compliance, not addressed in this PR, would be to show UI to the user upon first run of the add-on that gives them the option of opting out of data collection.
Source: https://extensionworkshop.com/documentation/publish/add-on-policies/
Implementation
Adding a new setting in the Options Page UI
The browser extension shows a list of boolean options in the add-on Options Page. Internally we call these options feature flags.
Part of this PR introduces a renaming to call these "option flags" instead of feature flags. This does not change the internal string key used for saving the option values in extension sync
storage, so the change is backwards-compatible.
This PR adds a new boolean option, represented as a checkbox, to the option flags, tentatively called "Send telemetry".
Added to the scope of this PR
- The feature flags in the browser extension aren't strictly speaking feature flags anymore, although they started out that way. They are renamed to
Option Flags
- The feature flags have labels in the UI which are derived directly from their internal names. For example
allowErrorReporting
becomeAllow error reporting
in the UI, using a string conversion function. This makes it compact but it also makes it difficult to change flag names in the future, because changing the UI label will require changing the internal name, and making such a change will have the side-effect of resetting the user's saved value to default. TheOption Flags
now have a separate label field instead of deriving the label from the key.
Telemetry service implementation
The telemetry service in the browser extension is implemented with an EventLogger
which is instantiated in injectCodeIntelligenceToCodeHost
.
This telemetry service is then passed to several places that use it:
initCodeIntelligence
handleCodeHost
renderCommandPalette
<CodeViewToolbar/>
<HoverOverlay/>
To make the telemetry service depend on the flag:
- Instantiate a telemetry service which itself will observe the setting, and will pass events along while telemetry is enabled, and will swallow events otherwise.
Different behavior based on the environment
The opt-in setting behavior should be present on Firefox and in particular when the Sourcegraph URL is set to sourcegraph.com
.
In other cases the flag is not applicable (it is overriden) and the checkbox is not shown in the interface.
Alternatives considered
An alternative to the opt-in mechanism is to make it an opt-out flag while making sure that the user is shown the options page at first installation to make sure that they've seen it and have given consent. In order to avoid introducing a new step in the installation process, we didn't pursue this solution.