From bd7103166e2d98e9103790dc18c4c2e9e01c7b2d Mon Sep 17 00:00:00 2001 From: Evan Bacon Date: Wed, 26 Jan 2022 20:00:04 -0700 Subject: [PATCH] drop amplitude --- .../cli/utils/analytics/rudderstackClient.ts | 43 ++++++------------- packages/expo/cli/utils/env.ts | 3 ++ packages/expo/cli/utils/user/UserSettings.ts | 2 - 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/packages/expo/cli/utils/analytics/rudderstackClient.ts b/packages/expo/cli/utils/analytics/rudderstackClient.ts index 9dc753e84a9f0..bb647c4cae42c 100644 --- a/packages/expo/cli/utils/analytics/rudderstackClient.ts +++ b/packages/expo/cli/utils/analytics/rudderstackClient.ts @@ -3,7 +3,7 @@ import os from 'os'; import { URL } from 'url'; import { v4 as uuidv4 } from 'uuid'; -import UserSettings from '../user/UserSettings'; +import { EXPO_LOCAL, EXPO_STAGING, EXPO_NO_TELEMETRY } from '../env'; const PLATFORM_TO_ANALYTICS_PLATFORM: { [platform: string]: string } = { darwin: 'Mac', @@ -12,7 +12,7 @@ const PLATFORM_TO_ANALYTICS_PLATFORM: { [platform: string]: string } = { }; let rudderstackClient: RudderAnalytics | null = null; -let userIdentified = false; +let identifier = false; let identifyData: { userId: string; deviceId: string; @@ -20,26 +20,9 @@ let identifyData: { } | null = null; export async function initAsync(): Promise { - // TODO: remove after some time - const amplitudeEnabled = await UserSettings.getAsync('amplitudeEnabled', null); - if (amplitudeEnabled !== null) { - await UserSettings.setAsync('analyticsEnabled', amplitudeEnabled); - await UserSettings.deleteKeyAsync('amplitudeEnabled'); - } - const amplitudeDeviceId = await UserSettings.getAsync('amplitudeDeviceId', null); - if (amplitudeDeviceId !== null) { - await UserSettings.setAsync('analyticsDeviceId', amplitudeDeviceId); - await UserSettings.deleteKeyAsync('amplitudeDeviceId'); - } - // TODO: cut here - if (process.env.DISABLE_EAS_ANALYTICS) { - await UserSettings.setAsync('analyticsEnabled', false); - } - - const analyticsEnabled = await UserSettings.getAsync('analyticsEnabled', true); - if (analyticsEnabled) { + if (EXPO_NO_TELEMETRY) { const config = - process.env.EXPO_STAGING || process.env.EXPO_LOCAL + EXPO_STAGING || EXPO_LOCAL ? { // staging environment rudderstackWriteKey: '1wpX20Da4ltFGSXbPFYUL00Chb7', @@ -62,10 +45,12 @@ export async function initAsync(): Promise { } export async function setUserDataAsync(userId: string, traits: Record): Promise { - const savedDeviceId = await UserSettings.getAsync('analyticsDeviceId', null); + const UserSettings = await import('../user/UserSettings'); + + const savedDeviceId = await UserSettings.default.getAsync('analyticsDeviceId', null); const deviceId = savedDeviceId ?? uuidv4(); if (!savedDeviceId) { - await UserSettings.setAsync('analyticsDeviceId', deviceId); + await UserSettings.default.setAsync('analyticsDeviceId', deviceId); } identifyData = { @@ -74,7 +59,7 @@ export async function setUserDataAsync(userId: string, traits: Record { @@ -87,7 +72,7 @@ export function logEvent(name: string, properties: Record = {}): vo if (!rudderstackClient) { return; } - ensureUserIdentified(); + ensureIdentified(); const { userId, deviceId } = identifyData ?? {}; const commonEventProperties = { source_version: process.env.__EXPO_VERSION, source: 'expo' }; @@ -101,8 +86,8 @@ export function logEvent(name: string, properties: Record = {}): vo }); } -function ensureUserIdentified(): void { - if (!rudderstackClient || userIdentified || !identifyData) { +function ensureIdentified(): void { + if (!rudderstackClient || identifier || !identifyData) { return; } @@ -111,7 +96,7 @@ function ensureUserIdentified(): void { anonymousId: identifyData.deviceId, traits: identifyData.traits, }); - userIdentified = true; + identifier = true; } function getRudderStackContext(): Record { @@ -119,7 +104,7 @@ function getRudderStackContext(): Record { return { os: { name: platform, version: os.release() }, device: { type: platform, model: platform }, - app: { name: 'expo', version: process.env.__EXPO_VERSION ?? undefined }, + app: { name: 'expo', version: process.env.__EXPO_VERSION }, }; } diff --git a/packages/expo/cli/utils/env.ts b/packages/expo/cli/utils/env.ts index 497dc62e6eda1..d08a58925a1f1 100644 --- a/packages/expo/cli/utils/env.ts +++ b/packages/expo/cli/utils/env.ts @@ -16,3 +16,6 @@ export const EXPO_LOCAL = boolish('EXPO_LOCAL', false); /** Is running in non-interactive CI mode */ export const CI = boolish('CI', false); + +/** Disable telemetry (analytics) */ +export const EXPO_NO_TELEMETRY = boolish('EXPO_NO_TELEMETRY', false); diff --git a/packages/expo/cli/utils/user/UserSettings.ts b/packages/expo/cli/utils/user/UserSettings.ts index 7c00cc56a8b13..b8d42a6b68cd1 100644 --- a/packages/expo/cli/utils/user/UserSettings.ts +++ b/packages/expo/cli/utils/user/UserSettings.ts @@ -27,8 +27,6 @@ const SETTINGS_FILE_PATH = path.join(getConfigDirectory(), 'user-settings.json') export type UserSettingsData = { appleId?: string; - amplitudeDeviceId?: string; - amplitudeEnabled?: boolean; analyticsDeviceId?: string; analyticsEnabled?: boolean; };