Skip to content

Commit 89c8b0d

Browse files
authored
Use Posthog over Vercel analytics (#4389)
1 parent e971d98 commit 89c8b0d

File tree

10 files changed

+124
-87
lines changed

10 files changed

+124
-87
lines changed

.github/workflows/build-frontend.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
sentry_auth_token=$(aws ssm get-parameter --output text --query Parameter.Value --with-decryption --name /pythonit/${{ inputs.tf_environment }}/common/sentry-auth-token)
4343
echo "::add-mask::$sentry_auth_token"
4444
echo "SENTRY_AUTH_TOKEN=$sentry_auth_token" >> "$GITHUB_OUTPUT"
45+
46+
posthog_key=$(aws ssm get-parameter --output text --query Parameter.Value --with-decryption --name /pythonit/${{ inputs.tf_environment }}/pycon-frontend/posthog-key)
47+
echo "::add-mask::$posthog_key"
48+
echo "POSTHOG_KEY=$posthog_key" >> "$GITHUB_OUTPUT"
4549
- name: Build and push
4650
uses: docker/build-push-action@v6
4751
with:
@@ -62,4 +66,5 @@ jobs:
6266
CONFERENCE_CODE=${{ steps.vars.outputs.conference_code }}
6367
GIT_HASH=${{ inputs.githash }}
6468
secrets: |
65-
"sentry_auth_token=${{ steps.vars.outputs.sentry_auth_token }}"
69+
sentry_auth_token=${{ steps.vars.outputs.sentry_auth_token }}
70+
posthog_key=${{ steps.vars.outputs.posthog_key }}

frontend/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ COPY . .
2626

2727
RUN corepack enable pnpm
2828
RUN --mount=type=secret,id=sentry_auth_token,env=SENTRY_AUTH_TOKEN \
29+
--mount=type=secret,id=posthog_key,env=POSTHOG_KEY \
2930
pnpm run build
3031

3132
FROM base AS runner

frontend/next.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
CMS_ADMIN_HOST = "admin.pycon.it",
1212
NEXT_PUBLIC_SITE_URL,
1313
SENTRY_AUTH_TOKEN,
14+
POSTHOG_KEY,
1415
} = process.env;
1516

1617
const nextConfig = {
@@ -21,6 +22,7 @@ const nextConfig = {
2122
localeDetection: false,
2223
},
2324
trailingSlash: false,
25+
skipTrailingSlashRedirect: true,
2426
cacheHandler:
2527
process.env.VERCEL_ENV === "preview"
2628
? undefined
@@ -89,6 +91,14 @@ const nextConfig = {
8991
source: "/graphql",
9092
destination: `${API_URL_SERVER}/graphql`,
9193
},
94+
{
95+
source: "/ingest/static/:path*",
96+
destination: "https://eu-assets.i.posthog.com/static/:path*",
97+
},
98+
{
99+
source: "/ingest/:path*",
100+
destination: "https://eu.i.posthog.com/:path*",
101+
},
92102
];
93103

94104
if (API_URL_SERVER.includes("http://backend")) {
@@ -111,6 +121,7 @@ const nextConfig = {
111121
env: {
112122
API_URL: API_URL,
113123
conferenceCode: CONFERENCE_CODE || "pycon-demo",
124+
POSTHOG_KEY: POSTHOG_KEY,
114125
cmsHostname: CMS_HOSTNAME,
115126
NEXT_PUBLIC_SITE_URL: NEXT_PUBLIC_SITE_URL
116127
? `https://${NEXT_PUBLIC_SITE_URL}/`

frontend/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
"@neshca/cache-handler": "^1.9.0",
2727
"@python-italia/pycon-styleguide": "0.1.210",
2828
"@sentry/nextjs": "^8.45.0",
29-
"@vercel/analytics": "^1.1.1",
3029
"@vercel/og": "^0.6.5",
31-
"@vercel/speed-insights": "^1.0.12",
3230
"@xstate/react": "^3.0.1",
3331
"clsx": "^1.2.1",
3432
"concurrently": "^9.1.0",
@@ -45,6 +43,7 @@
4543
"next": "15.2.0",
4644
"next-cookies": "^2.0.3",
4745
"pdfkit": "^0.15.1",
46+
"posthog-js": "^1.225.0",
4847
"react": "19.0.0",
4948
"react-dnd": "^11.1.3",
5049
"react-dnd-html5-backend": "^11.1.3",

frontend/pnpm-lock.yaml

Lines changed: 50 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/add-schedule-to-calendar-modal/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Spacer,
66
Text,
77
} from "@python-italia/pycon-styleguide";
8-
import va from "@vercel/analytics";
8+
import posthog from "posthog-js";
99
import { FormattedMessage } from "react-intl";
1010
import { useCurrentUser } from "~/helpers/use-current-user";
1111
import { useTranslatedMessage } from "~/helpers/use-translated-message";
@@ -38,7 +38,7 @@ export const AddScheduleToCalendarModal = ({ onClose }: Props) => {
3838
const autoSelectInput = (e: React.MouseEvent<HTMLInputElement>) => {
3939
(e.target as HTMLInputElement).select();
4040
document.execCommand("copy");
41-
va.track("copy-calendar-url");
41+
posthog.capture("copy-calendar-url");
4242
};
4343

4444
const pleaseWaitMessage = useTranslatedMessage("login.loading");

frontend/src/components/schedule-view/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
Spacer,
77
Text,
88
} from "@python-italia/pycon-styleguide";
9-
import va from "@vercel/analytics";
9+
import posthog from "posthog-js";
10+
1011
import { isAfter, isBefore, parseISO } from "date-fns";
1112
import { fromZonedTime } from "date-fns-tz";
1213
import React, {
@@ -144,7 +145,7 @@ export const ScheduleView = ({
144145
setViewMode((current) => {
145146
const nextValue = current === "grid" ? "list" : "grid";
146147
prevViewMode.current = nextValue;
147-
va.track("schedule-view", { view: nextValue });
148+
posthog.capture("schedule-view", { view: nextValue });
148149
return nextValue;
149150
});
150151
}, []);

frontend/src/middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function middleware(req: NextRequest) {
3131
!PUBLIC_FILE.test(req.nextUrl.pathname) &&
3232
!req.nextUrl.pathname.includes("/api/") &&
3333
!req.nextUrl.pathname.includes("/admin") &&
34+
!req.nextUrl.pathname.includes("/ingest") &&
3435
!req.nextUrl.pathname.includes("/local_files_upload") &&
3536
!req.nextUrl.pathname.includes("/media") &&
3637
!req.nextUrl.pathname.includes("/graphql") &&

0 commit comments

Comments
 (0)