mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
44 lines
947 B
TypeScript
44 lines
947 B
TypeScript
import Analytics from 'analytics';
|
|
import googleAnalytics from '@analytics/google-analytics';
|
|
import { get } from 'svelte/store';
|
|
import { page } from '$app/stores';
|
|
|
|
const analytics = Analytics({
|
|
app: 'appwrite',
|
|
plugins: [
|
|
googleAnalytics({
|
|
measurementIds: [globalThis.GOOGLE_ANALYTICS]
|
|
})
|
|
]
|
|
});
|
|
|
|
export function trackEvent(name: string, data: object = null): void {
|
|
if (!isTrackingAllowed()) {
|
|
return;
|
|
}
|
|
|
|
analytics.track(name, { ...data, path: get(page).routeId });
|
|
}
|
|
|
|
export function trackPageView(path: string) {
|
|
if (!isTrackingAllowed()) {
|
|
return;
|
|
}
|
|
|
|
analytics.page({
|
|
path
|
|
});
|
|
}
|
|
|
|
function isTrackingAllowed() {
|
|
if (window.navigator?.doNotTrack) {
|
|
if (navigator.doNotTrack === '1' || navigator.doNotTrack === 'yes') {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|