{"record":{"id":"5cc2ac962c16bcee","repo":"medusajs/medusa","slug":"group-type-is-required-if-passing-group-id-when-tr","errorCode":null,"errorMessage":"Group type is required if passing group id when tracking an event with Posthog","messagePattern":"Group type is required if passing group id when tracking an event with Posthog","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/modules/providers/analytics-posthog/src/services/posthog-analytics.ts","lineNumber":51,"sourceCode":"      host: options.posthogHost || \"https://eu.i.posthog.com\",\n    })\n  }\n\n  async track(data: ProviderTrackAnalyticsEventDTO): Promise<void> {\n    if (!data.event) {\n      throw new Error(\n        \"Event name is required when tracking an event with Posthog\"\n      )\n    }\n\n    if (!data.actor_id) {\n      throw new Error(\n        \"Actor ID is required when tracking an event with Posthog\"\n      )\n    }\n\n    if (data.group?.id && !data.group?.type) {\n      throw new Error(\n        \"Group type is required if passing group id when tracking an event with Posthog\"\n      )\n    }\n\n    this.client_.capture({\n      event: data.event,\n      distinctId: data.actor_id,\n      properties: data.properties,\n      groups: data.group?.id\n        ? { [data.group.type!]: data.group.id }\n        : undefined,\n    })\n  }\n\n  async identify(data: ProviderIdentifyAnalyticsEventDTO): Promise<void> {\n    if (\"group\" in data) {\n      this.client_.groupIdentify({\n        groupKey: data.group.id!,","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/providers/analytics-posthog/src/services/posthog-analytics.ts#L33-L69","documentation":"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.","triggerScenarios":"Calling `track({ ..., group: { id: 'org_123' } })` with no `type` property.","commonSituations":"Partial group objects built from loosely-typed payloads, or assuming Posthog infers the group type from the id.","solutions":["Add a type: `group: { id: 'org_123', type: 'company' }`","Omit the group entirely if group analytics isn't needed"],"exampleFix":"// before\ngroup: { id: organizationId }\n// after\ngroup: { id: organizationId, type: 'organization' }","handlingStrategy":"type-guard","validationCode":"if (dto.group?.id && !dto.group.type) {\n  throw new Error('group.type is required when group.id is set')\n}","typeGuard":"const isValidGroup = (g?: { id?: string; type?: string }): boolean => !g?.id || Boolean(g.type)","tryCatchPattern":null,"preventionTips":["Define group as a strict { id: string; type: string } tuple type in your analytics wrapper","Reject partial group payloads at the API boundary"],"tags":["posthog","analytics","grouping","validation"],"backgroundTag":"required-field-missing","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}