medusajs/medusa · error · Error
Group type is required if passing group id when tracking an
Error message
Group type is required if passing group id when tracking an event with Posthog
What it means
When you pass a `group` with an `id` to the Posthog provider's `track` method, Posthog also needs a group `type` (the group key like 'company'). The provider rejects the combination id-without-type.
Source
Thrown at packages/modules/providers/analytics-posthog/src/services/posthog-analytics.ts:51
host: options.posthogHost || "https://eu.i.posthog.com",
})
}
async track(data: ProviderTrackAnalyticsEventDTO): Promise<void> {
if (!data.event) {
throw new Error(
"Event name is required when tracking an event with Posthog"
)
}
if (!data.actor_id) {
throw new Error(
"Actor ID is required when tracking an event with Posthog"
)
}
if (data.group?.id && !data.group?.type) {
throw new Error(
"Group type is required if passing group id when tracking an event with Posthog"
)
}
this.client_.capture({
event: data.event,
distinctId: data.actor_id,
properties: data.properties,
groups: data.group?.id
? { [data.group.type!]: data.group.id }
: undefined,
})
}
async identify(data: ProviderIdentifyAnalyticsEventDTO): Promise<void> {
if ("group" in data) {
this.client_.groupIdentify({
groupKey: data.group.id!,View on GitHub (pinned to 5e06e544a2)
Solutions
- Add a type: `group: { id: 'org_123', type: 'company' }`
- Omit the group entirely if group analytics isn't needed
Example fix
// before
group: { id: organizationId }
// after
group: { id: organizationId, type: 'organization' } Defensive patterns
Strategy: type-guard
Validate before calling
if (dto.group?.id && !dto.group.type) {
throw new Error('group.type is required when group.id is set')
} Type guard
const isValidGroup = (g?: { id?: string; type?: string }): boolean => !g?.id || Boolean(g.type) Prevention
- Define group as a strict { id: string; type: string } tuple type in your analytics wrapper
- Reject partial group payloads at the API boundary
When it happens
Trigger: Calling `track({ ..., group: { id: 'org_123' } })` with no `type` property.
Common situations: Partial group objects built from loosely-typed payloads, or assuming Posthog infers the group type from the id.
Related errors
- Event name is required when tracking an event with Posthog
- Actor ID is required when tracking an event with Posthog
- Actor or group is required when identifying an entity with P
- Posthog API key is not set, but is required
- --paths must be a directory - ${additionalPath}
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/5cc2ac962c16bcee.
Report an issue: GitHub.