Skip to content

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

🐛 Stop firing $groupidentify on every dashboard page load (#2785)

Luke Vellaa06ca236a099
diff --git a/apps/web/src/features/space/actions.ts b/apps/web/src/features/space/actions.ts
index 072d6937b..97ebe8e79 100644
--- a/apps/web/src/features/space/actions.ts
+++ b/apps/web/src/features/space/actions.ts
@@ -178,6 +178,16 @@ export const updateSpaceAction = authActionClient
primaryColor: parsedInput.primaryColor,
});
+ if (parsedInput.name) {
+ identifyGroup({
+ groupType: "space",
+ groupKey: space.id,
+ properties: {
+ name: parsedInput.name,
+ },
+ });
+ }
+
track(ctx.user, {
event: "space_update",
properties: {
diff --git a/apps/web/src/features/space/client.tsx b/apps/web/src/features/space/client.tsx
index 084f77d6f..95ed66299 100644
--- a/apps/web/src/features/space/client.tsx
+++ b/apps/web/src/features/space/client.tsx
@@ -44,23 +44,13 @@ export function SpaceProvider({
children: React.ReactNode;
}) {
React.useEffect(() => {
- // Property names must match the server-side identifyGroup payloads.
- // posthog-js only re-sends $groupidentify when these values change.
- posthog?.group("space", space.id, {
- name: space.name,
- tier: space.tier,
- custom_branding: space.showBranding,
- member_count: space.memberCount,
- seat_count: space.seatCount,
- });
- }, [
- space.id,
- space.name,
- space.tier,
- space.showBranding,
- space.memberCount,
- space.seatCount,
- ]);
+ // No properties here — posthog-js captures $groupidentify on EVERY
+ // group() call that passes properties (no diffing), which fired one
+ // event per page load. Without properties it only fires when the
+ // group key changes. Group properties are maintained by the
+ // server-side identifyGroup calls on the mutations that change them.
+ posthog?.group("space", space.id);
+ }, [space.id]);
const primaryColorVars =
space.showBranding && space.primaryColor
diff --git a/apps/web/src/features/space/member/actions.ts b/apps/web/src/features/space/member/actions.ts
index 11da1e719..34b91efdb 100644
--- a/apps/web/src/features/space/member/actions.ts
+++ b/apps/web/src/features/space/member/actions.ts
@@ -20,7 +20,7 @@ import {
removeMemberSchema,
} from "@/features/space/member/schema";
import { AppError } from "@/lib/errors/app-error";
-import { track } from "@/lib/posthog";
+import { identifyGroup, track } from "@/lib/posthog";
import { authActionClient } from "@/lib/safe-action/server";
async function requireActiveSpace(user: { id: string }) {
@@ -97,6 +97,14 @@ export const acceptInviteAction = authActionClient
});
if (result.ok) {
+ identifyGroup({
+ groupType: "space",
+ groupKey: parsedInput.spaceId,
+ properties: {
+ member_count: result.memberCount,
+ },
+ });
+
track(ctx.user, {
event: "space_member_join",
properties: {
@@ -173,6 +181,14 @@ export const removeMemberAction = authActionClient
memberId: parsedInput.memberId,
});
+ identifyGroup({
+ groupType: "space",
+ groupKey: member.spaceId,
+ properties: {
+ member_count: memberCount,
+ },
+ });
+
track(ctx.user, {
event: "space_member_remove",
properties: {
diff --git a/apps/web/src/trpc/routers/spaces.ts b/apps/web/src/trpc/routers/spaces.ts
index 7ee1ef583..26aa0bfcf 100644
--- a/apps/web/src/trpc/routers/spaces.ts
+++ b/apps/web/src/trpc/routers/spaces.ts
@@ -5,7 +5,7 @@ import { createSpaceDTO } from "@/features/space/data";
import { effectiveSpaceMemberWhere } from "@/features/space/member/utils";
import type { SpaceDTO } from "@/features/space/types";
import { fromDBRole } from "@/features/space/utils";
-import { track } from "@/lib/posthog";
+import { identifyGroup, track } from "@/lib/posthog";
import { privateProcedure, router, spaceProcedure } from "../trpc";
export const spaces = router({
@@ -172,6 +172,14 @@ export const spaces = router({
where: { spaceId: ctx.space.id },
});
+ identifyGroup({
+ groupType: "space",
+ groupKey: ctx.space.id,
+ properties: {
+ member_count: memberCount,
+ },
+ });
+
track(ctx.user, {
event: "space_member_leave",
properties: {
@@ -250,6 +258,14 @@ export const spaces = router({
where: { spaceId: input.spaceId },
});
+ identifyGroup({
+ groupType: "space",
+ groupKey: input.spaceId,
+ properties: {
+ member_count: memberCount,
+ },
+ });
+
track(ctx.user, {
event: "space_member_leave",
properties: {