Skip to content

Commit

Permalink
chore: correct uninstall url and provide extra data
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Oct 29, 2021
1 parent b68aa43 commit 4d5735d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/@types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 10 additions & 3 deletions src/background/uninstall-feedback.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/common/utils/UsageStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 4d5735d

Please sign in to comment.