Bloomreach integration for Medusa V2 for customers, catalog, and search. It can also be used for transactional emails.
This module integrates Bloomreach (Exponea) as a notification and analytics provider for Medusa v2. It enables you to send transactional emails and SMS messages through the Bloomreach platform, as well as track customer events and behavior for powerful engagement and marketing automation.
With this plugin, you can:
This module/plugin is compatible with versions >= 2.4.0 of .
Before using this integration, you need:
For more details, see the Bloomreach Authentication Documentation.
npm install @igorppbr/medusa-v2-bloomreach-notification
import { Modules } from "@medusajs/framework/utils"export default defineConfig({// ... other configmodules: [{resolve: "@medusajs/medusa/notification",options: {providers: [// default provider{resolve: "@medusajs/medusa/notification-local",id: "local",options: {name: "Local Notification Provider",channels: ["feed"]}},{resolve: "@igorppbr/medusa-v2-bloomreach/providers/notifications",id: "bloomreach-notification",options: {channels: ["email", "sms"], // Specify the channels you want to supportnotifications: {key_id: process.env.BLOOMREACH_API_KEY_ID,secret: process.env.BLOOMREACH_API_SECRET,project_id: process.env.BLOOMREACH_PROJECT_ID,integration_id: process.env.BLOOMREACH_INTEGRATION_ID,from_email: "noreply@yourdomain.com",from_name: "Your Company Name",from_sms: "+1234567890", // Required if using SMS channellanguage: "en", // Optional: default language for templatestransfer_identity: "enabled", // Optional: 'enabled', 'disabled', or 'first_click'template_mappings: { // Optional: map Medusa template names to Bloomreach template IDs"order-confirmation": "60758e2d18883e1048b817a8","order-shipped": "60758e2d18883e1048b817a9"},campaign_mappings: { // Optional: map template names to campaign names"order-confirmation": "Order Confirmation Campaign","order-shipped": "Order Shipped Campaign"}}}}]}},{resolve: "@medusajs/medusa/analytics",options: {providers: [{resolve: "@igorppbr/medusa-v2-bloomreach/providers/analytics",id: "bloomreach-analytics",options: {notifications: {key_id: process.env.BLOOMREACH_API_KEY_ID,secret: process.env.BLOOMREACH_API_SECRET,project_id: process.env.BLOOMREACH_PROJECT_ID}}}]}}],plugins: [{resolve: "@igorppbr/medusa-v2-bloomreach",options: {},},]})
Note: Adding the plugin is required for Medusa to load the event subscribers that handle notifications and analytics tracking.
BLOOMREACH_API_KEY_ID=your_api_key_idBLOOMREACH_API_SECRET=your_api_secretBLOOMREACH_PROJECT_ID=your_project_idBLOOMREACH_INTEGRATION_ID=your_integration_id
Important: Never commit your API credentials to version control. Always use environment variables.
| Option | Type | Required | Description |
|---|---|---|---|
| string | Yes | Your Bloomreach API Key ID | |
| string | Yes | Your Bloomreach API Secret | |
| string | Yes | Your Bloomreach Project ID | |
| string | Yes | Your email/SMS integration ID | |
| string | Yes | Default sender email address | |
| string | Yes | Default sender name for emails | |
| string | Conditional | Required if using SMS channel - sender phone number | |
| string | No | Default language code (e.g., "en", "es") | |
| string | No | Link tracking behavior: "enabled", "disabled", or "first_click" | |
| object | No | Map Medusa template names to Bloomreach template IDs | |
| object | No | Map template names to campaign names |
Track customer behavior and events for analytics and personalization:
import { Modules } from "@medusajs/framework/utils"// In a workflow, subscriber, or API routeconst analyticsModuleService = container.resolve(Modules.ANALYTICS)await analyticsModuleService.track({event: "product_viewed",actor_id: "customer123",properties: {product_id: "prod_abc",product_name: "Amazing Widget",price: 99.99,category: "electronics"}})
Create a workflow to track order events:
// src/workflows/track-order-placed.tsimport { createWorkflow, createStep, WorkflowResponse } from "@medusajs/framework/workflows-sdk"import { Modules } from "@medusajs/framework/utils"import { useQueryGraphStep } from "@medusajs/medusa/core-flows"type WorkflowInput = {order_id: string}type StepInput = {order: any}const trackOrderPlacedStep = createStep("track-order-placed-step",async ({ order }: StepInput, { container }) => {const analyticsModuleService = container.resolve(Modules.ANALYTICS)await analyticsModuleService.track({event: "order_placed",actor_id: order.customer_id,properties: {order_id: order.id,order_number: order.display_id,total: order.total,currency: order.currency_code,items: order.items.map((item) => ({variant_id: item.variant_id,product_id: item.product_id,quantity: item.quantity,price: item.unit_price}))}})})export const trackOrderPlacedWorkflow = createWorkflow("track-order-placed-workflow",({ order_id }: WorkflowInput) => {const { data: orders } = useQueryGraphStep({entity: "order",fields: ["*", "customer.*", "items.*"],filters: { id: order_id }})trackOrderPlacedStep({ order: orders[0] })return new WorkflowResponse(void 0)})
Then create a subscriber to execute the workflow:
// src/subscribers/order-placed-analytics.tsimport { SubscriberArgs, type SubscriberConfig } from "@medusajs/medusa"import { trackOrderPlacedWorkflow } from "../workflows/track-order-placed"export default async function orderPlacedAnalyticsHandler({event: { data },container,}: SubscriberArgs<{ id: string }>) {await trackOrderPlacedWorkflow(container).run({input: { order_id: data.id }})}export const config: SubscriberConfig = {event: "order.placed",}
Once configured, you can send email notifications using the Notification Module:
import { Modules } from "@medusajs/framework/utils"// In a workflow, subscriber, or API routeconst notificationModuleService = container.resolve(Modules.NOTIFICATION)await notificationModuleService.createNotifications({to: "customer@example.com",channel: "email",template: "order-confirmation",data: {order_number: "12345",customer_name: "John Doe",order_total: "$99.99"}})
import { Modules } from "@medusajs/framework/utils"const notificationModuleService = container.resolve(Modules.NOTIFICATION)await notificationModuleService.createNotifications({to: "+1234567890",channel: "sms",template: "order-shipped",data: {order_number: "12345",tracking_number: "ABC123XYZ"}})
Create a subscriber to send order confirmation emails:
// src/subscribers/order-placed.tsimport { Modules } from "@medusajs/framework/utils"import { SubscriberArgs, type SubscriberConfig } from "@medusajs/medusa"import { trackOrderPlacedWorkflow } from "../workflows/track-order-placed"export default async function orderPlacedHandler({event: { data },container,}: SubscriberArgs<{ id: string }>) {// Notificationstry {const notificationModuleService = container.resolve(Modules.NOTIFICATION)const query = container.resolve("query")// Get order detailsconst { data: [order] } = await query.graph({entity: "order",fields: ["*", "customer.*", "items.*"],filters: { id: data.id }})// Send email notificationawait notificationModuleService.createNotifications({to: order.customer.email,channel: "email",template: "order-confirmation",data: {customer_name: `${order.customer.first_name} ${order.customer.last_name}`,order_number: order.display_id,order_total: order.total,items: order.items}})} catch (error) {console.error("[Bloomreach] Error sending order notification:", error)}// Track analyticstry {await trackOrderPlacedWorkflow(container).run({input: { order_id: data.id }})} catch (error) {console.error("[Bloomreach] Error tracking order analytics:", error)}}export const config: SubscriberConfig = {event: "order.placed",}
Hello {{ first_name }},Your order #{{ order_number }} has been confirmed!Total: {{ order_total }}
Error: "API key is required in the provider's options"
Error: "From SMS is required in the provider's options to send SMS notifications"
Email/SMS not being sent
Template not found
This package includes a Bloomreach SDK with the following functions:
Sends a transactional email through Bloomreach.
const messageId = await sendTransactionalEmail(key_id,secret,project_id,integration_id,template_id,campaign_name,{email: "customer@example.com",customer_ids: { registered: "user123" },language: "en"},{ firstName: "John", orderTotal: "99.99" },sender_address,sender_name,transfer_identity)
Sends a transactional SMS through Bloomreach.
const messageId = await sendTransactionalSms(key_id,secret,project_id,campaign_name,{template_id: "template789",params: { order_number: "12345" }},{phone: "+1234567890",customer_ids: { registered: "user123" },language: "en"},integration_id)
Tracks a customer event in Bloomreach.
await addEvent(key_id,secret,project_id,{ registered: "user@example.com" },"purchase",{total_price: 149.99,voucher_code: "SAVE20",product_ids: ["prod1", "prod2"],currency: "USD"},Math.floor(Date.now() / 1000) // Optional timestamp in seconds)
We welcome contributions to this project! If you have suggestions, improvements, or bug fixes, please follow these steps:
Fork the Repository
Create a personal copy of the repository by forking it on GitHub.
Create a New Branch
Create a new branch for your changes:
git checkout -b my-feature-branch
Make Your Changes
Implement your changes in the codebase.
Test Your Changes
Ensure that your changes work as expected and do not break existing functionality.
Submit a Pull Request
Push your changes to your forked repository and submit a pull request to the main repository.
If you need help or have questions about the Bloomreach Engagement Integration, please reach out to us:
This project is licensed under the MIT License.