Skip to content

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

📈 Instrument the paywall funnel with trigger context (#2818)

Luke Vellaf401d8a3bb9b
diff --git a/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx b/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx
index 3475340f2..14323da1d 100644
--- a/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx
+++ b/apps/web/src/app/[locale]/(space)/(dashboard)/components/upgrade-menu-item.tsx
@@ -1,6 +1,5 @@
"use client";
-import { posthog } from "@rallly/posthog/client";
import { SidebarMenuButton, SidebarMenuItem } from "@rallly/ui/sidebar";
import { SparklesIcon } from "lucide-react";
import { showPayWall, useIsFree } from "@/features/billing/client";
@@ -18,8 +17,7 @@ export function UpgradeMenuItem() {
<SidebarMenuButton
variant="primary"
onClick={() => {
- posthog?.capture("space_sidebar:upgrade_button_click");
- showPayWall();
+ showPayWall({ from: "sidebar" });
}}
>
<SparklesIcon />
diff --git a/apps/web/src/app/[locale]/(space)/settings/api-keys/components/api-access-upgrade.tsx b/apps/web/src/app/[locale]/(space)/settings/api-keys/components/api-access-upgrade.tsx
index 77b675040..5091e2fb6 100644
--- a/apps/web/src/app/[locale]/(space)/settings/api-keys/components/api-access-upgrade.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/api-keys/components/api-access-upgrade.tsx
@@ -1,6 +1,5 @@
"use client";
-import { posthog } from "@rallly/posthog/client";
import { Button } from "@rallly/ui/button";
import { TerminalIcon } from "lucide-react";
import {
@@ -37,8 +36,7 @@ export function ApiAccessUpgrade() {
<Button
variant="primary"
onClick={() => {
- posthog?.capture("api_keys:upgrade_button_click");
- showPayWall();
+ showPayWall({ from: "api-keys" });
}}
>
<Trans i18nKey="upgradeToPro" defaults="Upgrade to Pro" />
diff --git a/apps/web/src/app/[locale]/(space)/settings/billing/components/hobby-plan-card.tsx b/apps/web/src/app/[locale]/(space)/settings/billing/components/hobby-plan-card.tsx
index 90518bfd6..fd5a89a27 100644
--- a/apps/web/src/app/[locale]/(space)/settings/billing/components/hobby-plan-card.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/billing/components/hobby-plan-card.tsx
@@ -1,6 +1,5 @@
"use client";
-import { posthog } from "@rallly/posthog/client";
import { Button } from "@rallly/ui/button";
import { showPayWall } from "@/features/billing/client";
import {
@@ -49,8 +48,7 @@ export function HobbyPlanCard({ className }: { className?: string }) {
<Button
variant="primary"
onClick={() => {
- showPayWall();
- posthog?.capture("space_billing:upgrade_button_click");
+ showPayWall({ from: "billing-settings" });
}}
>
<Trans i18nKey="upgradeToPro" defaults="Upgrade to Pro" />
diff --git a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
index 9db9d19ac..7f2c173c7 100644
--- a/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/general/components/custom-branding-section.tsx
@@ -1,6 +1,5 @@
"use client";
-import { posthog } from "@rallly/posthog/client";
import { Button } from "@rallly/ui/button";
import { ColorPicker, parseColor } from "@rallly/ui/color-picker";
import { Field, FieldGroup, FieldLabel } from "@rallly/ui/field";
@@ -60,8 +59,7 @@ export function CustomBrandingSection({
const handleToggle = async (newChecked: boolean) => {
if (isFree) {
- posthog?.capture("branding_settings:paywall_trigger");
- showPayWall();
+ showPayWall({ from: "custom-branding" });
return;
}
diff --git a/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx b/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx
index dd70f4d6c..cbd2fbf78 100644
--- a/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/members/components/invite-member-button.tsx
@@ -33,7 +33,7 @@ export function InviteMemberButton({
}),
);
} else if (space.getAbility().cannot("invite", "Member")) {
- showPayWall();
+ showPayWall({ from: "space-members", action: "invite" });
} else {
inviteMemberDialog.trigger();
}
diff --git a/apps/web/src/app/[locale]/(space)/settings/members/page-client.tsx b/apps/web/src/app/[locale]/(space)/settings/members/page-client.tsx
index d65e12fd4..a8d49952a 100644
--- a/apps/web/src/app/[locale]/(space)/settings/members/page-client.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/members/page-client.tsx
@@ -1,6 +1,5 @@
"use client";
-import { posthog } from "@rallly/posthog/client";
import {
Alert,
AlertAction,
@@ -90,10 +89,10 @@ export function MembersSettingsPageClient({
<Button
size="sm"
onClick={() => {
- posthog?.capture(
- "members_settings:upgrade_button_click",
- );
- showPayWall();
+ showPayWall({
+ from: "space-members",
+ action: "reactivate",
+ });
}}
>
<Trans
@@ -166,8 +165,7 @@ export function MembersSettingsPageClient({
size="sm"
variant="link"
onClick={() => {
- posthog?.capture("members_settings:upgrade_button_click");
- showPayWall();
+ showPayWall({ from: "space-members", action: "invite" });
}}
>
<Trans i18nKey="upgradeToPro" defaults="Upgrade to Pro" />
diff --git a/apps/web/src/features/billing/actions.ts b/apps/web/src/features/billing/actions.ts
index 137cc302c..f50e2af85 100644
--- a/apps/web/src/features/billing/actions.ts
+++ b/apps/web/src/features/billing/actions.ts
@@ -13,6 +13,7 @@ import type {
import { getStripe } from "@/features/billing/service";
import { getActiveSpaceForUser } from "@/features/space/data";
import { AppError } from "@/lib/errors/app-error";
+import { track } from "@/lib/posthog";
import { authActionClient } from "@/lib/safe-action/server";
import { validateRedirectUrl } from "@/lib/utils/redirect";
@@ -151,6 +152,16 @@ export const upgradeToProAction = authActionClient
});
}
+ track(ctx.user, {
+ event: "billing:checkout_start",
+ properties: {
+ interval: period === "yearly" ? "year" : "month",
+ },
+ groups: {
+ space: space.id,
+ },
+ });
+
redirect(checkoutSession.url);
});
diff --git a/apps/web/src/features/billing/client.tsx b/apps/web/src/features/billing/client.tsx
index aac0dddbe..27ea13820 100644
--- a/apps/web/src/features/billing/client.tsx
+++ b/apps/web/src/features/billing/client.tsx
@@ -1,5 +1,6 @@
"use client";
+import { posthog } from "@rallly/posthog/client";
import { create } from "zustand";
import type { SpaceTier } from "@/features/space/schema";
import { trpc } from "@/trpc/client";
@@ -14,16 +15,41 @@ export function useIsFree() {
return useTier() === "hobby";
}
+export type PayWallTrigger = {
+ from:
+ | "poll-settings"
+ | "manage-poll"
+ | "custom-branding"
+ | "api-keys"
+ | "space-members"
+ | "billing-settings"
+ | "sidebar";
+ setting?: string;
+ action?: string;
+ pollId?: string;
+};
+
type PayWallStore = {
isOpen: boolean;
- show: () => void;
+ trigger: PayWallTrigger | null;
+ show: (trigger: PayWallTrigger) => void;
hide: () => void;
};
export const usePayWallStore = create<PayWallStore>((set) => ({
isOpen: false,
- show: () => set({ isOpen: true }),
+ trigger: null,
+ show: (trigger) => {
+ posthog?.capture("trigger paywall", {
+ from: trigger.from,
+ setting: trigger.setting,
+ action: trigger.action,
+ poll_id: trigger.pollId,
+ });
+ set({ isOpen: true, trigger });
+ },
hide: () => set({ isOpen: false }),
}));
-export const showPayWall = () => usePayWallStore.getState().show();
+export const showPayWall = (trigger: PayWallTrigger) =>
+ usePayWallStore.getState().show(trigger);
diff --git a/apps/web/src/features/billing/components/pay-wall-dialog.tsx b/apps/web/src/features/billing/components/pay-wall-dialog.tsx
index 838cc6d5c..1bb73f77c 100644
--- a/apps/web/src/features/billing/components/pay-wall-dialog.tsx
+++ b/apps/web/src/features/billing/components/pay-wall-dialog.tsx
@@ -1,6 +1,7 @@
"use client";
import { pricingData } from "@rallly/billing/pricing";
+import { posthog } from "@rallly/posthog/client";
import { Button } from "@rallly/ui/button";
import {
Dialog,
@@ -33,6 +34,7 @@ import { UpgradeButton } from "@/features/billing/components/upgrade-button";
import type { SpaceTier } from "@/features/space/schema";
import { spaceTierSchema } from "@/features/space/schema";
import { Trans } from "@/i18n/client";
+import { usePayWallStore } from "../client";
import { PLAN_NAMES } from "../constants";
function KeyBenefits({ children }: { children?: React.ReactNode }) {
@@ -117,6 +119,7 @@ export function PayWallDialog({
}) {
const [selectedPlan, setSelectedPlan] = React.useState<SpaceTier>("pro");
const [isAnnual, setIsAnnual] = React.useState(false);
+ const trigger = usePayWallStore((state) => state.trigger);
const handleChangePlan = (value: string) => {
setSelectedPlan(spaceTierSchema.parse(value));
@@ -234,7 +237,20 @@ export function PayWallDialog({
)}
{selectedPlan === "pro" ? (
<TabsContent value="pro">
- <UpgradeButton className="w-full" annual={isAnnual}>
+ <UpgradeButton
+ className="w-full"
+ annual={isAnnual}
+ onClick={() => {
+ posthog?.capture("paywall:upgrade_button_click", {
+ from: trigger?.from,
+ setting: trigger?.setting,
+ action: trigger?.action,
+ poll_id: trigger?.pollId,
+ plan: selectedPlan,
+ interval: isAnnual ? "year" : "month",
+ });
+ }}
+ >
<Trans i18nKey="upgrade" defaults="Upgrade" />
</UpgradeButton>
</TabsContent>
diff --git a/apps/web/src/features/billing/components/upgrade-button.tsx b/apps/web/src/features/billing/components/upgrade-button.tsx
index dc9aaf296..2f10e94f4 100644
--- a/apps/web/src/features/billing/components/upgrade-button.tsx
+++ b/apps/web/src/features/billing/components/upgrade-button.tsx
@@ -12,9 +12,11 @@ export const UpgradeButton = ({
children,
annual,
className,
+ onClick,
}: React.PropsWithChildren<{
annual?: boolean;
className?: string;
+ onClick?: () => void;
}>) => {
const pathname = usePathname();
const router = useRouter();
@@ -29,6 +31,7 @@ export const UpgradeButton = ({
variant="primary"
loading={upgradeToPro.isExecuting}
onClick={() => {
+ onClick?.();
if (!user || user.isGuest) {
router.push(`/register?redirectTo=${encodeURIComponent(pathname)}`);
return;
diff --git a/apps/web/src/features/poll/components/forms/poll-settings.tsx b/apps/web/src/features/poll/components/forms/poll-settings.tsx
index a890dd5b4..568a86321 100644
--- a/apps/web/src/features/poll/components/forms/poll-settings.tsx
+++ b/apps/web/src/features/poll/components/forms/poll-settings.tsx
@@ -63,11 +63,7 @@ const PollSetting = ({
checked={!!field.value}
onCheckedChange={(checked) => {
if (checked && pro && isFree) {
- showPayWall();
- posthog?.capture("trigger paywall", {
- setting: name,
- from: "poll-settings",
- });
+ showPayWall({ from: "poll-settings", setting: name });
} else {
field.onChange(checked);
if (name === "disableComments") {
diff --git a/apps/web/src/features/poll/components/manage-poll.tsx b/apps/web/src/features/poll/components/manage-poll.tsx
index bc4a8733c..2e68dc6d6 100644
--- a/apps/web/src/features/poll/components/manage-poll.tsx
+++ b/apps/web/src/features/poll/components/manage-poll.tsx
@@ -1,4 +1,3 @@
-import { posthog } from "@rallly/posthog/client";
import { Button } from "@rallly/ui/button";
import { useDialog } from "@rallly/ui/dialog";
import {
@@ -157,11 +156,10 @@ const ManagePoll: React.FunctionComponent<{
disabled={!!poll.event}
onClick={() => {
if (isFree) {
- showPayWall();
- posthog?.capture("trigger paywall", {
- poll_id: poll.id,
+ showPayWall({
from: "manage-poll",
action: "schedule",
+ pollId: poll.id,
});
} else {
scheduleDialog.trigger();
@@ -183,11 +181,10 @@ const ManagePoll: React.FunctionComponent<{
<DropdownMenuItem
onClick={() => {
if (isFree) {
- showPayWall();
- posthog?.capture("trigger paywall", {
- poll_id: poll.id,
- action: "duplicate",
+ showPayWall({
from: "manage-poll",
+ action: "duplicate",
+ pollId: poll.id,
});
} else {
duplicateDialog.trigger();