From b328ead8cff0f97ff8621145fc6f74c15eed184b Mon Sep 17 00:00:00 2001
From: Darshan
Date: Sat, 10 May 2025 17:20:12 +0530
Subject: [PATCH] update: handle events.
---
src/lib/actions/analytics.ts | 45 +++++++------------
.../components/AppwriteIn100Seconds.svelte | 12 ++---
src/lib/components/FooterNav.svelte | 14 +++++-
src/lib/components/IsLoggedIn.svelte | 18 ++------
src/lib/components/MainNav.svelte | 7 +--
src/lib/components/PreFooter.svelte | 23 ++++------
.../components/ProductsMobileSubmenu.svelte | 16 +++----
src/lib/components/ProductsSubmenu.svelte | 9 +---
src/lib/components/Technologies.svelte | 5 ++-
src/lib/components/ui/button.svelte | 16 ++++---
src/lib/layouts/Main.svelte | 6 +--
src/routes/+layout.svelte | 5 +--
src/routes/+page.svelte | 10 ++---
src/routes/community/+page.svelte | 5 +++
src/routes/community/EventCard.svelte | 2 +-
src/routes/community/ProjectCard.svelte | 3 ++
src/routes/company/+page.svelte | 1 +
src/routes/contact-us/+page.svelte | 3 ++
src/routes/contact-us/enterprise/+page.svelte | 5 ++-
.../{+page.server.js => +page.server.ts} | 0
src/routes/pricing/+page.svelte | 14 +++++-
src/routes/pricing/compare-plans.svelte | 6 ++-
.../products/auth/(components)/SSR.svelte | 3 +-
src/routes/startups/+page.svelte | 5 +--
24 files changed, 108 insertions(+), 125 deletions(-)
rename src/routes/discord/{+page.server.js => +page.server.ts} (100%)
diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts
index db883247a..c39d53894 100644
--- a/src/lib/actions/analytics.ts
+++ b/src/lib/actions/analytics.ts
@@ -1,12 +1,11 @@
-import { Analytics, type AnalyticsPlugin } from 'analytics';
-import Plausible from 'plausible-tracker';
-import posthogEvent from 'posthog-js';
-import { get } from 'svelte/store';
-import { page } from '$app/stores';
-
+import { page } from '$app/state';
import { ENV } from '$lib/system';
import { browser } from '$app/environment';
+import posthogEvent from 'posthog-js';
+import Plausible from 'plausible-tracker';
+import { Analytics, type AnalyticsPlugin } from 'analytics';
+
type Payload = {
payload: {
event: string;
@@ -55,30 +54,20 @@ const analytics = Analytics({
plugins: [plausible('appwrite.io')]
});
-export type TrackEventArgs = {
- plausible?: { name: string; data?: object };
- posthog?: { name: string };
-};
+export type TrackEventArgs = { name: string; data?: object };
-export const trackEvent = async (platforms: TrackEventArgs) => {
- if (!isTrackingAllowed()) {
+export const trackEvent = (eventArgs?: string | TrackEventArgs): void => {
+ if (!eventArgs || ENV.TEST) return;
+
+ const path = page.route.id ?? '';
+ const name = typeof eventArgs === 'string' ? eventArgs : eventArgs.name;
+ const data = typeof eventArgs === 'string' ? { path } : { ...eventArgs.data, path };
+
+ if (ENV.DEV || ENV.PREVIEW) {
+ console.log(`[Analytics] Event:`, name, data);
return;
}
- const currentPage = get(page);
- const path = currentPage.route.id ?? '';
-
- if (ENV.DEV || ENV.PREVIEW) {
- console.log(`[Analytics] Event`, platforms.plausible, platforms.posthog);
- } else {
- if (platforms.plausible) {
- await analytics.track(platforms.plausible.name, { ...platforms.plausible.data, path });
- }
-
- if (platforms.posthog) {
- posthogEvent.capture(platforms.posthog.name);
- }
- }
+ posthogEvent.capture(name, data);
+ analytics.track(name, data).then();
};
-
-export const isTrackingAllowed = () => !ENV.TEST;
diff --git a/src/lib/components/AppwriteIn100Seconds.svelte b/src/lib/components/AppwriteIn100Seconds.svelte
index 0407d7987..c1148878b 100644
--- a/src/lib/components/AppwriteIn100Seconds.svelte
+++ b/src/lib/components/AppwriteIn100Seconds.svelte
@@ -1,8 +1,7 @@
- trackEvent({
- plausible: {
- name: plan.eventName
- }
- })}
>
{plan.buttonText}
diff --git a/src/lib/components/ProductsMobileSubmenu.svelte b/src/lib/components/ProductsMobileSubmenu.svelte
index 14192ae09..2a8282d53 100644
--- a/src/lib/components/ProductsMobileSubmenu.svelte
+++ b/src/lib/components/ProductsMobileSubmenu.svelte
@@ -1,9 +1,9 @@
{#if href}
-
+ event && trackEvent(event)} {...rest}>
{@render children()}
{:else}
-
+ event && trackEvent(event)} {...rest}>
{@render children()}
{/if}
diff --git a/src/lib/layouts/Main.svelte b/src/lib/layouts/Main.svelte
index 207b7f1ed..86b2a7839 100644
--- a/src/lib/layouts/Main.svelte
+++ b/src/lib/layouts/Main.svelte
@@ -227,11 +227,7 @@
target="_blank"
rel="noopener noreferrer"
class="web-u-inline-width-100-percent-mobile"
- onclick={() =>
- trackEvent({
- plausible: { name: 'Star on GitHub in header' },
- posthog: { name: 'github-stars_nav_click' }
- })}
+ event={{ name: 'github-stars-nav-click' }}
>
Star on GitHub
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 56bccd099..8cc95abe3 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -127,10 +127,7 @@
const eventName = `${pageName}_scroll-depth_${threshold * 100}prct_scroll`;
tracked.add(threshold);
- trackEvent({
- plausible: { name: eventName },
- posthog: { name: eventName }
- });
+ trackEvent(eventName);
}
});
}
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 46c4f833e..80e33ff0e 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -136,7 +136,7 @@
trackEvent({ plausible: { name: 'Banner button click' } })}
+ onclick={() => trackEvent('main-banner-button-click')}
>
New
@@ -162,11 +162,7 @@
- trackEvent({
- plausible: { name: 'Get started in hero' },
- posthog: { name: 'get-started-btn_hero_click' }
- })}
+ onclick={() => trackEvent('get-started-btn-hero-click')}
>
Start building
@@ -487,7 +483,7 @@
trackEvent({ plausible: { name: 'Explore all SDKs' } })}
+ onclick={() => trackEvent('main-explore-all-sdks-click')}
>Explore all SDKs
diff --git a/src/routes/community/+page.svelte b/src/routes/community/+page.svelte
index 1a174e16a..bbf008bb2 100644
--- a/src/routes/community/+page.svelte
+++ b/src/routes/community/+page.svelte
@@ -57,6 +57,7 @@
import { SOCIAL_STATS } from '$lib/constants';
import { Button, Icon } from '$lib/components/ui';
+ import { trackEvent } from '$lib/actions/analytics';
import InlineTag from '$lib/components/ui/inline-tag.svelte';
let { data } = $props();
@@ -113,6 +114,9 @@
submitting = true;
error = undefined;
const response = await newsletter(name, email);
+
+ trackEvent('community-insights-subscribe-submit');
+
submitting = false;
if (response.status >= 400) {
error = response.status >= 500 ? 'Server Error.' : 'Error submitting form.';
@@ -464,6 +468,7 @@
target="_blank"
rel="noopener noreferrer"
class="mt-4 self-center"
+ event="community-built-with-appwrite-click"
>
View all projects
diff --git a/src/routes/community/EventCard.svelte b/src/routes/community/EventCard.svelte
index 1a8d3adc7..d213aaffc 100644
--- a/src/routes/community/EventCard.svelte
+++ b/src/routes/community/EventCard.svelte
@@ -59,7 +59,7 @@
{description}
-
+
{buttonText}
diff --git a/src/routes/community/ProjectCard.svelte b/src/routes/community/ProjectCard.svelte
index 7586fddf5..b81087faf 100644
--- a/src/routes/community/ProjectCard.svelte
+++ b/src/routes/community/ProjectCard.svelte
@@ -11,6 +11,8 @@