Skip to content

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

πŸ› Use a shared distinct id for group identify events (#2681)

Luke Vella6dd09f0f0bc2
diff --git a/apps/web/src/features/billing/webhook/mutations.ts b/apps/web/src/features/billing/webhook/mutations.ts
index 663086ff8..3de202ac7 100644
--- a/apps/web/src/features/billing/webhook/mutations.ts
+++ b/apps/web/src/features/billing/webhook/mutations.ts
@@ -21,7 +21,7 @@ import {
} from "@/features/billing/webhook/utils";
import { licenseManager } from "@/features/licensing/mutations";
import { licenseCheckoutMetadataSchema } from "@/features/licensing/schema";
-import { posthog } from "@/lib/posthog";
+import { identifyGroup, posthog } from "@/lib/posthog";
async function getExpandedSubscription(subscriptionId: string) {
return stripe.subscriptions.retrieve(subscriptionId, {
@@ -281,7 +281,7 @@ async function onCustomerSubscriptionCreated(event: Stripe.Event) {
return syncSpaceTier(tx, spaceId);
});
- posthog()?.groupIdentify({
+ identifyGroup({
groupType: "space",
groupKey: spaceId,
properties: {
@@ -368,7 +368,7 @@ async function onCustomerSubscriptionDeleted(event: Stripe.Event) {
return syncSpaceTier(tx, spaceId);
});
- posthog()?.groupIdentify({
+ identifyGroup({
groupType: "space",
groupKey: spaceId,
properties: {
@@ -461,7 +461,7 @@ async function onCustomerSubscriptionUpdated(event: Stripe.Event) {
return syncSpaceTier(tx, spaceId);
});
- posthog()?.groupIdentify({
+ identifyGroup({
groupType: "space",
groupKey: spaceId,
properties: {
diff --git a/apps/web/src/lib/posthog.ts b/apps/web/src/lib/posthog.ts
index de8412656..324cdc851 100644
--- a/apps/web/src/lib/posthog.ts
+++ b/apps/web/src/lib/posthog.ts
@@ -78,16 +78,27 @@ export function getClientAnonymousDistinctId(req: NextRequest) {
return parsePostHogCookieDistinctId(cookie?.value) ?? undefined;
}
+// Without an explicit distinctId, groupIdentify defaults to
+// $<groupType>_<groupKey>, creating a dummy person profile per group
+// (PostHog/posthog#7921). A single shared id caps the junk at one person.
+// Sending the event personless is not an option β€” ingestion only applies
+// $group_set when person processing is enabled.
+const GROUP_IDENTIFY_DISTINCT_ID = "server_group_identify";
+
/**
- * Update properties on a group (e.g. poll, space). Groups are independent
- * of person profiles, so no guest handling is involved.
+ * Update properties on a group (e.g. poll, space). Group identify events are
+ * not attributed to the acting user β€” actor attribution belongs on the
+ * accompanying track() event.
*/
export function identifyGroup(group: {
groupType: string;
groupKey: string;
properties?: Record<string, unknown>;
}) {
- posthog()?.groupIdentify(group);
+ posthog()?.groupIdentify({
+ ...group,
+ distinctId: GROUP_IDENTIFY_DISTINCT_ID,
+ });
}
export function withPostHog(
diff --git a/packages/posthog/src/scripts/backfill-space-group-properties.ts b/packages/posthog/src/scripts/backfill-space-group-properties.ts
index 8785e95cd..d355c3e30 100644
--- a/packages/posthog/src/scripts/backfill-space-group-properties.ts
+++ b/packages/posthog/src/scripts/backfill-space-group-properties.ts
@@ -34,9 +34,10 @@ const API_HOST = process.env.NEXT_PUBLIC_POSTHOG_API_HOST;
const PAGE_SIZE = 500;
const SAMPLE_SIZE = 10;
// Without an explicit distinctId, groupIdentify defaults to $space_<groupKey>,
-// which creates a dummy person profile PER GROUP (PostHog/posthog#7921). A
-// single shared id caps the junk at one person for the whole run.
-const BACKFILL_DISTINCT_ID = "space_group_properties_backfill";
+// which creates a dummy person profile PER GROUP (PostHog/posthog#7921). Shares
+// the id used by identifyGroup in apps/web so all group identifies collapse
+// into a single dummy person.
+const BACKFILL_DISTINCT_ID = "server_group_identify";
// Matches DEFAULT_SEAT_LIMIT in apps/web β€” spaces without an active
// subscription have a single seat
const DEFAULT_SEAT_COUNT = 1;