A TypeScript-based ecommerce events tracker that integrates with Salla's analytics platform. This package provides a comprehensive set of event listeners for tracking various Salla ecommerce activities based on Segment's ecommerce v2 specification.
The Store Events Tracker automatically registers with Salla's analytics system and provides event handlers for all major ecommerce events. It uses a plugin-based architecture where individual event listeners are automatically discovered and registered.
- 🚀 Automatic Registration: Seamlessly integrates with Salla's analytics platform
- 📊 Comprehensive Event Coverage: Supports 25+ ecommerce events
- 🔧 TypeScript Support: Full type safety with TypeScript definitions
- 🎯 Modular Architecture: Individual event listeners for easy customization
- 🛡️ Error Handling: Built-in error handling for robust tracking
- 📦 Auto-Discovery: Automatic listener registration via build-time discovery
src/
├── index.ts # Main entry point and tracker registration
└── listeners/ # Event listener implementations
├── product-viewed.ts # Product viewing events
├── cart-viewed.ts # Shopping cart events
├── order-completed.ts # Order completion events
└── ... (22+ more listeners)product-viewed.ts- Product page viewsproduct-clicked.ts- Product link clicksproduct-added.ts- Add to cart actionsproduct-removed.ts- Remove from cart actionsproduct-reviewed.ts- Product reviewsproduct-shared.ts- Product sharingproduct-list-viewed.ts- Category/list viewsproducts-searched.ts- Search queries
cart-viewed.ts- Shopping cart viewscheckout-started.ts- Checkout initiationcheckout-step-viewed.ts- Checkout step viewscheckout-step-completed.ts- Checkout step completionpayment-info-entered.ts- Payment information entry
order-completed.ts- Order completionorder-updated.ts- Order modificationsorder-cancelled.ts- Order cancellationsorder-refunded.ts- Order refunds
coupon-entered.ts- Coupon code entrycoupon-applied.ts- Successful coupon applicationcoupon-denied.ts- Failed coupon attemptscoupon-removed.ts- Coupon removal
promotion-viewed.ts- Promotion displayspromotion-clicked.ts- Promotion interactions
wishlist-product-added.ts- Add to wishlistwishlist-product-removed.ts- Remove from wishlist
- Initialization: The tracker registers with Salla's analytics system when the SDK is ready
- Event Discovery: Build-time plugin discovers all listener files and generates an auto-registry
- Event Handling: When events occur, the tracker routes them to the appropriate listener
- Error Handling: Any listener errors are caught and logged without breaking the flow
Each event listener follows a consistent pattern:
import { EventPayload, EcommerceEvents } from '@salla.sa/ecommerce-events-base';
export const eventName = EcommerceEvents.EVENT_NAME;
export default (payload: EventPayload): void => {
console.log('EVENT NAME:', payload);
// Add your custom tracking logic here
// Example: Send to Google Analytics, Facebook Pixel, etc.
};To add custom tracking logic to any event, simply modify the corresponding listener file:
// src/listeners/product-viewed.ts
export default (payload: ProductViewedPayload): void => {
console.log('PRODUCT VIEWED Event:', payload);
// Send to Google Analytics
gtag('event', 'view_item', {
item_id: payload.product_id,
item_name: payload.name,
currency: payload.currency,
value: payload.price
});
// Send to Facebook Pixel
fbq('track', 'ViewContent', {
content_ids: [payload.product_id],
content_type: 'product',
value: payload.price,
currency: payload.currency
});
};To add a new event listener:
- Create a new file in the
listeners/directory - Export the
eventNameand default handler function - The build system will automatically discover and register it
@salla.sa/ecommerce-events-base- Base types and event definitions- Salla Twilight SDK - Required for integration with Salla's platform
This tracker is designed to work with Salla's ecommerce platform and requires the Salla Twilight SDK to be loaded before initialization.
// The tracker automatically registers when Salla Twlight SDK is ready
window.Salla.onReady(() => {
// Tracker is now active and listening for events
});The tracker includes built-in error handling:
- Validates Salla Twlight SDK availability
- Catches and logs individual listener errors
- Continues processing other events even if one fails
The package uses TypeScript for type safety and includes:
- Full type definitions for all event payloads
- Auto-completion support in IDEs
- Compile-time error checking
- Node.js (version 16 or higher)
- pnpm (recommended) or npm
- Clone the repository:
git clone <repository-url>
cd store-events-tracker-starter-kit- Install dependencies:
pnpm install- Start development server:
pnpm devThis starts the Vite development server with hot reload
- Build for production:
pnpm buildCompiles TypeScript and bundles the project
- Preview production build:
pnpm previewServes the production build locally for testing
- Type checking:
pnpm type-checkRuns TypeScript compiler to check for type errors
- Start the development server:
pnpm dev-
Open
example.htmlin your browser or visit the local server URL -
Open browser developer tools to see event tracking in the console
-
Interact with the page to trigger events and verify your listeners are working
store-events-tracker-starter-kit/
├── src/
│ ├── index.ts # Main entry point
│ ├── auto-listeners-registry.ts # Auto-generated listener registry
│ └── listeners/ # Event listener implementations
├── example.html # Example implementation
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
├── vite.config.ts # Vite build configuration
└── README.md # This file-
Create a new TypeScript file in
src/listeners/ -
Follow the established pattern:
import { EventPayload, EcommerceEvents } from '@salla.sa/ecommerce-events-base';
export const eventName = EcommerceEvents.YOUR_EVENT_NAME;
export default (payload: EventPayload): void => {
console.log('YOUR EVENT:', payload);
// Add your custom logic here
};-
The build system will automatically discover and register your new listener
-
Test your changes using the development server
- Use browser developer tools to inspect console logs
- Check the Network tab for any failed requests
- Verify that the Twilight SDK is properly loaded before the tracker initializes
- Use TypeScript's type checking to catch errors early:
pnpm type-check
Once you've customized your event listeners and tested your tracker locally, you can publish it as a Salla app to make it available to merchants. Follow these steps to publish your tracker:
- Visit https://portal.salla.partners/
- Sign in with your Salla Partners account
- Create a new app and configure its basic settings
- Note down your app's details for the next steps
- Build your tracker for production:
pnpm buildThis creates a dist/tracker.js file containing your compiled tracker
-
Upload the
dist/tracker.jsfile to your preferred CDN service (e.g., AWS CloudFront, Cloudflare, or any other CDN) -
Make note of the CDN URL where your
tracker.jsfile is hosted
- In the Salla Partners Portal, navigate to your app
- Go to the "Snippet" section
- Add a new Snippet with the CDN URL of your
tracker.jsfile
- Install your app in the demo store provided by Salla Partners Portal
- Navigate through the demo store and perform various actions (view products, add to cart, checkout, etc.)
- Open browser developer tools and check the console to verify your event listeners are working correctly
- Test all the events you've customized to ensure they're tracking properly
- Once you've verified everything works correctly in the demo store
- Return to the Salla Partners Portal
- Navigate to your app and publish the changes
- Your tracker will now be available for merchants to install and use
- Testing: Always thoroughly test your tracker in the demo store before publishing
- Performance: Ensure your tracker doesn't negatively impact store performance
- Error Handling: The built-in error handling ensures individual listener failures don't break the entire tracking system
- Updates: When you make changes to your tracker, repeat the build and upload process, then update the snapbit URL if necessary
- Events not firing: Check that the Salla Twilight SDK is properly loaded before your tracker
- Console errors: Review your event listener implementations for any JavaScript errors
- Missing events: Verify that all your custom event listeners are properly exported and follow the correct pattern
MIT License - See the main project license for details.