Skip to content
Closed
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
4 changes: 4 additions & 0 deletions apps/basic-integration/sveltekit/CMSaasStarter/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ PRIVATE_SUPABASE_SERVICE_ROLE='REPLACE_ME'
# Stripe settings
PRIVATE_STRIPE_API_KEY='REPLACE_ME'

# PostHog settings
PUBLIC_POSTHOG_PROJECT_TOKEN='your_posthog_project_token_here'
PUBLIC_POSTHOG_HOST='https://us.i.posthog.com'

# Optional - settings for email

# Email address admin messages will be sent to
Expand Down
150 changes: 134 additions & 16 deletions apps/basic-integration/sveltekit/CMSaasStarter/package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@supabase/ssr": "^0.5.2",
"@supabase/supabase-js": "^2.45.2",
"handlebars": "^4.7.8",
"posthog-js": "^1.438.13",
"resend": "^3.5.0",
"stripe": "^13.3.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { dev } from "$app/environment"
import { env } from "$env/dynamic/public"
import type { HandleClientError } from "@sveltejs/kit"
import posthog from "posthog-js"

export async function init() {
if (!env.PUBLIC_POSTHOG_PROJECT_TOKEN) {
if (dev) {
throw new Error(
"PUBLIC_POSTHOG_PROJECT_TOKEN variable required by PostHog is missing or un-configured, this causes events to be silently missed. This error stops appearing once PUBLIC_POSTHOG_PROJECT_TOKEN is configured",
)
}
return
}

if (!env.PUBLIC_POSTHOG_HOST) {
if (dev) {
throw new Error(
"PUBLIC_POSTHOG_HOST variable required by PostHog is missing or un-configured, this causes events to be silently missed. This error stops appearing once PUBLIC_POSTHOG_HOST is configured",
)
}
return
}

posthog.init(env.PUBLIC_POSTHOG_PROJECT_TOKEN, {
api_host: env.PUBLIC_POSTHOG_HOST,
capture_exceptions: true,
logs: {
serviceName: "cm-saas-starter-web",
environment: dev ? "development" : "production",
},
})
}

export const handleError: HandleClientError = ({ error, message }) => {
if (env.PUBLIC_POSTHOG_PROJECT_TOKEN && env.PUBLIC_POSTHOG_HOST) {
posthog.captureException(error)
}

return { message }
}
Loading
Loading