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
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ NEXT_PUBLIC_POSTHOG_KEY=
# Set on the Convex deployment (not here):
# CLERK_JWT_ISSUER_DOMAIN - the Frontend API URL of your Clerk app, e.g. https://clerk.pseudoeditor.dev
# CLERK_WEBHOOK_SECRET - signing secret of the Clerk webhook pointing at <convex-site-url>/clerk/webhook
# (events: user.created, user.deleted)
# (events: user.created, user.deleted). For production, set it in Vercel's
# Production environment instead: the build copies it to Convex.
# POSTHOG_PROJECT_KEY - production deployment only: same key as NEXT_PUBLIC_POSTHOG_KEY, for anonymous
# account counts
# account counts. The production build copies it from NEXT_PUBLIC_POSTHOG_KEY.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ the Production environment. In the PostHog project, turn on **Settings > Project
cookieless tracking**, or PostHog drops every event the site sends. Keep session replay off, and set event
retention to one year or less to match the privacy policy.

Account counts come from Convex, not the browser. Set `POSTHOG_PROJECT_KEY` (the same project key) on the
production Convex deployment only. The Clerk webhook then sends anonymous `account_created` and `account_deleted`
Account counts come from Convex, not the browser. Each production build copies `NEXT_PUBLIC_POSTHOG_KEY` to
the production Convex deployment as `POSTHOG_PROJECT_KEY`, and copies `CLERK_WEBHOOK_SECRET` when it is set in
Vercel, so set both in Vercel's Production environment rather than on Convex. The Clerk webhook then sends anonymous `account_created` and `account_deleted`
events, and a daily cron (`convex/crons.ts`) sends `account_stats`: the number of synced accounts and how many
saved their workspace in the last 1, 7, and 30 days. None of these events identify an account.

Expand Down
20 changes: 20 additions & 0 deletions scripts/vercel-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ if [[ "${VERCEL_ENV:-}" != "production" && "${CONVEX_DEPLOY_KEY}" == prod:* ]];
exit 0
fi

# Copies a Vercel setting into the production Convex deployment. Only an admin deploy key can write
# production Convex variables, and the production build holds one, so Vercel is the single place to
# set them. The value goes in through stdin, so it never appears in the command line or the build log.
sync_convex_env() {
local name=$1 value=$2
if [[ -z "$value" ]]; then
echo "$name is unset in Vercel; leaving it unchanged on Convex."
return
fi
printf '%s' "$value" | pnpm exec convex env set "$name" >/dev/null
echo "Synced $name to Convex."
}

if [[ "${VERCEL_ENV:-}" == "production" && "${CONVEX_DEPLOY_KEY}" == prod:* ]]; then
# Account analytics (convex/analytics.ts) use the same public project key as the browser.
sync_convex_env POSTHOG_PROJECT_KEY "${NEXT_PUBLIC_POSTHOG_KEY:-}"
# Verifies Clerk's user.created and user.deleted webhook (convex/http.ts).
sync_convex_env CLERK_WEBHOOK_SECRET "${CLERK_WEBHOOK_SECRET:-}"
fi

pnpm exec convex deploy \
--cmd "pnpm --filter @pseudoeditor/web build" \
--cmd-url-env-var-name NEXT_PUBLIC_CONVEX_URL
Loading