Skip to content
Longplay
Docs
Browse docs / Feature flags, experiments and events

Feature flags, experiments and events

Feature flags and experiments, event collection, URL redirect and visual experiments.

Markdown
API v1Updated

Prepare experiments and collection#

  • Create and publish the feature flag definition or experiment in the selected App/environment. Record its feature flag key and environment UUID. A commercial metering Feature UUID does not replace a feature flag key.
  • For Customer evaluation and event collection, issue a Customer Token with features:read and events:write on the backend and configure the browser Origin.
  • Enable the required behavior-event, experiment-exposure and feature-flag usage collection in that environment. Statistical results additionally need exposure sources, metrics and corresponding events.

Related: Customers and sessions

Read feature flags#

flags.tsTypeScript
import { createLongplay } from "@tinkerlandai/longplay-sdk"; const longplay = createLongplay({  baseUrl: "https://api.longplayai.com",  scope: { projectId: "<APP_UUID>", environment: "sandbox" },}); export async function loadFlags(  customerToken: string,  customer: { id: string; externalUserId: string | null },) {  longplay.identify(customerToken);  const identity = { id: customer.id, externalUserId: customer.externalUserId };  const flags = await longplay.features({ attributes: { ...identity, country: "CA" } });  const enabled = flags.getFeatureValue("new-checkout", false);  const unsubscribe = flags.subscribe(() => console.log(flags.isOn("new-checkout")));  longplay.track("Checkout Viewed", { source: "pricing" });  await longplay.flush();  return { enabled, stop: () => (unsubscribe(), flags.destroy()) };}
  • Pass id (the Customer UUID) and externalUserId so a user gets the same experiment variation everywhere.
  • Local feature flags read these two fields. Remote feature flags read the session's verified Customer, so the SDK leaves them out of the remote evaluation request.
  • setAttributes() replaces all attributes; keep these two fields on every update.
  • Backends can read and evaluate with getFeatures or evaluateFeatures (features:read).
  • When evaluateFeatures selects a customerId, leave id, externalUserId, createdAt, ageDays and subscription out of attributes. The Customer supplies them, and sending one returns INVALID_REQUEST naming the field.

Track events#

Event recording with an official SDK requires at least 0.10.20. POST /api/v1/events accepts only typed events with kind (custom, experiment_exposure or feature_usage); earlier SDKs cannot record events. Direct HTTP clients must implement the current typed request and per-event result contract and do not need an SDK.

track(name, properties) records a behavior event and flush() sends it. Experiment exposures and feature flag usage are recorded automatically; each kind can be turned on or off per environment in Console.

The example above evaluates new-checkout, tracks Checkout Viewed and calls flush(). Replace the key, event name and attributes with your business definitions. Call stop() and clear the Customer client on unmount or account changes.

Check evaluation and event results#

Results and troubleshooting
ObservationCheck
Always receives the defaultCheck the key, publication environment, targeting attributes and traffic conditions; a default value is not proof of assignment.
401 / 403Check the Customer Token, features:read/events:write, Origin and App/environment.
Events sent but no statistical resultDistinguish sending from acceptance, then check collection settings, event names, exposure linkage, metric configuration and data volume. A completed flush does not establish a statistical conclusion.

Results and troubleshooting

  • Always receives the default

    Check
    Check the key, publication environment, targeting attributes and traffic conditions; a default value is not proof of assignment.
  • 401 / 403

    Check
    Check the Customer Token, features:read/events:write, Origin and App/environment.
  • Events sent but no statistical result

    Check
    Distinguish sending from acceptance, then check collection settings, event names, exposure linkage, metric configuration and data volume. A completed flush does not establish a statistical conclusion.

Website experiments#

Load URL redirect and visual experiments on your pages without a credential. Copy the environment UUID from the experiment pages in Console.

experiments.tsTypeScript
import { createPageExperiments } from "@tinkerlandai/longplay-sdk/page";import { createVisualExperiments } from "@tinkerlandai/longplay-sdk/visual"; // The environment UUID is public; it selects published experiments and authenticates nothing.const redirects = createPageExperiments({ environmentId: "<ENVIRONMENT_UUID>", baseUrl: "https://api.longplayai.com" });const visual = createVisualExperiments({ environmentId: "<ENVIRONMENT_UUID>", baseUrl: "https://api.longplayai.com" }); export async function startExperiments() {  await Promise.all([redirects.start(), visual.start()]);}

Related operations#