Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
π Share the PostHog id across rallly.co and the app (#3358)
Luke Vella5c923225ccad
diff --git a/apps/landing/src/app/[locale]/(main)/cookie-policy/page.tsx b/apps/landing/src/app/[locale]/(main)/cookie-policy/page.tsxindex 06af8ee27..a6180280f 100644--- a/apps/landing/src/app/[locale]/(main)/cookie-policy/page.tsx+++ b/apps/landing/src/app/[locale]/(main)/cookie-policy/page.tsx@@ -9,7 +9,7 @@ export default async function CookiePolicy() {cacheLife("max");return (<Section>- <LegalPageLayout title="Cookie policy" lastUpdated="2026-09-08">+ <LegalPageLayout title="Cookie policy" lastUpdated="2026-09-23"><p>This Policy explains how we use cookies and other similar technologieson our website, and your options to control them.@@ -43,18 +43,23 @@ export default async function CookiePolicy() {<h2>Analytics</h2><p>- We use PostHog for product analytics. PostHog does not set cookies and- does not store anything on your device. Users who are signed in are- recognised through their account: their analytics profile is keyed to- their account and carries the name and email address on it, so it is- identified data rather than anonymous data. Our{" "}+ We use PostHog for product analytics. PostHog sets a first-party+ cookie (<code>ph_*_posthog</code>) holding a random identifier, and a+ copy in your browser's local storage. The cookie is shared+ between this website and the app at app.rallly.co; local storage is+ kept separately by each. It lets us see which pages lead people to+ sign up. When you sign in, activity recorded under that identifier,+ including pages you visited on this website before creating an+ account, is linked to your account. Your analytics profile carries the+ name and email address on your account, so it is identified data+ rather than anonymous data. Our{" "}<LinkBase href="/privacy-policy">privacy policy</LinkBase> explains- why we keep it and when it is erased. Visitors who are not signed in- are counted using a hash derived from IP address and browser that- changes every day and cannot be used to identify anyone. The data- collected includes pages visited, events triggered, and device type.- It is stored on PostHog's servers in the EU and is not used for- advertising or shared with third parties.+ why we keep it and when it is erased. The data collected includes+ pages visited, events triggered, the website that referred you, and+ device type. It is stored on PostHog's servers in the EU and is+ not used for advertising or shared with third parties. The cookie+ expires after one year, and signing out replaces the identifier with a+ new one.</p><h2>Your options</h2>diff --git a/apps/landing/src/app/[locale]/(main)/privacy-policy/page.tsx b/apps/landing/src/app/[locale]/(main)/privacy-policy/page.tsxindex 60b786ad8..cc2c16d8a 100644--- a/apps/landing/src/app/[locale]/(main)/privacy-policy/page.tsx+++ b/apps/landing/src/app/[locale]/(main)/privacy-policy/page.tsx@@ -9,7 +9,7 @@ export default async function PrivacyPolicy() {cacheLife("max");return (<Section>- <LegalPageLayout title="Privacy policy" lastUpdated="2026-09-14">+ <LegalPageLayout title="Privacy policy" lastUpdated="2026-09-23"><p>At rallly.co, we take your privacy seriously. This privacy policyexplains how we collect, use, and disclose your personal data, and@@ -53,6 +53,9 @@ export default async function PrivacyPolicy() {can find your account's activity and work out what went wrong. Itis not written into individual analytics events, is not used formarketing, and is erased from Posthog when you delete your account.+ When you create an account, the pages you visited on our website+ beforehand are linked to your profile so we can tell which pages lead+ people to Rallly.</p><h2>Optional information about your work</h2>diff --git a/apps/landing/src/app/[locale]/layout.tsx b/apps/landing/src/app/[locale]/layout.tsxindex 7356f9e06..aca9092b6 100644--- a/apps/landing/src/app/[locale]/layout.tsx+++ b/apps/landing/src/app/[locale]/layout.tsx@@ -41,8 +41,6 @@ export default async function Root(props: {<body><LazyMotion features={domAnimation}><I18nProvider locale={i18n.resolvedLanguage} resources={translations}>- {/* Both cookieless (daily-rotating server-side hash, nothing- stored on the device), so neither needs consent. */}<PostHogInit>{children}</PostHogInit><Analytics /></I18nProvider>diff --git a/apps/web/src/app/[locale]/components/posthog-init.tsx b/apps/web/src/app/[locale]/components/posthog-init.tsxindex fba3a867d..c09071fa8 100644--- a/apps/web/src/app/[locale]/components/posthog-init.tsx+++ b/apps/web/src/app/[locale]/components/posthog-init.tsx@@ -18,7 +18,7 @@ export async function PostHogSessionInit({const user = session?.user;return (- <PostHogInit distinctId={user && !user.isGuest ? user.id : undefined}>+ <PostHogInit distinctId={user && !user.isGuest ? user.id : null}>{children}</PostHogInit>);diff --git a/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsxindex 782e5881d..a489de86c 100644--- a/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx+++ b/apps/web/src/app/[locale]/e/[id]/components/rsvp-verify-email.tsx@@ -129,9 +129,9 @@ export function RsvpVerifyEmail({}dialog.dismiss();- // A full reload, not router.refresh(): the PostHog client fixes its- // identity at page load (cookieless for the guest who opened this page),- // and only a new document can start it as the signed-in user.+ // A full reload, not router.refresh(): the PostHog client settles its+ // identity at page load, so only a new document identifies the guest who+ // opened this page as the signed-in user.window.location.reload();});diff --git a/apps/web/src/features/user/client.tsx b/apps/web/src/features/user/client.tsxindex 89e41acc0..eb9880da2 100644--- a/apps/web/src/features/user/client.tsx+++ b/apps/web/src/features/user/client.tsx@@ -25,8 +25,8 @@ export function UserProvider({const name = user?.name;const email = user?.email;- // The client is already identified as this user from init (bootstrap in- // packages/posthog/src/client-config.ts), so no identify() here. Name and+ // The client is already identified as this user from init (initPostHog in+ // packages/posthog/src/client.ts), so no identify() here. Name and// email ride along so a profile PostHog has to recreate for an existing// account is never empty. Changing the language refreshes the router with// a new [locale] param, so this re-runs; posthog-js drops a repeat $setdiff --git a/packages/posthog/package.json b/packages/posthog/package.jsonindex d0d7cb37d..ae8870e2a 100644--- a/packages/posthog/package.json+++ b/packages/posthog/package.json@@ -16,7 +16,7 @@},"dependencies": {"js-cookie": "^3.0.1",- "posthog-js": "^1.407.2",+ "posthog-js": "^1.434.11","posthog-node": "^5.46.1","react": "19.2.6"},diff --git a/packages/posthog/src/client-config.test.ts b/packages/posthog/src/client-config.test.tsindex a2e9a10f5..aeadf1a5a 100644--- a/packages/posthog/src/client-config.test.ts+++ b/packages/posthog/src/client-config.test.ts@@ -2,28 +2,16 @@ import { describe, expect, it } from "vitest";import { getPostHogInitOptions } from "./client-config";describe("getPostHogInitOptions", () => {- it("runs cookieless when there is no identified user", () => {- const options = getPostHogInitOptions({});+ it("shares the anonymous id across subdomains", () => {+ const options = getPostHogInitOptions();- expect(options.cookieless_mode).toBe("always");- expect(options.bootstrap).toBeUndefined();- });-- it("bootstraps an identified user in memory without a cookie", () => {- const options = getPostHogInitOptions({ distinctId: "user_123" });-- expect(options.persistence).toBe("memory");- expect(options.bootstrap).toEqual({- distinctID: "user_123",- isIdentifiedID: true,- });+ expect(options.persistence).toBe("localStorage+cookie");+ expect(options.cross_subdomain_cookie).toBe(true);+ expect(options.cookieWinsOnConflict).toBe(true);expect(options.cookieless_mode).toBeUndefined();});it("never creates person profiles for anonymous ids", () => {- expect(getPostHogInitOptions({}).person_profiles).toBe("identified_only");- expect(- getPostHogInitOptions({ distinctId: "user_123" }).person_profiles,- ).toBe("identified_only");+ expect(getPostHogInitOptions().person_profiles).toBe("identified_only");});});diff --git a/packages/posthog/src/client-config.ts b/packages/posthog/src/client-config.tsindex 2b8f785bd..e2bce68c5 100644--- a/packages/posthog/src/client-config.ts+++ b/packages/posthog/src/client-config.ts@@ -1,39 +1,26 @@import type { PostHogConfig } from "posthog-js";/**- * Persistence and identity options for the browser client. Nothing is ever- * stored on the device, so no consent banner is needed under ePrivacy:+ * Persistence options for the browser client. The anonymous id lives in a+ * cookie scoped to the registrable domain, so a visitor keeps one id from+ * rallly.co through to app.rallly.co. When they sign in, initPostHog+ * identifies them, which merges that anonymous id (and every marketing+ * pageview on it) into their person.*- * - A logged-in user is bootstrapped as already identified. The first event- * carries their user id, so no anonymous id is minted and no merge runs β- * every anonymous id that gets merged would otherwise be appended to the- * person's distinct ids forever, one per page load.- * - Anyone else captures cookielessly: the client sends a sentinel id and the- * server substitutes a daily-rotating hash of IP+UA. Requires "Cookieless- * server hash mode" in PostHog project settings. identify() is unavailable- * in this mode, which is why the identified branch bootstraps at init- * instead of identifying after the fact.- *- * Person profiles stay identified-only in both branches. Never call- * posthog.group() from the browser: registering a group turns person- * processing on for whatever distinct id is current, identified or not,- * which is how cookieless visitors ended up with a fresh empty person per- * day. Group membership is attached server-side by track() and identifyGroup.+ * Person profiles stay identified-only: anonymous visitors never get a+ * person until they sign in. Never call posthog.group() from the browser:+ * registering a group turns person processing on for whatever distinct id is+ * current, identified or not, which mints an empty person per visitor. Group+ * membership is attached server-side by track() and identifyGroup.*/-export function getPostHogInitOptions({- distinctId,-}: {- distinctId?: string;-}): Partial<PostHogConfig> {- const identity: Partial<PostHogConfig> = distinctId- ? {- persistence: "memory",- bootstrap: { distinctID: distinctId, isIdentifiedID: true },- }- : { cookieless_mode: "always" };-+export function getPostHogInitOptions(): Partial<PostHogConfig> {return {person_profiles: "identified_only",- ...identity,+ persistence: "localStorage+cookie",+ cross_subdomain_cookie: true,+ // localStorage is per origin, so rallly.co and app.rallly.co each keep a+ // copy that goes stale when the other signs in or out. The shared cookie+ // is the one source both see.+ cookieWinsOnConflict: true,};}diff --git a/packages/posthog/src/client.ts b/packages/posthog/src/client.tsindex 7418c418b..77dba9557 100644--- a/packages/posthog/src/client.ts+++ b/packages/posthog/src/client.ts@@ -11,6 +11,30 @@ import {} from "./utils";let initialized = false;+let syncedDistinctId: string | null | undefined;++function syncIdentity(distinctId: string | null | undefined) {+ syncedDistinctId = distinctId;++ // Merges the persisted anonymous id into the user the first time they load+ // a page signed in. posthog-js only merges from an anonymous id, so a+ // browser still carrying another account's id is switched, not merged.+ if (distinctId && posthog.get_distinct_id() !== distinctId) {+ posthog.identify(distinctId);+ }++ // null means the page knows nobody is signed in. A session that expired or+ // was revoked never ran signOut(), so the persisted id still belongs to the+ // last account; drop it rather than attribute this visitor's events to+ // them. undefined (the landing site) cannot see the session, so it leaves+ // the id alone.+ if (+ distinctId === null &&+ posthog.get_property("$user_state") === "identified"+ ) {+ posthog.reset();+ }+}/*** Initialise the browser client once per page load. Idempotent and safe to@@ -18,9 +42,22 @@ let initialized = false;* effect captures an event or registers a group, and effects run child-first.* No-op on the server and when no key is configured.*/-export function initPostHog({ distinctId }: { distinctId?: string } = {}) {+export function initPostHog({+ distinctId,+}: {+ distinctId?: string | null;+} = {}) {const apiKey = process.env.NEXT_PUBLIC_POSTHOG_API_KEY;- if (initialized || typeof window === "undefined" || !apiKey) {+ if (typeof window === "undefined" || !apiKey) {+ return;+ }+ if (initialized) {+ // Re-sync only when the session actually changed (e.g. a refresh after+ // a failed session read). Re-running on every render would re-identify+ // the old user in the window between signOut()'s reset() and navigation.+ if (distinctId !== syncedDistinctId) {+ syncIdentity(distinctId);+ }return;}initialized = true;@@ -48,8 +85,10 @@ export function initPostHog({ distinctId }: { distinctId?: string } = {}) {}return event;},- ...getPostHogInitOptions({ distinctId }),+ ...getPostHogInitOptions(),});++ syncIdentity(distinctId);}/**@@ -57,19 +96,18 @@ export function initPostHog({ distinctId }: { distinctId?: string } = {}) {* descendant renders or runs an effect β a sibling placed earlier in the* tree is not enough once Suspense boundaries stream in out of order. Pass* the logged-in user's id so the session is identified from its first- * event; omit it for anonymous visitors and guests.+ * event, null where the page can see there is no logged-in user (anonymous+ * visitors and guests), and omit it where it cannot see the session at all.*- * Identity is fixed for the life of the document: a cookieless instance- * cannot identify later, and a bootstrapped one must not be re-pointed at- * another user. Sign-in flows therefore end in a full navigation, never a- * router.refresh(), and sign-out calls posthog.reset() so events after it- * are anonymous until the next document load.+ * Sign-in flows end in a full navigation so the next load identifies, and+ * sign-out calls posthog.reset() so the browser gets a fresh anonymous id.+ * A later render with a different id re-syncs the identity.*/export function PostHogInit({distinctId,children,}: {- distinctId?: string;+ distinctId?: string | null;children: React.ReactNode;}) {initPostHog({ distinctId });diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ece3960e4..3db6a7cfb 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -624,7 +624,7 @@ importers:version: link:../tsconfig'@react-email/ui':specifier: ^6.9.3- version: 6.9.3(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ version: 6.9.3(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])'@types/react':specifier: 19.2.13version: 19.2.13@@ -682,8 +682,8 @@ importers:specifier: ^3.0.1version: 3.0.5posthog-js:- specifier: ^1.407.2- version: 1.407.2+ specifier: ^1.434.11+ version: 1.434.11(@types/[email protected])([email protected])posthog-node:specifier: ^5.46.1version: 5.46.1([email protected])@@ -3989,18 +3989,24 @@ packages:'@polka/[email protected]':resolution: {integrity: sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==}- '@posthog/[email protected]':- resolution: {integrity: sha512-FTVPsRw6GBKWvFwN26TNIQNNYPR9FsUj+B+CKhk/ht63IRzn4yYFtFOjcmW+bfXvNHuRADs6APbZ6Haz1kpoAw==}+ '@posthog/[email protected]':+ resolution: {integrity: sha512-EWoVzs1vVY7ihpn8yOjj3jyjriHUEEMVSBNL/TW3hk09fTriWRe76vJXrRg0G0yjTYxHmtlSkNn4mOV24ZEzzA==}'@posthog/[email protected]':resolution: {integrity: sha512-tLtvzomavb2PPWdGYKsusyIzIeL2Px47v348Smibkay7sMy/83TyPk+Ptsp2NdeOgJsbuwSxWkR2+XA0aSCAaA==}+ '@posthog/[email protected]':+ resolution: {integrity: sha512-2mYxGbDmTLUs096VbcZqSWo0lrI48/BrX65r54NynxxFq409BOx9w73HxOAtOKZ1vblkdV6/GxQTe7KDcIQidg==}+'@posthog/[email protected]':resolution: {integrity: sha512-kjK0eFMIpKo9GXIbts8VtAknsoZ18oZorANdtuTj1CbgS28t4ZVq//HAWhnxEuXRTrtkd+SUJ6Ux3j2Af8NCuA==}'@posthog/[email protected]':resolution: {integrity: sha512-sJMkl4k+u8yS/0fjHsKqE9xTdsAh30a2WvgChiptellnVoE0e8QJKFgqOMD2sk8FaEArPdeFklAhXvmENAt3Sg==}+ '@posthog/[email protected]':+ resolution: {integrity: sha512-Q7lV9O9TbLngjOYw1ucm3bS3tn48xb1B4ZQdDy8gv7yfKe99hCTeWYG4xZ36nJM80VxpTF9TriiJt5hngDOkBg==}+'@prisma/[email protected]':resolution: {integrity: sha512-ygb3UkerK3v8MDpXVgCISdRNDozpxh6+JVJgiIGbSr5KBgz10LLf5ejUskPGoXlsIjxsOu6nuy1JVQr2EKGSlg==}@@ -8008,8 +8014,8 @@ packages:resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==}engines: {node: '>= 4'}- resolution: {integrity: sha512-Oj6pzI2+RqBfFG+qOaOLbFXLQ90ARpcGG6UePL82bJLtdsa6CYJD7nmiU8MW9nQNOtCHV3lZ/Bzq1X0QYbBZCA==}+ resolution: {integrity: sha512-sqo+pNp3qRhCIpbgRi1y8Tgk27Bo2Ry7w0dC1NBeNTdZChWjz9Xb/KOoZbRP/R6pQZ80Qw8YhXw13hWWBbMRnQ==}resolution: {integrity: sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==}@@ -10663,8 +10669,16 @@ packages:resolution: {integrity: sha512-Jtc2612XINuBjIl/QTWsV5UvE8UHuNblcO3vVADSrKsrc6RqGX6lOW1cEo3CM2v0XG4Nat8nI+YM7/f26VxXLw==}engines: {node: '>=12'}- resolution: {integrity: sha512-5deTvXopn+NJWEmCUw8Ix/ms3cv2+60WJ73Vgbvu2wSkZY/FIj2uqAgCnq7IewGpGC+tH7CAbPYFzH6hw8eW1w==}+ resolution: {integrity: sha512-B5DPg/SZaMEqsJIqX7lVkcH3orFFTk8Ok8q17fYYB8WS1rlzuoSqj5RD8v3JLIL+U9WDBZfzpY6XY9LvnJD1Yg==}+ peerDependencies:+ '@types/react': '>=16.8.0'+ react: '>=16.8.0'+ peerDependenciesMeta:+ '@types/react':+ optional: true+ react:+ optional: trueresolution: {integrity: sha512-lz3YJOr0Nmiz0yHASaINEDHqoV+0bC3eD8aZAG+Ky292dAnVYul+ga/dMX8KCBXg8hHfKdxw0SztYD5j6dgUqQ==}@@ -12409,8 +12423,11 @@ packages:resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==}engines: {node: '>= 8'}- resolution: {integrity: sha512-q6LWsLatGYZp5VGBIOvbTj6JBV2nOmC8KvWztXBmwJcfFAzhwKwbOxhUH306XY3CcaZDUlSmSuNPBsCn0bFu+g==}+ resolution: {integrity: sha512-rLcLXA2sx6+9dE88NHFubwTtGxpK4yYBLj6qHPdFoCaLr0cXGb4efOqtKLlm4loGA4OEKHIQKMKzZkKyOh5ctw==}++ resolution: {integrity: sha512-oto5x6dLEgrRqfcWed+pZEUb2q6ikbFmqF54CRDhI/QGbn+qxC49b4C4OkbH+kb9C3a8shpFD3SgR9kRcs80ZQ==}resolution: {integrity: sha512-P+x1MvlNCXlKbLSOY4cYrdreqPG5hbzkmawbcXLKN/mf6DZW0SdNNkZ+sjwsqVkI4A4Ko2sPZmkZtCKY58w83A==}@@ -16395,21 +16412,27 @@ snapshots:'@polka/[email protected]': {}- '@posthog/[email protected]':+ '@posthog/[email protected]':dependencies:- '@posthog/core': 1.45.1- '@posthog/types': 1.398.0+ '@posthog/core': 1.55.2+ '@posthog/types': 1.412.4'@posthog/[email protected]':dependencies:'@posthog/types': 1.398.0+ '@posthog/[email protected]':+ dependencies:+ '@posthog/types': 1.412.4+'@posthog/[email protected]':dependencies:cross-spawn: 7.0.6'@posthog/[email protected]': {}+ '@posthog/[email protected]': {}+'@prisma/[email protected]':dependencies:'@prisma/driver-adapter-utils': 7.8.0@@ -17476,10 +17499,10 @@ snapshots:dependencies:react: 19.2.6- '@react-email/[email protected](@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ '@react-email/[email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:esbuild: 0.28.1- next: 16.3.3(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ next: 16.3.3(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])transitivePeerDependencies:- '@babel/core'- '@opentelemetry/api'@@ -21001,7 +21024,7 @@ snapshots:dependencies:domelementtype: 2.3.0optionalDependencies:'@types/trusted-types': 2.0.7@@ -23923,7 +23946,7 @@ snapshots:- '@types/node'- babel-plugin-macros- [email protected](@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected]):+ [email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected]):dependencies:'@next/env': 16.3.3'@swc/helpers': 0.5.23@@ -24472,17 +24495,21 @@ snapshots:dependencies:- '@posthog/browser-common': 0.2.1- '@posthog/core': 1.45.1- '@posthog/types': 1.398.0+ '@posthog/browser-common': 0.9.0+ '@posthog/core': 1.55.2+ '@posthog/types': 1.412.4core-js: 3.49.0- dompurify: 3.3.3+ dompurify: 3.4.16fflate: 0.4.8preact: 10.29.7query-selector-shadow-dom: 1.0.1- web-vitals: 5.3.0+ web-vitals: 6.2.2+ web-vitals-soft-navs: [email protected]+ optionalDependencies:+ '@types/react': 19.2.13+ react: 19.2.6transitivePeerDependencies:- preact-render-to-string@@ -26817,7 +26844,9 @@ snapshots:- [email protected]: {}+ [email protected]: {}++ [email protected]: {}dependencies: