Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

πŸ“ˆ Attribute signups to the originating landing page (#3133)

Luke Vella2ab2cb91e1b6
diff --git a/apps/landing/src/app/[locale]/(main)/mobile-menu.tsx b/apps/landing/src/app/[locale]/(main)/mobile-menu.tsx
index b57f1e194..bd48cbd1d 100644
--- a/apps/landing/src/app/[locale]/(main)/mobile-menu.tsx
+++ b/apps/landing/src/app/[locale]/(main)/mobile-menu.tsx
@@ -8,6 +8,7 @@ import React from "react";
import { CtaButton } from "@/components/home/cta-button";
import { LinkBase } from "@/i18n/client/link";
import { linkToApp } from "@/lib/linkToApp";
+import { getRefSlug } from "@/lib/ref-slug";
const PANEL_ID = "mobile-menu-panel";
// Matches the `lg:hidden` on the panel below. Tailwind's default `lg`.
@@ -113,7 +114,7 @@ export const MobileMenu = ({
</nav>
<div className="flex flex-col gap-3 border-t px-4 py-6 sm:px-6">
<LinkBase
- href={linkToApp("/login")}
+ href={linkToApp("/login", { ref: getRefSlug(pathname) })}
className={buttonVariants({
variant: "default",
size: "lg",
diff --git a/apps/landing/src/app/[locale]/(main)/pricing/page.tsx b/apps/landing/src/app/[locale]/(main)/pricing/page.tsx
index 3e7697dc2..f44627ef7 100644
--- a/apps/landing/src/app/[locale]/(main)/pricing/page.tsx
+++ b/apps/landing/src/app/[locale]/(main)/pricing/page.tsx
@@ -164,7 +164,7 @@ export default async function Page(props: {
</PlanCardPrice>
<div>
<Link
- href={linkToApp("/")}
+ href={linkToApp("/", { ref: "pricing" })}
className={buttonVariants({
className: "w-full",
})}
@@ -270,7 +270,7 @@ export default async function Page(props: {
</PlanCardPrice>
<div>
<Link
- href={linkToApp("/settings/billing")}
+ href={linkToApp("/settings/billing", { ref: "pricing" })}
className={buttonVariants({
variant: "primary",
className: "w-full",
@@ -782,7 +782,9 @@ export default async function Page(props: {
a: (
<Link
className={faqLinkClassName}
- href={linkToApp("/settings/billing")}
+ href={linkToApp("/settings/billing", {
+ ref: "pricing",
+ })}
/>
),
b: <strong />,
@@ -808,7 +810,9 @@ export default async function Page(props: {
a: (
<Link
className={faqLinkClassName}
- href={linkToApp("/settings/billing")}
+ href={linkToApp("/settings/billing", {
+ ref: "pricing",
+ })}
/>
),
b: <strong />,
diff --git a/apps/landing/src/components/home/cta-button.tsx b/apps/landing/src/components/home/cta-button.tsx
index d5ad2f7b2..d14ee6c91 100644
--- a/apps/landing/src/components/home/cta-button.tsx
+++ b/apps/landing/src/components/home/cta-button.tsx
@@ -4,6 +4,7 @@ import { buttonVariants, cn } from "@rallly/ui";
import Link from "next/link";
import type React from "react";
import { linkToApp } from "@/lib/linkToApp";
+import { useRefSlug } from "@/lib/use-ref-slug";
export function CtaButton({
captureEvent,
@@ -16,9 +17,10 @@ export function CtaButton({
className?: string;
children: React.ReactNode;
}) {
+ const ref = useRefSlug();
return (
<Link
- href={linkToApp("/new")}
+ href={linkToApp("/new", { ref })}
className={buttonVariants({
size,
variant: "primary",
diff --git a/apps/landing/src/components/home/hero-demo/vote-actions.tsx b/apps/landing/src/components/home/hero-demo/vote-actions.tsx
index 222314d20..9b33f4227 100644
--- a/apps/landing/src/components/home/hero-demo/vote-actions.tsx
+++ b/apps/landing/src/components/home/hero-demo/vote-actions.tsx
@@ -7,12 +7,14 @@ import * as React from "react";
import { Trans } from "@/i18n/client/trans";
import { useTranslation } from "@/i18n/client/use-translation";
import { linkToApp } from "@/lib/linkToApp";
+import { useRefSlug } from "@/lib/use-ref-slug";
// The action bar of the phone demo, plus the confirmation it opens. The
// surrounding poll layout stays on the server. Must be a direct child of the
// relative DemoScreen so the confirmation overlay covers the whole screen.
export const VoteActions = () => {
const { t } = useTranslation("home");
+ const ref = useRefSlug();
const [submitted, setSubmitted] = React.useState(false);
return (
@@ -108,7 +110,7 @@ export const VoteActions = () => {
className="mt-4"
>
<Link
- href={linkToApp("/new")}
+ href={linkToApp("/new", { ref })}
onClick={() => {
posthog?.capture("landing:hero_demo_modal_cta_click");
}}
diff --git a/apps/landing/src/components/login-button.tsx b/apps/landing/src/components/login-button.tsx
index d06188a04..54e802296 100644
--- a/apps/landing/src/components/login-button.tsx
+++ b/apps/landing/src/components/login-button.tsx
@@ -4,11 +4,13 @@ import { buttonVariants } from "@rallly/ui";
import Link from "next/link";
import { Trans } from "@/i18n/client/trans";
import { linkToApp } from "@/lib/linkToApp";
+import { useRefSlug } from "@/lib/use-ref-slug";
export const LoginButton = () => {
+ const ref = useRefSlug();
return (
<Link
- href={linkToApp("/login")}
+ href={linkToApp("/login", { ref })}
className={buttonVariants({ variant: "ghost" })}
>
<Trans i18nKey="login" defaults="Login" />
diff --git a/apps/landing/src/lib/linkToApp.ts b/apps/landing/src/lib/linkToApp.ts
index a02e0386c..6e9d53ef9 100644
--- a/apps/landing/src/lib/linkToApp.ts
+++ b/apps/landing/src/lib/linkToApp.ts
@@ -1,4 +1,7 @@
-export const linkToApp = (path = "") => {
+export const linkToApp = (path = "", options?: { ref?: string }) => {
const url = new URL(path, process.env.NEXT_PUBLIC_APP_BASE_URL);
+ if (options?.ref) {
+ url.searchParams.set("ref", options.ref);
+ }
return url.href;
};
diff --git a/apps/landing/src/lib/ref-slug.ts b/apps/landing/src/lib/ref-slug.ts
new file mode 100644
index 000000000..e6418ac52
--- /dev/null
+++ b/apps/landing/src/lib/ref-slug.ts
@@ -0,0 +1,16 @@
+import { languages } from "@/i18n/settings";
+
+// Cross-domain referrers don't survive the hop from rallly.co to the app, so
+// CTA links carry the originating page as a ?ref=<slug> query param instead.
+// The slug is always a locale-independent page path β€” never personal data.
+export function getRefSlug(pathname: string) {
+ let path = pathname;
+ const locale = languages.find(
+ (lng) => path === `/${lng}` || path.startsWith(`/${lng}/`),
+ );
+ if (locale) {
+ path = path.slice(locale.length + 1) || "/";
+ }
+ const slug = path.replace(/^\/+|\/+$/g, "");
+ return slug === "" ? "home" : slug;
+}
diff --git a/apps/landing/src/lib/use-ref-slug.ts b/apps/landing/src/lib/use-ref-slug.ts
new file mode 100644
index 000000000..d411dbd45
--- /dev/null
+++ b/apps/landing/src/lib/use-ref-slug.ts
@@ -0,0 +1,8 @@
+"use client";
+
+import { usePathname } from "next/navigation";
+import { getRefSlug } from "@/lib/ref-slug";
+
+export function useRefSlug() {
+ return getRefSlug(usePathname());
+}
diff --git a/apps/web/src/lib/acquisition.ts b/apps/web/src/lib/acquisition.ts
new file mode 100644
index 000000000..694e04110
--- /dev/null
+++ b/apps/web/src/lib/acquisition.ts
@@ -0,0 +1,34 @@
+import type { NextRequest, NextResponse } from "next/server";
+
+// Landing CTAs append ?ref=<page-slug> because cross-domain referrers don't
+// survive the hop from rallly.co to the app. The proxy persists the slug in a
+// cookie so it is still available when registration completes requests later
+// (signup spans redirects and, for OAuth, a round trip to the provider).
+export const REF_COOKIE_NAME = "rallly_ref";
+
+const REF_COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
+
+// Page slugs only (e.g. "home", "blog/is-doodle-still-free") β€” the param is
+// visitor-controlled, so reject anything else before it reaches analytics.
+const REF_PATTERN = /^[a-z0-9][a-z0-9/_-]{0,63}$/;
+
+export function parseRefParam(value: string | null | undefined) {
+ if (!value || !REF_PATTERN.test(value)) {
+ return undefined;
+ }
+ return value;
+}
+
+export function setRefCookie(req: NextRequest, res: NextResponse) {
+ const ref = parseRefParam(req.nextUrl.searchParams.get("ref"));
+ if (!ref) {
+ return;
+ }
+ res.cookies.set(REF_COOKIE_NAME, ref, {
+ httpOnly: true,
+ sameSite: "lax",
+ path: "/",
+ secure: req.nextUrl.protocol === "https:",
+ maxAge: REF_COOKIE_MAX_AGE,
+ });
+}
diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts
index 3432b1927..63443cfee 100644
--- a/apps/web/src/lib/auth.ts
+++ b/apps/web/src/lib/auth.ts
@@ -31,6 +31,7 @@ import type { UserDTO } from "@/features/user/schema";
import { jobTitleFieldSchema } from "@/features/user/schema";
import { getTranslation } from "@/i18n/server";
import { getLocale } from "@/i18n/server/get-locale";
+import { parseRefParam, REF_COOKIE_NAME } from "@/lib/acquisition";
import { SESSION_TTL_SECONDS } from "@/lib/auth-config";
import { hostOnlyCookieCleanup } from "@/lib/auth-plugins/host-only-cookie-cleanup";
import { redis } from "@/lib/kv";
@@ -479,10 +480,11 @@ export const authLib = betterAuth({
databaseHooks: {
user: {
create: {
- after: async (user) => {
+ after: async (user, ctx) => {
if (user.isAnonymous) {
return;
}
+ const ref = parseRefParam(ctx?.getCookie(REF_COOKIE_NAME));
// No space is created here β€” /setup owns space creation, and the
// active-space gate keeps redirecting there until it happens.
track(
@@ -491,6 +493,7 @@ export const authLib = betterAuth({
event: "register",
properties: {
method: user.lastLoginMethod,
+ ref,
$set: {
name: user.name,
email: user.email,
@@ -498,6 +501,7 @@ export const authLib = betterAuth({
timeZone: user.timeZone ?? undefined,
locale: user.locale ?? undefined,
},
+ ...(ref && { $set_once: { initial_ref: ref } }),
},
},
);
diff --git a/apps/web/src/proxy.ts b/apps/web/src/proxy.ts
index aea665243..a8770284d 100644
--- a/apps/web/src/proxy.ts
+++ b/apps/web/src/proxy.ts
@@ -1,5 +1,6 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
+import { setRefCookie } from "@/lib/acquisition";
import { getLocaleFromRequest, setLocaleCookie } from "@/lib/locale/server";
import {
hashBypassToken,
@@ -66,6 +67,8 @@ export const proxy = async (req: NextRequest) => {
setLocaleCookie(req, res, locale);
+ setRefCookie(req, res);
+
res.headers.set("x-locale", locale);
setPathname(req, res);