Bloomreach
Send notifications and track engagement
Bloomreach Engagement Integration for Medusa v2
API Documentation | Bloomreach Website
Introduction
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:
- Send transactional emails using Bloomreach email templates or custom content.
- Send transactional SMS messages using Bloomreach SMS templates or raw text.
- Track customer events and behavior for analytics and personalization.
- Personalize notifications with dynamic data and customer information.
- Monitor notification delivery and engagement through Bloomreach analytics.
- Manage campaigns and templates directly in the Bloomreach dashboard.
Compatibility
This module/plugin is compatible with versions >= 2.4.0 of Copy to clipboard@medusajs/medusa.
Prerequisites
Before using this integration, you need:
- A Bloomreach (Exponea) account - Sign up at Bloomreach
- API credentials - You'll need:
- API Key ID - Found in your Bloomreach project settings
- API Secret - Found in your Bloomreach project settings
- Project ID - Your Bloomreach project identifier
- Integration ID - The ID of your email/SMS service provider integration
Getting Your Bloomreach Credentials
- Log in to Bloomreach at https://app.exponea.com/
- Navigate to Project Settings → Access Management → API
- Create a new API key (or use an existing one):
- Assign permissions: Campaigns > Transactional Email API, Campaigns > Transactional SMS API, and Events > Set
- Note down your Key ID and Secret
- Find your Project ID:
- Available in the URL when logged into your project
- Format: Copy to clipboard
https://app.exponea.com/project/{project-id}/...
- Get your Integration ID:
- Go to Project Settings → Channels → Email/SMS
- Select your email or SMS integration
- Copy the Integration ID from the URL or settings page
For more details, see the Bloomreach Authentication Documentation.
Installation
- Install the package
1npm install @igorppbr/medusa-v2-bloomreach-notification
- Add the module to your Copy to clipboard
medusa-config.ts
1234567891011121314151617181920import { 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",
Note: Adding the plugin is required for Medusa to load the event subscribers that handle notifications and analytics tracking.
- Add environment variables to your Copy to clipboard
.envfile
1234BLOOMREACH_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.
Configuration Options
Option Type Required Description Copy to clipboardkey_id string Yes Your Bloomreach API Key ID Copy to clipboardsecret string Yes Your Bloomreach API Secret Copy to clipboardproject_id string Yes Your Bloomreach Project ID Copy to clipboardintegration_id string Yes Your email/SMS integration ID Copy to clipboardfrom_email string Yes Default sender email address Copy to clipboardfrom_name string Yes Default sender name for emails Copy to clipboardfrom_sms string Conditional Required if using SMS channel - sender phone number Copy to clipboardlanguage string No Default language code (e.g., "en", "es") Copy to clipboardtransfer_identity string No Link tracking behavior: "enabled", "disabled", or "first_click" Copy to clipboardtemplate_mappings object No Map Medusa template names to Bloomreach template IDs Copy to clipboardcampaign_mappings object No Map template names to campaign names
Usage
Tracking Customer Events (Analytics)
Track customer behavior and events for analytics and personalization:
123456789101112131415import { 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"}})
Example: Tracking Order Events
Create a workflow to track order events:
1234567891011121314151617181920// 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",
Then create a subscriber to execute the workflow:
12345678910111213141516// 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",}
Sending Email Notifications
Once configured, you can send email notifications using the Notification Module:
123456789101112131415import { 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"}})
Sending SMS Notifications
12345678910111213import { 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"}})
Example: Order Confirmation Subscriber
Create a subscriber to send order confirmation emails:
1234567891011121314151617181920// 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 }})
Template Setup in Bloomreach
- Log in to Bloomreach and navigate to Campaigns → Email/SMS Templates
- Create a new template or use an existing one
- Note the Template ID from the URL or template settings
- Add personalization variables in your template using Jinja syntax:
1234Hello {{ first_name }},Your order #{{ order_number }} has been confirmed!Total: {{ order_total }}
- Map the template in your Copy to clipboard
medusa-config.tsusing Copy to clipboardtemplate_mappings
Features
Analytics Features
- ✅ Track custom events and user behavior
- ✅ Customer journey tracking
- ✅ Event properties and metadata
- ✅ Real-time event processing
- ✅ Integration with Bloomreach Engagement
Email Features
- ✅ Template-based emails with personalization
- ✅ Custom sender name and address
- ✅ Multi-language support
- ✅ Link tracking and analytics
- ✅ Campaign management
SMS Features
- ✅ Template-based SMS with personalization
- ✅ Raw text SMS messages
- ✅ Multi-language support
- ✅ Configurable message parts (1-8)
- ✅ Campaign tracking
Troubleshooting
Common Issues
Error: "API key is required in the provider's options"
- Make sure all required environment variables are set in your Copy to clipboard
.envfile - Verify that your Copy to clipboard
medusa-config.tscorrectly references the environment variables
Error: "From SMS is required in the provider's options to send SMS notifications"
- Add the Copy to clipboard
from_smsoption to your configuration if you're using the SMS channel
Email/SMS not being sent
- Check that your Bloomreach API credentials have the correct permissions
- Verify that your Integration ID is correct
- Check the Medusa logs for detailed error messages
- Ensure your templates exist in Bloomreach and template IDs are correct
Template not found
- Verify the template ID in your Copy to clipboard
template_mappingsconfiguration - Check that the template exists and is published in Bloomreach
API Reference
Bloomreach SDK Functions
This package includes a Bloomreach SDK with the following functions:
Copy to clipboardsendTransactionalEmail
Sends a transactional email through Bloomreach.
1234567891011121314151617const 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)
Copy to clipboardsendTransactionalSms
Sends a transactional SMS through Bloomreach.
12345678910111213141516const 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)
Copy to clipboardaddEvent
Tracks a customer event in Bloomreach.
1234567891011121314await 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)
Contributing
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:
1git 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.
Support / Contact
If you need help or have questions about the Bloomreach Engagement Integration, please reach out to us:
- Email: igorlmiura@gmail.com
- GitHub Issues: Submit an issue
License
This project is licensed under the MIT License.


