Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v6] Disable analytics: CI and production environments #3947

Merged
merged 3 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ x.x.x Release notes (yyyy-MM-dd)
* None.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None.

### Compatibility
Expand All @@ -13,7 +12,8 @@ x.x.x Release notes (yyyy-MM-dd)
* File format: Generates Realms with format v11 (reads and upgrades previous file format).

### Internal
* None.
* Disable analytics if `NODE_ENV` is set to `"production"` or `"test"`. Since `NODE_ENV` is used by many commonly used JavaScript frameworks, this should help us to get a better signal-to-noise ratio in our builders' statistics.
* Disable analytics if the `CI` environment variable is set to some value.

6.1.7 Release notes (2021-3-13)
=============================================================
Expand Down
16 changes: 15 additions & 1 deletion lib/submit-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,21 @@ class MixpanelDetails {


function isAnalyticsDisabled() {
return 'REALM_DISABLE_ANALYTICS' in process.env;
// NODE_ENV is commonly used by JavaScript framework
if ("NODE_ENV" in process.env) {
return process.env["NODE_ENV"] === "production" || process.env["NODE_ENV"] === "test";
}

// Electron apps are assumed to be in production if packaged
try {
const { app } = require("electron");
return !app.isPackaged;
} catch (_) {
// ignore error
}

// If the user has specifically opted-out or if we're running in a CI environment
return 'REALM_DISABLE_ANALYTICS' in process.env || "CI" in process.env;
}

function sha256(data) {
Expand Down
5 changes: 3 additions & 2 deletions react-native/android/analytics_template
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class SendAnalyticsTask extends DefaultTask {
def sendAnalytics() {
try {
def env = System.getenv()
def disableAnalytics= env['REALM_DISABLE_ANALYTICS']
if (disableAnalytics == null || disableAnalytics != "true") {
def disableAnalytics = env['REALM_DISABLE_ANALYTICS'] != null
def isCI = env['CI'] != null
if (!disableAnalytics && !isCI) {
send()
}
} catch(all) {}
Expand Down
2 changes: 1 addition & 1 deletion react-native/ios/RealmReact/RealmAnalytics.mm
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static bool RLMIsDebuggerAttached() {
}

void RLMSendAnalytics() {
if (getenv("REALM_DISABLE_ANALYTICS") || !RLMIsDebuggerAttached()) {
if (getenv("REALM_DISABLE_ANALYTICS") || getenv("CI") || !RLMIsDebuggerAttached()) {
return;
}

Expand Down