Web experiment triggers, targeting sources and product recommendations
## Activation triggers
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_triggerin 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) andmanual.manualwaits forlucida.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-triggersandGET|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: trueon 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__,prototypeandconstructorare refused.Nothing is read or sent before analytics consent.
Product recommendations
Turn recommendations on under Product recommendations > Settings. Pick the view event and the purchase event (defaults
$product_viewedand$purchase), the item id property (defaultitem_id) and the lookback.Fill the catalog. It comes from view events (
name,image_url,price,categoryproperties 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.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.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_shownand$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.