Script Tag
Lightweight browser SDK. No build step. Single script tag. Sends events via sendBeacon with XHR fallback.
Installation
<script src="https://cdn.wirelog.ai/public/wirelog.js" data-key="pk_your_public_key"></script>Script attributes
| Attribute | Required | Description |
|---|---|---|
data-key | Yes | Public API key (pk_...) |
data-host | No | API base URL. Falls back to inferring from script src. Only needed if CDN and API are on different hosts. |
data-consent | No | "true" to require optIn() before any tracking |
data-auto | No | "false" to disable automatic page_view on load |
data-spa | No | SPA navigation tracking. On by default. Set to "false" to disable. |
data-env | No | Choice result environment. Defaults to production. |
data-choice-seed | No | Stable choice assignment seed, usually your project ID. Defaults to the API key. |
Automatic behavior
- Tracks
page_viewon page load (unlessdata-auto="false") - SPA mode (on by default) intercepts
pushState,replaceState, andpopstateto firepage_viewon navigation. Disable withdata-spa="false". - Auto-injects event context on all tracked events:
url,language,timezone - Marks tracked events as
clientOriginated: true - Auto-captured
page_viewproperties include:url,previous_url,referrer,title,referring_domain, viewport/screen size, attribution params (utm_*,gclid,fbclid)
Batching and delivery
- Events queue locally, flush on 10 events or every 2 seconds
- Uses
navigator.sendBeaconfor reliable delivery on page close; falls back to XHR ifsendBeaconreturnsfalse - Flushes on
visibilitychange(hidden) andpagehide
Identity management
| Storage | Key | Persistence |
|---|---|---|
device_id | wl_did in localStorage | Permanent until reset() or optOut() |
session_id | wl_sid in sessionStorage | Reused in-tab, regenerated after 30 minutes of inactivity |
user_id | wl_uid in localStorage | Set via identify(), cleared via reset() |
Queue
- Capped at 500 events
- On overflow, oldest events are dropped (FIFO eviction)
API reference
Available as window.wirelog and window.wl.
wl.track(eventType, eventProps?, userProps?)
Track a custom event.
wl.track("button_click", { button: "signup" });
wl.track("purchase", { amount: 49.99, plan: "pro" }, { plan: "pro" });wl.identify(userId, userProps?, userPropOps?)
Set the user ID, persist it in localStorage, and send a POST /identify call.
wl.identify("alice@acme.org", { plan: "pro" });
wl.identify("alice@acme.org", null, { $set: { plan: "enterprise" }, $set_once: { signup_source: "organic" }, $add: { login_count: 1 }, $unset: ["legacy_flag"]});The user ID is attached to all subsequent track() calls until reset().
wl.reset()
Clear identity state. Use on logout.
wl.reset();Removes user_id, device_id, and session_id. Generates a new device_id.
wl.optIn()
Enable tracking and persist consent in localStorage (wl_consent).
wl.optIn();wl.optOut()
Disable tracking. Clears the event queue and all stored identifiers.
wl.optOut();wl.flush()
Manually flush the event queue.
wl.flush();Choices
choice() resolves synchronously, then records the exposure through the normal
async event queue. Call identify() first for user-level experiments, or
visitor() for anonymous device-level tests.
wl.identify("u_123");
const headline = wl.choice("landing_h1", [ { key: "welcome", value: "landing.h1.welcome" }, { key: "best", value: "landing.h1.best" },]);Weighted variants use { key, value, weight }. Use assignment() when you need
the selected variant key in application code.
For internationalized copy, keep variant key stable and translate the selected
value after assignment. choice_version ignores value, so translation edits
do not rebucket users while keys and weights are unchanged.
Use data-choice-seed to preserve assignments across API key rotation:
<script src="https://cdn.wirelog.ai/public/wirelog.js" data-key="pk_your_key" data-choice-seed="proj_your_project_id"></script>Consent mode
Set data-consent="true" on the script tag. No events are tracked or queued until optIn() is called. Consent state persists in localStorage across page loads.
<script src="https://cdn.wirelog.ai/public/wirelog.js" data-key="pk_your_key" data-consent="true"></script>
<script> // After user grants consent: wl.optIn();</script>