{"record":{"id":"645f46044273b5fd","repo":"medusajs/medusa","slug":"event-name-is-required-when-tracking-an-event-with","errorCode":null,"errorMessage":"Event name is required when tracking an event with Posthog","messagePattern":"Event name is required 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":39,"sourceCode":"    { logger }: InjectedDependencies,\n    options: PosthogAnalyticsServiceOptions\n  ) {\n    super()\n    this.config_ = options\n    this.logger_ = logger\n\n    if (!options.posthogEventsKey) {\n      throw new Error(\"Posthog API key is not set, but is required\")\n    }\n\n    this.client_ = new PostHog(options.posthogEventsKey, {\n      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,","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/providers/analytics-posthog/src/services/posthog-analytics.ts#L21-L57","documentation":"The Posthog provider's `track` method requires an event name. The provider throws when `data.event` is falsy because the underlying PostHog `capture` call cannot send an unnamed event.","triggerScenarios":"Calling `analyticsService.track({ actor_id: '...', event: '' })` or building the DTO dynamically where the event field ends up undefined.","commonSituations":"Dynamic event-name construction (e.g. `event: `${prefix}_${action}``) where one part is undefined, or migrating from an analytics interface that made event optional.","solutions":["Pass a non-empty `event` string in the track DTO","If the event name is dynamic, default it: `event: name || 'unnamed_action'`"],"exampleFix":"// before\nawait analytics.track({ actor_id: userId })\n// after\nawait analytics.track({ actor_id: userId, event: 'user_login' })","handlingStrategy":"validation","validationCode":"function assertTrackDTO(data: ProviderTrackAnalyticsEventDTO) {\n  if (!data.event) throw new TypeError('track: event name is required')\n}","typeGuard":"const isTrackable = (d: ProviderTrackAnalyticsEventDTO): boolean => Boolean(d.event)","tryCatchPattern":"try { await provider.track(dto) } catch (e) { logger.warn(`analytics track failed: ${e.message}`) } // analytics should not break the request","preventionTips":["Type the DTO strictly so event is required","Centralize analytics calls in one wrapper that validates first"],"tags":["posthog","analytics","validation"],"backgroundTag":"required-field-missing","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}