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
216 changes: 203 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"e2e": "playwright test tests/e2e"
},
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"analytics": "^0.8.1",
"@aw-labs/appwrite-console": "^11.0.0",
"@aw-labs/icons": "0.0.0-77",
"@aw-labs/ui": "0.0.0-77",
Expand All @@ -40,7 +42,6 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/svelte": "^3.2.2",
"@testing-library/user-event": "^14.4.3",
"@types/gtag.js": "^0.0.12",
"@types/prismjs": "^1.26.0",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
Expand Down
2 changes: 0 additions & 2 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/// <reference types="@sveltejs/kit" />
/// <reference types="@types/gtag.js" />
interface Window {
GOOGLE_ANALYTICS: string | false;
VERCEL_ANALYTICS_ID: string | false;
SENTRY_DSN: string | false;
}
46 changes: 25 additions & 21 deletions src/lib/actions/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import type { Action } from 'svelte/action';
import Analytics from 'analytics';
import googleAnalytics from '@analytics/google-analytics';
import { get } from 'svelte/store';
import { page } from '$app/stores';

export type AnalyticsActionParam = {
name: string;
action: string;
category?: string;
label?: string;
parameters?: Record<string, string>;
event?: keyof HTMLElementEventMap;
};
const analytics = Analytics({
app: 'appwrite',
plugins: [
googleAnalytics({
measurementIds: [import.meta.env.VITE_GOOGLE_ANALYTICS?.toString()]
})
]
});

export const event: Action<HTMLElement, Partial<AnalyticsActionParam>> = (node, param) => {
export function trackEvent(name: string, data: object = null): void {
if (!isTrackingAllowed()) {
return;
}

node.addEventListener(param.event ?? 'click', () => {
gtag('event', param.name, {
...param.parameters,
action: param.action
});
});
};
analytics.track(name, { ...data, path: get(page).routeId });
}

const isTrackingAllowed = () => {
if (!('gtag' in window)) {
return false;
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;
Expand All @@ -36,4 +40,4 @@ const isTrackingAllowed = () => {
} else {
return true;
}
};
}
Loading