Skip to content

Commit 953ac86

Browse files
committed
update: proper profile based logic.
1 parent 13664d4 commit 953ac86

2 files changed

Lines changed: 24 additions & 14 deletions

File tree

src/lib/actions/analytics.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ENV, MODE, VARS, isCloud } from '$lib/system';
77
import { AppwriteException } from '@appwrite.io/console';
88
import { browser } from '$app/environment';
99
import { getReferrerAndUtmSource, getTrackedQueryParams } from '$lib/helpers/utm';
10-
import { ProfileMode } from '$lib/profiles/index.svelte';
10+
import { resolvedProfile } from '$lib/profiles/index.svelte';
1111

1212
function plausible(domain: string): AnalyticsPlugin {
1313
if (!browser) return { name: 'analytics-plugin-plausible' };
@@ -41,24 +41,17 @@ function plausible(domain: string): AnalyticsPlugin {
4141
};
4242
}
4343

44-
const PLAUSIBLE_DOMAINS = {
45-
CLOUD: 'cloud.appwrite.io',
46-
STUDIO: 'studio.imagine.dev',
47-
SELF_HOSTED: 'self-hosted.appwrite'
48-
/*GLOBAL: 'console.appwrite',*/
49-
};
44+
function getPlausibleDomain(): string | null {
45+
const plausibleConfig = resolvedProfile.analytics.plausible;
46+
if (!plausibleConfig) return null;
5047

51-
function getPlausibleDomain(): string {
52-
if (VARS.CONSOLE_PROFILE === ProfileMode.STUDIO) {
53-
return PLAUSIBLE_DOMAINS.STUDIO;
54-
} else {
55-
return isCloud ? PLAUSIBLE_DOMAINS.CLOUD : PLAUSIBLE_DOMAINS.SELF_HOSTED;
56-
}
48+
return isCloud ? plausibleConfig.cloud : (plausibleConfig.selfHosted ?? null);
5749
}
5850

51+
const plausibleDomain = getPlausibleDomain();
5952
const analytics = Analytics({
6053
app: 'appwrite',
61-
plugins: [plausible(getPlausibleDomain())]
54+
plugins: plausibleDomain ? [plausible(plausibleDomain)] : []
6255
});
6356

6457
export function trackEvent(name: string, data: object = null): void {

src/lib/profiles/index.svelte.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ export type Profile = {
7777
support: {
7878
technical: string[];
7979
};
80+
analytics: {
81+
plausible?: {
82+
cloud: string;
83+
selfHosted?: string;
84+
};
85+
};
8086
};
8187

8288
export const base: Profile = {
@@ -161,6 +167,12 @@ export const base: Profile = {
161167
'Sites',
162168
'Other'
163169
]
170+
},
171+
analytics: {
172+
plausible: {
173+
cloud: 'cloud.appwrite.io',
174+
selfHosted: 'self-hosted.appwrite'
175+
}
164176
}
165177
};
166178

@@ -243,6 +255,11 @@ export const studio: Profile = {
243255
'Storage',
244256
'Other'
245257
]
258+
},
259+
analytics: {
260+
plausible: {
261+
cloud: 'studio.imagine.dev'
262+
}
246263
}
247264
};
248265

0 commit comments

Comments
 (0)