Introduction
What the Widget Library is, why it exists, and the words used throughout this documentation.
This page explains what the Widget Library is, why it exists, and the words used throughout this documentation.
What Is This Library?
Section titled “What Is This Library?”Segmentify campaigns show widgets on a customer’s website: product recommendations, popups, banners and more. Until now the HTML, CSS and JavaScript of a widget were written by hand in the panel, per campaign.
The Widget Library is an npm package, @segmentify/widgets, that replaces that code. A widget in the library is a tested component. The panel no longer sends code to it; it sends data and settings.
Why It Exists
Section titled “Why It Exists”Code written in the panel cannot be reviewed or tested. In practice that meant:
- Almost every campaign carried its own copy of slider set-up, click tracking and add-to-basket code.
- A mistake in one copy only showed up on the customer’s live site.
- Anyone who could edit a campaign could run any JavaScript on a customer’s site.
A library turns each of those into something that is written once, tested, versioned and released.
What a Widget Is Responsible For
Section titled “What a Widget Is Responsible For”A widget owns its business flow. For the recommendation widget that means:
- deciding whether it may be shown at all (device, minimum number of products),
- drawing itself from the settings it was given,
- sending the events Segmentify measures: impression, widget view, click, slider arrows,
- adding a product to the basket through the site’s adapter.
It is not responsible for choosing products, for formatting prices or for talking to the Segmentify API. Those stay on the server and in @segmentify/integration.
Status
Section titled “Status”The library is being rebuilt from zero. The table shows what exists today.
| Part | Status |
|---|---|
| Contract: runtime interface and config schema | Draft, revision 2 |
| Conformance scenario format and runner | Done |
| Recommendation widget: display rules, events, slider, add to basket, favourites, rating, badges, discount, account-specific fields, texts by language, theme, “data only” delivery, extension hooks, list and compact layouts | Done, tested in happy-dom and Chrome |
Per-account extensions and basket / favourite adapters, in @segmentify/integration |
Planned |
Loading from @segmentify/integration |
Planned |
| Settings validation in Sauron, settings UI in the dashboard | Planned |
| React Native, iOS and Android renderers | Planned |
Words Used in These Pages
Section titled “Words Used in These Pages”| Word | Meaning |
|---|---|
| Widget | A component of this library that shows one kind of campaign. |
| Contract | The runtime interface, the config schema and the event protocol. The same on every platform. |
| Config | The data and settings one widget instance receives. JSON, with a schema version. |
| Runtime | The object that connects a widget to the outside world. On the web @segmentify/integration provides it. |
| Scenario | A JSON file that describes a config, some steps and the runtime calls that must follow. |
| Renderer | The implementation of a widget on one platform. |
| Native mode | The mode of @segmentify/integration in which it renders everything itself and the legacy web SDK is not loaded. The library only supports this mode. |
| Adapter | Per-account code, kept in a repository, that adds a product to that site’s own basket. |
Next Steps
Section titled “Next Steps”- To see how the parts fit together, read Architecture.
- To see what a widget may call, read Runtime Interface.
- To work on the library, start with Development.