docs: fix examples in Analytics Module docs (#13259)

* docs: fix example in Analytics Module docs

* generate
This commit is contained in:
Shahed Nasser
2025-08-20 18:06:41 +03:00
committed by GitHub
parent e022723e8b
commit a594d32ba3
5 changed files with 63 additions and 29 deletions

View File

@@ -37774,6 +37774,18 @@ module.exports = defineConfig({
})
```
### Change Log Level
The Local Analytics Module Provider logs events to the console at the `debug` level, which is below the default `http` level.
So, to see the tracked events in your logs, you need to change the log level to `debug` or `silly`. You can do so by setting the `LOG_LEVEL` system environment variable:
```bash
export LOG_LEVEL=debug
```
The environment variable must be set as a system environment variable and not in `.env`.
***
## Test out the Module
@@ -37787,6 +37799,7 @@ For example, create a workflow at `src/workflows/track-order-placed.ts` with the
```ts title="src/workflows/track-order-created.ts" highlights={workflowHighlights}
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
import { OrderDTO } from "@medusajs/framework/types"
@@ -37801,11 +37814,11 @@ const trackOrderCreatedStep = createStep(
await analyticsModuleService.track({
event: "order_created",
userId: order.customer_id,
actor_id: order.customer_id,
properties: {
order_id: order.id,
total: order.total,
items: order.items.map((item) => ({
items: order.items?.map((item) => ({
variant_id: item.variant_id,
product_id: item.product_id,
quantity: item.quantity,
@@ -37836,7 +37849,7 @@ export const trackOrderCreatedWorkflow = createWorkflow(
})
trackOrderCreatedStep({
order: orders[0],
})
} as unknown as StepInput)
}
)
```
@@ -37872,7 +37885,7 @@ export const config: SubscriberConfig = {
This subscriber listens to the `order.placed` event and executes the `trackOrderCreatedWorkflow` workflow, passing the order ID as input.
You'll now track the order creation event whenever an order is placed in your Medusa application. You can test this out by placing an order and checking the console for the tracked event.
You'll now track the order creation event whenever an order is placed in your Medusa application. You can test this out by placing an order and checking the server's logs for the tracked event.
***
@@ -37948,6 +37961,7 @@ For example, create a workflow at `src/workflows/track-order-placed.ts` with the
```ts title="src/workflows/track-order-created.ts" highlights={workflowHighlights}
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
import { OrderDTO } from "@medusajs/framework/types"
@@ -37962,11 +37976,11 @@ const trackOrderCreatedStep = createStep(
await analyticsModuleService.track({
event: "order_created",
userId: order.customer_id,
actor_id: order.customer_id,
properties: {
order_id: order.id,
total: order.total,
items: order.items.map((item) => ({
items: order.items?.map((item) => ({
variant_id: item.variant_id,
product_id: item.product_id,
quantity: item.quantity,
@@ -37997,7 +38011,7 @@ export const trackOrderCreatedWorkflow = createWorkflow(
})
trackOrderCreatedStep({
order: orders[0],
})
} as unknown as StepInput)
}
)
```
@@ -38115,6 +38129,7 @@ For example, create a workflow at `src/workflows/track-order-placed.ts` with the
```ts title="src/workflows/track-order-created.ts" highlights={workflowHighlights}
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
import { OrderDTO } from "@medusajs/framework/types"
@@ -38129,11 +38144,11 @@ const trackOrderCreatedStep = createStep(
await analyticsModuleService.track({
event: "order_created",
userId: order.customer_id,
actor_id: order.customer_id,
properties: {
order_id: order.id,
total: order.total,
items: order.items.map((item) => ({
items: order.items?.map((item) => ({
variant_id: item.variant_id,
product_id: item.product_id,
quantity: item.quantity,
@@ -38164,7 +38179,7 @@ export const trackOrderCreatedWorkflow = createWorkflow(
})
trackOrderCreatedStep({
order: orders[0],
})
} as unknown as StepInput)
}
)
```

View File

@@ -45,6 +45,22 @@ module.exports = defineConfig({
})
```
### Change Log Level
The Local Analytics Module Provider logs events to the console at the `debug` level, which is below the default `http` level.
So, to see the tracked events in your logs, you need to change the log level to `debug` or `silly`. You can do so by setting the `LOG_LEVEL` system environment variable:
```bash
export LOG_LEVEL=debug
```
<Note title="Important">
The environment variable must be set as a system environment variable and not in `.env`.
</Note>
---
## Test out the Module
@@ -56,13 +72,14 @@ You'll first create a [workflow](!docs!/learn/fundamentals/workflows) that track
For example, create a workflow at `src/workflows/track-order-placed.ts` with the following content:
export const workflowHighlights = [
["13", "resolve", "Resolve the Analytics Module's service"],
["15", "track", "Track the event in the installed Analytics Module Provider"]
["14", "resolve", "Resolve the Analytics Module's service"],
["16", "track", "Track the event in the installed Analytics Module Provider"]
]
```ts title="src/workflows/track-order-created.ts" highlights={workflowHighlights}
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
import { OrderDTO } from "@medusajs/framework/types"
@@ -77,11 +94,11 @@ const trackOrderCreatedStep = createStep(
await analyticsModuleService.track({
event: "order_created",
userId: order.customer_id,
actor_id: order.customer_id,
properties: {
order_id: order.id,
total: order.total,
items: order.items.map((item) => ({
items: order.items?.map((item) => ({
variant_id: item.variant_id,
product_id: item.product_id,
quantity: item.quantity,
@@ -112,7 +129,7 @@ export const trackOrderCreatedWorkflow = createWorkflow(
})
trackOrderCreatedStep({
order: orders[0],
})
} as unknown as StepInput)
}
)
```
@@ -148,7 +165,7 @@ export const config: SubscriberConfig = {
This subscriber listens to the `order.placed` event and executes the `trackOrderCreatedWorkflow` workflow, passing the order ID as input.
You'll now track the order creation event whenever an order is placed in your Medusa application. You can test this out by placing an order and checking the console for the tracked event.
You'll now track the order creation event whenever an order is placed in your Medusa application. You can test this out by placing an order and checking the server's logs for the tracked event.
---

View File

@@ -99,13 +99,14 @@ In a step of your workflow, you can resolve the Analytics Module's service and u
For example, create a workflow at `src/workflows/track-order-placed.ts` with the following content:
export const workflowHighlights = [
["13", "resolve", "Resolve the Analytics Module's service"],
["15", "track", "Track the event in the installed Analytics Module Provider"]
["14", "resolve", "Resolve the Analytics Module's service"],
["16", "track", "Track the event in the installed Analytics Module Provider"]
]
```ts title="src/workflows/track-order-created.ts" highlights={workflowHighlights}
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
import { OrderDTO } from "@medusajs/framework/types"
@@ -120,11 +121,11 @@ const trackOrderCreatedStep = createStep(
await analyticsModuleService.track({
event: "order_created",
userId: order.customer_id,
actor_id: order.customer_id,
properties: {
order_id: order.id,
total: order.total,
items: order.items.map((item) => ({
items: order.items?.map((item) => ({
variant_id: item.variant_id,
product_id: item.product_id,
quantity: item.quantity,
@@ -155,7 +156,7 @@ export const trackOrderCreatedWorkflow = createWorkflow(
})
trackOrderCreatedStep({
order: orders[0],
})
} as unknown as StepInput)
}
)
```

View File

@@ -128,13 +128,14 @@ You'll first create a [workflow](!docs!/learn/fundamentals/workflows) that track
For example, create a workflow at `src/workflows/track-order-placed.ts` with the following content:
export const workflowHighlights = [
["13", "resolve", "Resolve the Analytics Module's service"],
["15", "track", "Track the event in the installed Analytics Module Provider"]
["14", "resolve", "Resolve the Analytics Module's service"],
["16", "track", "Track the event in the installed Analytics Module Provider"]
]
```ts title="src/workflows/track-order-created.ts" highlights={workflowHighlights}
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
import { OrderDTO } from "@medusajs/framework/types"
@@ -149,11 +150,11 @@ const trackOrderCreatedStep = createStep(
await analyticsModuleService.track({
event: "order_created",
userId: order.customer_id,
actor_id: order.customer_id,
properties: {
order_id: order.id,
total: order.total,
items: order.items.map((item) => ({
items: order.items?.map((item) => ({
variant_id: item.variant_id,
product_id: item.product_id,
quantity: item.quantity,
@@ -184,7 +185,7 @@ export const trackOrderCreatedWorkflow = createWorkflow(
})
trackOrderCreatedStep({
order: orders[0],
})
} as unknown as StepInput)
}
)
```

View File

@@ -6484,9 +6484,9 @@ export const generatedEditDates = {
"app/commerce-modules/tax/tax-provider/page.mdx": "2025-05-20T07:51:40.711Z",
"app/recipes/bundled-products/examples/standard/page.mdx": "2025-06-26T11:52:18.819Z",
"app/recipes/bundled-products/page.mdx": "2025-05-20T07:51:40.718Z",
"app/infrastructure-modules/analytics/local/page.mdx": "2025-06-10T15:56:43.648Z",
"app/infrastructure-modules/analytics/page.mdx": "2025-05-26T14:48:25.803Z",
"app/infrastructure-modules/analytics/posthog/page.mdx": "2025-06-10T15:56:43.648Z",
"app/infrastructure-modules/analytics/local/page.mdx": "2025-08-20T14:28:29.274Z",
"app/infrastructure-modules/analytics/page.mdx": "2025-08-20T14:25:57.537Z",
"app/infrastructure-modules/analytics/posthog/page.mdx": "2025-08-20T14:25:41.471Z",
"references/analytics/interfaces/analytics.IAnalyticsModuleService/page.mdx": "2025-06-05T19:05:43.239Z",
"references/analytics_provider/classes/analytics_provider.AbstractAnalyticsProviderService/page.mdx": "2025-05-21T14:22:04.267Z",
"references/modules/analytics/page.mdx": "2025-05-21T14:21:59.323Z",