Web experiment triggers, targeting sources and product recommendations

## Activation triggers

Embed
Preview of the card
<a href="https://lucidace.com/help/web-experiment-triggers-and-recommendations"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/6b05fc9e-adaa-439a-bfd5-051815d8f904/social-card.svg?v=3e7ae33eec8b" alt="Web experiment triggers, targeting sources and product recommendations" width="600" height="315"></a>

Activation triggers

A web experiment can wait for a trigger before it applies its changes and records $exposure. Visitors who never meet the trigger are never exposed, so they stay out of the results.

  • Pick the trigger in the experiment wizard (Targeting step). It is stored as lc_trigger in every variant payload: {"op": "and" | "or", "conditions": [...]}. Groups nest up to 3 levels and hold 1 to 20 conditions.

  • Condition types: time_on_page (seconds, up to 3600), time_in_session (seconds, up to 86400), pages_viewed (count, up to 100), scroll (percent, 0 to 100), exit_intent, element_visible (selector), custom_event (event, captured on this page) and manual.

  • manual waits for lucida.activateExperiment("<flag key>") from your code, which forces activation and re-applies the changes (useful for SPAs that re-render).

  • Saved triggers are reusable, project-wide definitions: GET|POST /v1/projects/{project}/experiment-triggers and GET|PATCH|DELETE /v1/projects/{project}/experiment-triggers/{id}. A variant that names {"lc_trigger": {"saved_id": "<id>"}} gets the saved definition copied in on save, and editing a saved trigger later does not change running experiments.

  • Once a flag activates, the SDK remembers it for the session (only after analytics consent), so later pages apply the changes straight away.

Custom code approval

When the project's experiment.custom_code policy requires approval, CSS, inserted HTML and JS changes are served only with the server's approval stamp:

  • Every flag save keeps a stamp only where the same code was approved before. Edited or new code loses its stamp until it is approved again. This covers scheduled changes, change requests, and copies to other projects (copies are re-stamped under the target project's policy).

  • The browser SDK skips any CSS, HTML or JS change without approved: true on the serving path.

Targeting sources

Project settings, SDK section, "Flag targeting sources": an allow-list of up to 50 cookies, JS globals (dot paths on window, like app.user.tier) and dataLayer keys (dot paths, the latest push wins).

  • The browser copies them into flag requests as $cookie/<name>, $global/<path> and $datalayer/<path> person properties, so flag conditions can target them.

  • Only strings (cut to 200 characters), numbers and booleans are copied. DOM nodes are never read through, so form field values cannot leak. __proto__, prototype and constructor are refused.

  • Nothing is read or sent before analytics consent.

Product recommendations

  1. Turn recommendations on under Product recommendations > Settings. Pick the view event and the purchase event (defaults $product_viewed and $purchase), the item id property (default item_id) and the lookback.

  2. Fill the catalog. It comes from view events (name, image_url, price, category properties and the page URL), from a CSV or JSON feed upload, from a synced warehouse table, or from items you edit by hand. Feed and manual items are never overwritten by event data.

  3. Create a placement (for example pdp) with a strategy (popular, trending, viewed_with, bought_with, recently_viewed), a limit and rules: exclude the current item, exclude out-of-stock items, same category only, and fill from popular items.

  4. Lists rebuild every hour (job recs.build). Use "Build now" to rebuild at once.

In the browser, add the recommendations module (exported from @lucida-analytics/browser, or the ./recommendations entry) to init:

const recs = await lucida.recommendations("pdp", { itemId: "sku-42" });
recs.items.forEach((item) => render(item, () => recs.clicked(item.item_id)));
  • The SDK calls the public endpoint GET /v1/recommendations?placement=&item_id=&recent=&exclude=&strategy=&limit= with the project key and records $recommendation_shown and $recommendation_clicked, with the placement, strategy, flag, variant, items and position.

  • To A/B test strategies, give a flag or experiment variant the payload {"lc_recs": {"placement": "pdp", "strategy": "bought_with", "limit": 6}}. Reading it records the $exposure. The placement's Stats tab shows shown, clicked and CTR for each strategy and variant.

  • Recently viewed items are kept in SDK storage and sent only after analytics consent.

Updated