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. |
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();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>