B2Metric Web SDK · v1.0.1

Behavioral analytics for your website, in one line.

A lightweight, privacy-focused JavaScript library that tracks page views, sessions and custom events — with built-in A/B testing — and streams it all into B2Metric IQ.

One <script> tagPrivacy-focusedSPA-ready
index.html
<!-- Add to your site's <head> -->
<script
  src="https://tracker-fr-test.b2metric.com/b2m-web-sdk.js"
  data-apiKey="YOUR_API_KEY">
</script>
That's it — the SDK starts tracking automatically
yourstore.com
b2m · live events
page_view
/ · Home
AUTO
session_start
fp_abc123
AUTO
product_viewed
SKU-123
TRACK
experiment_exposure
checkout_v2 → B
EXP
add_to_cart
$299.99
TRACK

Quick start

From zero to first event in three steps

Drop in one script tag, optionally tune it with data-attributes, or take full control with a manual init.

index.html
<!-- Add to your site's <head> -->
<script
  src="https://tracker-fr-test.b2metric.com/b2m-web-sdk.js"
  data-apiKey="YOUR_API_KEY">
</script>
One line in your <head> — that's it

Capabilities

Everything you need to understand web behavior

Auto-tracking gives you a baseline the moment the script loads — then opt into exactly the event groups, experiments and custom events you need.

Zero-config

Auto-Tracking

Page views, sessions & SPA nav, for free.

The moment the script loads it tracks page views, builds a user fingerprint, manages sessions and follows single-page-app route changes — no code required.

10 groups

Event Tracking

Ten event groups. Activate only what you need.

Opt into modular groups — core, ecommerce, search and more — so you collect exactly the signals that matter and nothing you don't.

Custom Events

Go beyond the built-ins.

Send your own custom events with arbitrary parameters to capture the interactions unique to your product.

Experiments

A/B Testing & Experiments

Assign, cache and attribute — automatically.

A built-in client requests variant assignments from the experiments service, caches them on the device, and emits exposure events so behavior is attributed to the right variant.

Resilient

Offline Queue

Capture now, send when connected.

Events recorded while the browser is offline are queued locally and flushed automatically once the connection returns.

Platform Integrations

Drop into the stack you already run.

First-class guides for WordPress and other platforms get the tracker live on existing sites without touching application code.

Configuration

Configure once. Collect exactly what you need.

Every option is set on the script tag or passed to b2mInit(). Activate only the event groups that matter, tune batching, and point experiments wherever you run them.

ParameterTypeDefaultDescription
apiKeyREQstringRequiredYour API key
apiUrlstringProduction URLCollector API URL
batchSizenumber10Batch send size
sendIntervalnumber5000Send interval (ms)
sessionTimeoutnumber30Session timeout (minutes)
eventGroupsstring[]['core']Active event groups
debugbooleanfalseDebug mode
experimentApiUrlstring/experiments/assignA/B assignment endpoint
experimentCacheTtlnumber86400000A/B cache TTL (ms)
Event groupscoreecommercesearch+ 7 more
Script tag
<script
  src="https://tracker-fr-test.b2metric.com/b2m-web-sdk.js"
  data-apiKey="YOUR_API_KEY"
  data-event-groups="core,ecommerce">
</script>

Event data format

One consistent shape for every event

Auto-tracked or custom, every event is sent in the same structured format — ready for funnels, retention and flows in B2Metric IQ.

  • Every event has an event_name, ISO event_date and unix event_timestamp.
  • A session_id and fingerprint-based user_id tie events to a visitor.
  • event_params and user_params carry your context as key/value pairs.
page_view · event.json
{
  "event_name": "page_view",
  "event_date": "2025-01-15T10:30:00.000Z",
  "event_timestamp": 1736936200,
  "session_id": "session_1736936000_abc12345",
  "user_id": "fp_abc123def456...",
  "event_params": [
    { "key": "page_url", "value": "https://example.com" },
    { "key": "page_title", "value": "Home" }
  ],
  "user_params": [
    { "key": "fingerprint_id", "value": "abc123..." },
    { "key": "user_agent", "value": "Mozilla/5.0..." },
    { "key": "screen_resolution", "value": "1920x1080" }
  ]
}
<script src="b2m-web-sdk.js">b2mInit({ apiKey })

Ship your first insight today.

Add one script tag, paste your API key, and watch events arrive in B2Metric IQ in real time.