diff --git a/src/@types/globals.d.ts b/src/@types/globals.d.ts index a90047a5..24769cbb 100644 --- a/src/@types/globals.d.ts +++ b/src/@types/globals.d.ts @@ -49,3 +49,5 @@ declare var serviceDisplayName: ServiceDisplayName; declare function addKeyDownListener(callback: (event: KeyboardEvent) => void): void; declare function removeKeyDownListener(callback: (event: KeyboardEvent) => void): void; + +declare const EXTENSION_VERSION: string; diff --git a/src/background/uninstall-feedback.ts b/src/background/uninstall-feedback.ts index af1db498..dc780fbe 100644 --- a/src/background/uninstall-feedback.ts +++ b/src/background/uninstall-feedback.ts @@ -1,15 +1,22 @@ import { browser } from 'webextension-polyfill-ts'; +import Browser from '~/common/utils/Browser'; import { loadedLog } from '~/common/utils/loadedLog'; import UsageStats from '~/common/utils/UsageStats'; loadedLog('background/uninstall-feedback.ts'); +function getUninstallUrl(userId: string | undefined): string | undefined { + if (userId == null) return undefined; + const encodedUserId = encodeURIComponent(userId); + const browserName = encodeURIComponent(Browser.detect()); + const appVersion = encodeURIComponent(EXTENSION_VERSION); + return `https://usage-stats.anime-skip.com/redirects/extension-uninstalled?user_id=${encodedUserId}&app_version=${appVersion}&browser=${browserName}`; +} + let prevUninstallUrl: string | undefined = undefined; setInterval(() => { Promise.resolve(UsageStats.getUserId()).then(userId => { - const uninstallUrl = userId - ? `https://usage-stats.anime-skip.com/redirects/${userId}/uninstall` - : undefined; + const uninstallUrl = userId ? getUninstallUrl(userId) : undefined; if (uninstallUrl !== prevUninstallUrl) { browser.runtime.setUninstallURL(uninstallUrl); console.log('Updated uninstall url:', uninstallUrl); diff --git a/src/common/utils/UsageStats.ts b/src/common/utils/UsageStats.ts index 82c97869..cc83eaf7 100644 --- a/src/common/utils/UsageStats.ts +++ b/src/common/utils/UsageStats.ts @@ -2,8 +2,6 @@ import { createUsageStatsClient, UsageStatsClientConfig } from '@anime-skip/usag import { browser } from 'webextension-polyfill-ts'; import Browser from './Browser'; -declare const EXTENSION_VERSION: string; - export const USAGE_STATS_USER_ID_STORAGE_KEY = 'usage-stats-user-id'; const getUserId: UsageStatsClientConfig['getUserId'] = async () => {