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

feat: disable analytics on FF #1695

Merged
merged 9 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 apps/extension/src/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
trackIndexedDbErrorExtras,
triggerIndexedDbUnavailablePopup,
} from "extension-core"
import { DEBUG } from "extension-shared"
import { DEBUG, IS_FIREFOX } from "extension-shared"
import { firstValueFrom, ReplaySubject } from "rxjs"

const normalizeUrl = (url: string) => {
Expand All @@ -18,7 +18,7 @@ settingsStore.observable.subscribe((settings) => useErrorTracking.next(settings.

export const initSentryFrontend = () => {
SentryReact.init({
enabled: true,
enabled: !IS_FIREFOX,
environment: process.env.BUILD,
dsn: process.env.SENTRY_DSN,
integrations: [SentryReact.browserTracingIntegration()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LockIcon,
ShieldZapIcon,
} from "@talismn/icons"
import { IS_FIREFOX } from "extension-shared"
import { Trans, useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom"
import { CtaButton, Toggle, Tooltip, TooltipContent, TooltipTrigger } from "talisman-ui"
Expand All @@ -15,7 +16,7 @@ import { HeaderBlock } from "@talisman/components/HeaderBlock"
import { Setting } from "@talisman/components/Setting"
import { Spacer } from "@talisman/components/Spacer"
import { useMnemonicBackup } from "@ui/hooks/useMnemonicBackup"
import { useSetting } from "@ui/state"
import { useFeatureFlag, useSetting } from "@ui/state"

import { DashboardLayout } from "../../layout"

Expand All @@ -26,6 +27,8 @@ const Content = () => {
const [autoRiskScan, setAutoRiskScan] = useSetting("autoRiskScan")
const navigate = useNavigate()

const withRiskAnalysis = useFeatureFlag("RISK_ANALYSIS")

const { allBackedUp } = useMnemonicBackup()

return (
Expand Down Expand Up @@ -55,83 +58,89 @@ const Content = () => {
subtitle={t("Set a timer to automatically lock your Talisman wallet")}
to={`/settings/security-privacy-settings/autolock`}
/>
<Setting
iconLeft={ShieldZapIcon}
title={
<span className="inline-flex items-center gap-[0.3em]">
<span>{t("Auto risk scan")}</span>
<Tooltip>
<TooltipTrigger className="inline-block">
<InfoIcon />
</TooltipTrigger>
<TooltipContent>
{t(
"This service is only available for some Ethereum networks, please visit Blowfish website for more information.",
)}
</TooltipContent>
</Tooltip>
</span>
}
subtitle={
<Trans t={t}>
Automatically assess risks of Ethereum transactions and messages via{" "}
<a
className="text-grey-200 hover:text-body"
href="https://blowfish.xyz"
target="_blank"
rel="noreferrer noopener"
>
Blowfish
</a>
</Trans>
}
>
<Toggle checked={autoRiskScan} onChange={(e) => setAutoRiskScan(e.target.checked)} />
</Setting>
<Setting
iconLeft={AlertCircleIcon}
title={t("Error reporting")}
subtitle={
<Trans t={t}>
Send anonymised error reports to Talisman (via{" "}
<a
className="text-grey-200 hover:text-body"
href="https://www.sentry.io"
target="_blank"
rel="noreferrer noopener"
>
Sentry
</a>
)
</Trans>
}
>
<Toggle
checked={useErrorTracking}
onChange={(e) => setUseErrorTracking(e.target.checked)}
/>
</Setting>
<Setting
iconLeft={ActivityIcon}
title={t("Analytics")}
subtitle={
<Trans t={t}>
Opt in to collection of anonymised usage data.{" "}
<button
type="button"
className="text-grey-200 hover:text-body"
onClick={() => navigate("/settings/analytics")}
>
Learn More
</button>
</Trans>
}
>
<Toggle
checked={useAnalyticsTracking}
onChange={(e) => setUseAnalyticsTracking(e.target.checked)}
/>
</Setting>
{withRiskAnalysis && (
<Setting
iconLeft={ShieldZapIcon}
title={
<span className="inline-flex items-center gap-[0.3em]">
<span>{t("Auto risk scan")}</span>
<Tooltip>
<TooltipTrigger className="inline-block">
<InfoIcon />
</TooltipTrigger>
<TooltipContent>
{t(
"This service is only available for some Ethereum networks, please visit Blowfish website for more information.",
)}
</TooltipContent>
</Tooltip>
</span>
}
subtitle={
<Trans t={t}>
Automatically assess risks of Ethereum transactions and messages via{" "}
<a
className="text-grey-200 hover:text-body"
href="https://blowfish.xyz"
target="_blank"
rel="noreferrer noopener"
>
Blowfish
</a>
</Trans>
}
>
<Toggle checked={autoRiskScan} onChange={(e) => setAutoRiskScan(e.target.checked)} />
</Setting>
)}
{!IS_FIREFOX && (
<>
<Setting
iconLeft={AlertCircleIcon}
title={t("Error reporting")}
subtitle={
<Trans t={t}>
Send anonymised error reports to Talisman (via{" "}
<a
className="text-grey-200 hover:text-body"
href="https://www.sentry.io"
target="_blank"
rel="noreferrer noopener"
>
Sentry
</a>
)
</Trans>
}
>
<Toggle
checked={useErrorTracking}
onChange={(e) => setUseErrorTracking(e.target.checked)}
/>
</Setting>
<Setting
iconLeft={ActivityIcon}
title={t("Analytics")}
subtitle={
<Trans t={t}>
Opt in to collection of anonymised usage data.{" "}
<button
type="button"
className="text-grey-200 hover:text-body"
onClick={() => navigate("/settings/analytics")}
>
Learn More
</button>
</Trans>
}
>
<Toggle
checked={useAnalyticsTracking}
onChange={(e) => setUseAnalyticsTracking(e.target.checked)}
/>
</Setting>
</>
)}
</div>
</>
)
Expand Down
3 changes: 2 additions & 1 deletion apps/extension/src/ui/apps/onboard/routes/Password.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { yupResolver } from "@hookform/resolvers/yup"
import { classNames } from "@talismn/util"
import { IS_FIREFOX } from "extension-shared"
import { useCallback, useEffect } from "react"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
Expand Down Expand Up @@ -86,7 +87,7 @@ export const PasswordPage = () => {
}, [setValue])

const navigateNext = useCallback(() => {
navigate(isResettingWallet ? "/accounts/add" : `/privacy`)
navigate(isResettingWallet || IS_FIREFOX ? "/accounts/add" : `/privacy`)
}, [navigate, isResettingWallet])

const submit = useCallback(
Expand Down
5 changes: 3 additions & 2 deletions apps/extension/src/ui/apps/onboard/routes/Privacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ export const PrivacyPage = () => {
always adjust these settings, or opt out completely at any time.
</p>
<p>
Read our{" "}
<a
onClick={handleLearnMoreClick}
className="text-body"
href={PRIVACY_POLICY_URL}
target="_blank"
>
Learn more
Privacy Policy
</a>{" "}
about what we track and how we use this data.
to learn more about what we track and how we use this data.
</p>
</div>
</Trans>
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-core/src/domains/analytics/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Sentry from "@sentry/browser"
import { DEBUG, log } from "extension-shared"
import { DEBUG, IS_FIREFOX, log } from "extension-shared"
import { v4 } from "uuid"

import { StorageProvider } from "../../libs/Store"
Expand Down Expand Up @@ -66,7 +66,7 @@ class AnalyticsStore extends StorageProvider<AnalyticsData> {
eventTimestamp?: number,
) {
const enabled = await settingsStore.get("useAnalyticsTracking")
if (!enabled) return
if (IS_FIREFOX || enabled === false) return

log.debug("AnalyticsStore.capture", { eventName, rawProperties, eventTimestamp })
const timestamp = eventTimestamp ?? Date.now()
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-core/src/domains/app/store.settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TokenRateCurrency } from "@talismn/token-rates"
import { IS_FIREFOX } from "extension-shared"

import { StorageProvider } from "../../libs/Store"
import { IdenticonType } from "../accounts/types"
Expand Down Expand Up @@ -28,7 +29,7 @@ export interface SettingsStoreData {
export class SettingsStore extends StorageProvider<SettingsStoreData> {}

export const DEFAULT_SETTINGS: SettingsStoreData = {
useErrorTracking: false,
useErrorTracking: !IS_FIREFOX,
useTestnets: false,
identiconType: "talisman-orb",
useAnalyticsTracking: undefined, // undefined for onboarding
Expand Down
6 changes: 3 additions & 3 deletions packages/extension-core/src/libs/Analytics.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DEBUG } from "extension-shared"
import { DEBUG, IS_FIREFOX } from "extension-shared"

import { analyticsStore } from "../domains/analytics/store"
import { PostHogCaptureProperties } from "../domains/analytics/types"
import { settingsStore } from "../domains/app/store.settings"
import { withGeneralReport } from "./GeneralReport"

class TalismanAnalytics {
#enabled = Boolean(process.env.POSTHOG_AUTH_TOKEN)
#enabled = !IS_FIREFOX && Boolean(process.env.POSTHOG_AUTH_TOKEN)

async capture(eventName: string, properties?: PostHogCaptureProperties) {
if (!this.#enabled) return
Expand All @@ -15,7 +15,7 @@ class TalismanAnalytics {
// have to put this manual check here because posthog is buggy and will not respect our settings
// https://github.com/PostHog/posthog-js/issues/336
const allowTracking = await settingsStore.get("useAnalyticsTracking")
if (!allowTracking) return
if (allowTracking === false) return

const captureProperties = await withGeneralReport(properties)
await analyticsStore.capture(eventName, captureProperties)
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-core/src/libs/GeneralReport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import keyring from "@polkadot/ui-keyring"
import { sleep } from "@talismn/util"
import { DEBUG } from "extension-shared"
import { DEBUG, IS_FIREFOX } from "extension-shared"
import groupBy from "lodash/groupBy"

import { db } from "../db"
Expand Down Expand Up @@ -84,7 +84,7 @@ async function getGeneralReport() {
settingsStore.get("useAnalyticsTracking"),
appStore.getIsOnboarded(),
])
if (!allowTracking || !onboarded) return
if (!allowTracking || !onboarded || IS_FIREFOX) return

//
// accounts
Expand Down
Loading