npm.io
2.22.7 • Published 4d ago

@medusajs/analytics

Licence
MIT
Version
2.22.7
Deps
0
Size
23 kB
Vulns
0
Weekly
0
Stars
36.1K

Medusa logo

@medusajs/analytics

Documentation | Website

Building blocks for digital commerce

Medusa is released under the MIT license. PRs welcome! Discord Chat Follow @medusajs

Analytics Module for Medusa: tracks events and identifies users by forwarding them to third-party analytics services such as PostHog. It uses a provider pattern, so the service you send data to is a pluggable Analytics Module Provider. It ships with @medusajs/medusa and is registered from @medusajs/medusa/analytics.

At a glance

Package @medusajs/analytics
Type Infrastructure Module
Module key Modules.ANALYTICS ("analytics")
Registered by default No
Import from @medusajs/medusa/analytics

Features

  • Track events (for example, order placed) and identify users from workflows, subscribers, or API routes.
  • Pluggable providers. Official providers:

Installation

No installation needed. The module ships with @medusajs/medusa, but you must register it in medusa-config.ts.

Usage

import { defineConfig } from "@medusajs/framework/utils"

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/analytics",
      options: {
        providers: [
          {
            resolve: "@medusajs/medusa/analytics-local",
            id: "local",
          },
        ],
      },
    },
  ],
})

Then resolve the service with container.resolve(Modules.ANALYTICS) and call its track and identify methods.

Configuration

Option Type Description Default
providers { resolve: string, id: string, options?: Record<string, unknown> }[] Analytics Module Providers to register. options is passed to the provider. []

Resources