Engagement Adapter Pattern
The adapter pattern decouples analytics components from vendor-specific event APIs. Components call a generic interface and the adapter translates those calls into the vendor’s API. Storefront Next provides two built-in adapters for analytics event tracking that use Einstein and Active Data.
| Adapter | Purpose | Config key |
|---|---|---|
| Einstein | Analytics event tracking (viewProduct, addToCart, etc.) | engagement.adapters.einstein |
| Active Data | Analytics event tracking (dwac beacon) | engagement.adapters.activeData |
Both implement the EngagementAdapter interface and are registered in a shared store.
A Map<string, EngagementAdapter> with functional accessors:
Adapter code is dynamically imported to stay out of the initial bundle:
The dynamic import() means that the Einstein or Active Data implementation modules are code-split into a separate chunk.
Adapters are configured in config.server.ts under engagement.adapters:
If an adapter’s enabled flag is false, it isn’t registered.
- Create
src/lib/adapters/engagement/your-adapter.tswith a factory function returningEngagementAdapter. - Register it in
src/lib/adapters/engagement/register.tsinsideinitializeEngagementAdapters(). - Add configuration under
engagement.adapters.yourAdapterinconfig.server.ts.