diff --git a/src/Vencord.ts b/src/Vencord.ts index 83c69e73..582ee3b8 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -34,6 +34,7 @@ import { patches, PMLogger, startAllPlugins } from "./plugins"; import { localStorage } from "./utils/localStorage"; import { relaunch } from "./utils/native"; import { getCloudSettings, putCloudSettings } from "./utils/settingsSync"; +import { sendTelemetry } from "./utils/telemetry"; import { checkForUpdates, update, UpdateLogger } from "./utils/updater"; import { onceReady } from "./webpack"; import { SettingsRouter } from "./webpack/common"; @@ -83,6 +84,8 @@ async function init() { syncSettings(); + sendTelemetry(); + if (!IS_WEB) { try { const isOutdated = await checkForUpdates(); diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 368f88f7..394b6671 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -61,6 +61,8 @@ export interface Settings { settingsSync: boolean; settingsSyncVersion: number; }; + + telemetry: boolean; } const DefaultSettings: Settings = { @@ -91,7 +93,9 @@ const DefaultSettings: Settings = { url: "https://api.vencord.dev/", settingsSync: false, settingsSyncVersion: 0 - } + }, + + telemetry: true }; try { diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index d368a159..532e93e4 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -91,6 +91,11 @@ function VencordSettings() { key: "macosTranslucency", title: "Enable translucent window", note: "Requires a full restart" + }, + { + key: "telemetry", + title: "Enable Telemetry", + note: "We only gather anonymous telemetry data. All data deleted after 3 days if you opt out." } ]; diff --git a/src/utils/telemetry.tsx b/src/utils/telemetry.tsx new file mode 100644 index 00000000..5804d911 --- /dev/null +++ b/src/utils/telemetry.tsx @@ -0,0 +1,65 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Settings } from "@api/Settings"; +import { Alerts, SettingsRouter } from "@webpack/common"; + +import { isPluginEnabled } from "../plugins"; +import { Plugins } from "../Vencord"; +import { isLinux, isMac, isWindows } from "./constants"; +import { localStorage } from "./localStorage"; + +export function sendTelemetry() { + // if (IS_DEV) return; // don't send on devbuilds, usually contains incorrect data + + // if we have not yet told the user about the telemetry's existence, DON'T send + // a probe now, but tell them and then let them decide if they want to opt in or + // not. this only takes place the next time the mod starts. + if (!localStorage.getItem("Vencord_telemetryAcknowledged")) { + Alerts.show({ + title: "Telemetry Notice", + body: <> +

+ Vencord has a telemetry feature that sends anonymous data to us, which we use to improve the mod. +

+

+ If you don't want this, that's okay! We haven't sent anything yet. You can disable this in the + settings at any time, easily. If you choose to do nothing, we'll send some information the next time + you reload or restart Discord. +

+ , + confirmText: "Okay", + secondaryConfirmText: "Vencord Settings", + onConfirmSecondary() { + SettingsRouter.open("VencordSettings"); + }, + }); + + localStorage.setItem("Vencord_telemetryAcknowledged", "1"); + + return; + } + + // if it's disabled in settings, obviously don't do anything + if (!Settings.telemetry) return; + + const activePluginsList = Object.keys(Plugins.plugins) + .filter(p => isPluginEnabled(p)); + + let operatingSystem = "Unknown"; + + if (isWindows) operatingSystem = "Windows"; + else if (isMac) operatingSystem = "macOS"; + else if (isLinux) operatingSystem = "Linux"; + + const data = { + version: VERSION, + plugins: activePluginsList, + operatingSystem + }; + + navigator.sendBeacon("https://api.vencord.dev/v1/telemetry", JSON.stringify(data)); +}