@medusajs/analytics-posthog 2.22.0-snapshot-20261020204851 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/AGENTS.md +51 -0
  2. package/README.md +97 -0
  3. package/package.json +7 -3
package/AGENTS.md ADDED
@@ -0,0 +1,51 @@
1
+ # @medusajs/analytics-posthog
2
+
3
+ Analytics Module provider that forwards `track`/`identify` calls to PostHog through `posthog-node`.
4
+
5
+ ## Using this package
6
+
7
+ ```ts
8
+ module.exports = defineConfig({
9
+ modules: [
10
+ {
11
+ resolve: "@medusajs/medusa/analytics",
12
+ options: {
13
+ providers: [
14
+ {
15
+ resolve: "@medusajs/medusa/analytics-posthog",
16
+ id: "posthog",
17
+ options: {
18
+ posthogEventsKey: process.env.POSTHOG_EVENTS_API_KEY,
19
+ posthogHost: process.env.POSTHOG_HOST,
20
+ },
21
+ },
22
+ ],
23
+ },
24
+ },
25
+ ],
26
+ })
27
+ ```
28
+
29
+ - Options (`PosthogAnalyticsServiceOptions`): `posthogEventsKey` (required, the project API key), `posthogHost` (defaults to `https://eu.i.posthog.com`).
30
+ - Resolve the module with `Modules.ANALYTICS` and call `track()` / `identify()`.
31
+ - Docs: https://docs.medusajs.com/resources/infrastructure-modules/analytics/posthog.md
32
+ - Build a custom analytics provider: https://docs.medusajs.com/resources/references/analytics/provider.md
33
+
34
+ ## Architecture
35
+
36
+ - `src/services/posthog-analytics.ts`: `PosthogAnalyticsService extends AbstractAnalyticsProviderService`, `static identifier = "analytics-posthog"`.
37
+ - Implements `track` (maps to `client.capture`), `identify` (maps to `client.identify`, or `client.groupIdentify` when the input has a `group`), and `shutdown` (flushes the PostHog client; called by the Analytics Module on shutdown).
38
+ - Good reference for a custom analytics provider that needs a `shutdown()` flush.
39
+
40
+ ## Development
41
+
42
+ - `yarn build`, `yarn test` (no tests in this package).
43
+
44
+ ## Gotchas
45
+
46
+ - The constructor throws if `posthogEventsKey` is missing, so a missing env var fails at boot.
47
+ - The default host is the EU cloud; set `posthogHost` (e.g. `https://us.i.posthog.com`) for US projects.
48
+ - `track` throws without `event` or `actor_id`, and throws if `group.id` is passed without `group.type`.
49
+ - `identify` throws when neither `actor_id` nor `group` is given.
50
+ - `track`/`identify` don't await delivery (`posthog-node` queues them); `shutdown()` flushes the queue, so short-lived scripts must let the module shut down cleanly.
51
+ - Exactly one Analytics provider may be registered.
package/README.md CHANGED
@@ -0,0 +1,97 @@
1
+ <p align="center">
2
+ <a href="https://www.medusajs.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
6
+ <img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
7
+ </picture>
8
+ </a>
9
+ </p>
10
+ <h1 align="center">
11
+ @medusajs/analytics-posthog
12
+ </h1>
13
+
14
+ <h4 align="center">
15
+ <a href="https://docs.medusajs.com">Documentation</a> |
16
+ <a href="https://www.medusajs.com">Website</a>
17
+ </h4>
18
+
19
+ <p align="center">
20
+ Building blocks for digital commerce
21
+ </p>
22
+ <p align="center">
23
+ <a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
24
+ <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
25
+ </a>
26
+ <a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
27
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
28
+ </a>
29
+ <a href="https://discord.gg/xpCwq3Kfn8">
30
+ <img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
31
+ </a>
32
+ <a href="https://twitter.com/intent/follow?screen_name=medusajs">
33
+ <img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
34
+ </a>
35
+ </p>
36
+
37
+ PostHog Analytics Module Provider for Medusa: sends events and identities tracked through the Analytics Module to PostHog. Use it to track commerce events (such as orders placed or carts updated) in PostHog from your workflows and subscribers. It ships with `@medusajs/medusa` and is registered through the `@medusajs/medusa/analytics-posthog` path.
38
+
39
+ ## At a glance
40
+
41
+ | | |
42
+ | --- | --- |
43
+ | Package | `@medusajs/analytics-posthog` |
44
+ | Type | Module Provider (Analytics Module) |
45
+ | Provider ID | `analytics-posthog` |
46
+ | Registered by default | No |
47
+ | Import from | `@medusajs/medusa/analytics-posthog` |
48
+
49
+ ## Installation
50
+
51
+ No installation needed. The provider is a dependency of `@medusajs/medusa`.
52
+
53
+ ## Usage
54
+
55
+ Register the provider in the Analytics Module's `providers` array in `medusa-config.ts`. The Analytics Module accepts exactly one provider.
56
+
57
+ ```ts
58
+ import { defineConfig } from "@medusajs/framework/utils"
59
+
60
+ module.exports = defineConfig({
61
+ // ...
62
+ modules: [
63
+ {
64
+ resolve: "@medusajs/medusa/analytics",
65
+ options: {
66
+ providers: [
67
+ {
68
+ resolve: "@medusajs/medusa/analytics-posthog",
69
+ id: "posthog",
70
+ options: {
71
+ posthogEventsKey: process.env.POSTHOG_EVENTS_API_KEY,
72
+ posthogHost: process.env.POSTHOG_HOST,
73
+ },
74
+ },
75
+ ],
76
+ },
77
+ },
78
+ ],
79
+ })
80
+ ```
81
+
82
+ ## Configuration
83
+
84
+ | Option | Type | Description | Default |
85
+ | --- | --- | --- | --- |
86
+ | `posthogEventsKey` | `string` | Required. The PostHog project API key used to send events. | - |
87
+ | `posthogHost` | `string` | The PostHog instance URL. | `https://eu.i.posthog.com` |
88
+
89
+ | Environment variable | Description |
90
+ | --- | --- |
91
+ | `POSTHOG_EVENTS_API_KEY` | Value for `posthogEventsKey`, as used in the example above. |
92
+ | `POSTHOG_HOST` | Value for `posthogHost`, as used in the example above. |
93
+
94
+ ## Resources
95
+
96
+ - [PostHog Analytics Module Provider](https://docs.medusajs.com/resources/infrastructure-modules/analytics/posthog)
97
+ - [Analytics Module](https://docs.medusajs.com/resources/infrastructure-modules/analytics)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/analytics-posthog",
3
- "version": "2.22.0-snapshot-20261020204851",
3
+ "version": "2.22.0",
4
4
  "description": "Posthog analytics provider for Medusa",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -13,10 +13,14 @@
13
13
  },
14
14
  "files": [
15
15
  "dist",
16
+ "AGENTS.md",
16
17
  "!dist/**/__tests__",
17
18
  "!dist/**/__mocks__",
18
19
  "!dist/**/__fixtures__"
19
20
  ],
21
+ "llms": "https://docs.medusajs.com/llms.txt",
22
+ "llmsFull": "https://docs.medusajs.com/llms-full.txt",
23
+ "mcpServer": "https://docs.medusajs.com/mcp",
20
24
  "engines": {
21
25
  "node": ">=22.22.0"
22
26
  },
@@ -28,11 +32,11 @@
28
32
  "watch": "yarn run -T tsc --watch"
29
33
  },
30
34
  "devDependencies": {
31
- "@medusajs/framework": "2.22.0-snapshot-20261020204851",
35
+ "@medusajs/framework": "2.22.0",
32
36
  "posthog-node": "^5.11.0"
33
37
  },
34
38
  "peerDependencies": {
35
- "@medusajs/framework": "2.22.0-snapshot-20261020204851",
39
+ "@medusajs/framework": "2.22.0",
36
40
  "posthog-node": "^5.11.0"
37
41
  },
38
42
  "keywords": [