In this document, you’ll learn about the different methods in the Analytics Module's service and how to use them.
To use the Analytics Module, you need to configure it along with an Analytics Module Provider.
Medusa provides two Analytics Module Providers: Local and PostHog module providers.
To configure the Analytics Module and its provider, add it to the list of modules in your medusa-config.ts
file. For example:
Refer to the documentation of each provider for specific configuration options.
In your workflow's step, you can resolve the Analytics Module's service from the Medusa container:
1import { Modules } from "@medusajs/framework/utils"2import { createStep } from "@medusajs/framework/workflows-sdk"3 4const step1 = createStep(5 "step-1",6 async ({}, { container }) => {7 const analyticsModuleService = container.resolve(8 Modules.Analytics9 )10 11 // TODO use analyticsModuleService12 } 13)
You can then use the Analytics Module's service's methods in the step, which would use the underlying provider's logic. The rest of this guide details these methods.
This method returns the service of the configured Analytics Module Provider in medusa-config.ts
. This is useful
if you want to execute custom methods defined in the provider's service or you need direct access to it.
track
(data: TrackAnalyticsEventDTO) => Promise<void>identify
(data: IdentifyAnalyticsEventDTO) => Promise<void>shutdown
() => Promise<void>OptionalThis method identifies an actor or group in the analytics provider. The Analytics Module
will use the identify
method of the underlying provider configured in medusa-config.ts
to identify the actor or group.
Promise
Promise<void>This method tracks an event in the analytics provider. The Analytics Module
will use the track
method of the underlying provider configured in medusa-config.ts
to track the event.
Promise
Promise<void>