Skip to content
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
35 changes: 22 additions & 13 deletions src/lib/actions/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import { AppwriteException } from '@appwrite.io/console';
import { browser } from '$app/environment';

function plausible(domain: string): AnalyticsPlugin {
if (!browser) return { name: 'analytics-plugin-plausible' };

const instance = Plausible({
domain
});

return {
name: 'analytics-plugin-plausible',
page: ({ payload }) => {
Expand All @@ -38,21 +41,27 @@ function plausible(domain: string): AnalyticsPlugin {
};
}

const PLAUSIBLE_DOMAINS = {
CLOUD: 'cloud.appwrite.io',
GLOBAL: 'console.appwrite',
SELF_HOSTED: 'self-hosted.appwrite'
};

const analytics = Analytics({
app: 'appwrite',
plugins:
isCloud && browser
? [
plausible('cloud.appwrite.io'),
googleTagManager({
containerId: [VARS.GOOGLE_TAG || 'GTM-P3T9TBV']
})
]
: [
googleAnalytics({
measurementIds: [VARS.GOOGLE_ANALYTICS || 'G-R4YJ9JN8L4']
})
]
plugins: isCloud
? [
plausible(PLAUSIBLE_DOMAINS.CLOUD),
googleTagManager({
containerId: [VARS.GOOGLE_TAG || 'GTM-P3T9TBV']
})
]
: [
plausible(PLAUSIBLE_DOMAINS.SELF_HOSTED),
googleAnalytics({
measurementIds: [VARS.GOOGLE_ANALYTICS || 'G-R4YJ9JN8L4']
})
]
});

export function trackEvent(name: string, data: object = null): void {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ export const VARS = {
| string
| undefined,
CONSOLE_MODE: import.meta.env?.VITE_CONSOLE_MODE?.toString() as string | undefined,
VERCEL_ENV: import.meta.env?.VITE_VERCEL_ENV?.toString() as string | undefined,
GOOGLE_ANALYTICS: import.meta.env?.VITE_GA_PROJECT?.toString() as string | undefined,
GOOGLE_TAG: import.meta.env?.VITE_GTM_PROJECT?.toString() as string | undefined
};

export const ENV = {
DEV: import.meta.env.DEV,
PROD: import.meta.env.PROD,
PREVIEW: VARS.VERCEL_ENV === 'preview',
PREVIEW: import.meta.env?.VERCEL === '1',
TEST: !!import.meta.env?.VITEST
};

Expand Down