From a594d32ba36feda9fd1fc3a55d6969f7d3dd0f36 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 20 Aug 2025 18:06:41 +0300 Subject: [PATCH] docs: fix examples in Analytics Module docs (#13259) * docs: fix example in Analytics Module docs * generate --- www/apps/book/public/llms-full.txt | 35 +++++++++++++------ .../analytics/local/page.mdx | 29 +++++++++++---- .../infrastructure-modules/analytics/page.mdx | 11 +++--- .../analytics/posthog/page.mdx | 11 +++--- www/apps/resources/generated/edit-dates.mjs | 6 ++-- 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/www/apps/book/public/llms-full.txt b/www/apps/book/public/llms-full.txt index daffdbae0c..2877ee3058 100644 --- a/www/apps/book/public/llms-full.txt +++ b/www/apps/book/public/llms-full.txt @@ -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) } ) ``` diff --git a/www/apps/resources/app/infrastructure-modules/analytics/local/page.mdx b/www/apps/resources/app/infrastructure-modules/analytics/local/page.mdx index 3377e00f25..3885c1d49d 100644 --- a/www/apps/resources/app/infrastructure-modules/analytics/local/page.mdx +++ b/www/apps/resources/app/infrastructure-modules/analytics/local/page.mdx @@ -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 +``` + + + +The environment variable must be set as a system environment variable and not in `.env`. + + + --- ## 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. --- diff --git a/www/apps/resources/app/infrastructure-modules/analytics/page.mdx b/www/apps/resources/app/infrastructure-modules/analytics/page.mdx index a9b7209e87..18c62f09a9 100644 --- a/www/apps/resources/app/infrastructure-modules/analytics/page.mdx +++ b/www/apps/resources/app/infrastructure-modules/analytics/page.mdx @@ -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) } ) ``` diff --git a/www/apps/resources/app/infrastructure-modules/analytics/posthog/page.mdx b/www/apps/resources/app/infrastructure-modules/analytics/posthog/page.mdx index 79c812b3f9..0b025b3e51 100644 --- a/www/apps/resources/app/infrastructure-modules/analytics/posthog/page.mdx +++ b/www/apps/resources/app/infrastructure-modules/analytics/posthog/page.mdx @@ -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) } ) ``` diff --git a/www/apps/resources/generated/edit-dates.mjs b/www/apps/resources/generated/edit-dates.mjs index 3d6410e02d..2d4f5a3d09 100644 --- a/www/apps/resources/generated/edit-dates.mjs +++ b/www/apps/resources/generated/edit-dates.mjs @@ -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",