Website tracking (tag and events)
B4ker's measurement tag installs as a single script and feeds Insights, session replay and your campaign attribution. It only collects on the origins and paths authorized in the project's installation.
1. Install the tag
Under Settings → Measurement → Installation, copy the project's snippet and paste it once into the site's <head> (or your global layout). It already carries your project's data-baker-site:
<scriptdefersrc="https://tracking.b4ker.io/sdk/v1/tag.js"referrerpolicy="no-referrer"data-baker-site="site_YOUR_ID"data-baker-replay="true"></script>
Installing the tag is the decision to measure — there is no consent step in the SDK. Collection starts at load and only happens on the origins, paths and events authorized in the project policy.
If your legal basis depends on a cookie banner, the decision is whether to inject the script: load it only after the person accepts. To stop a tag that is already running (someone turning the option off mid-visit):
window.baker.stop(); // aborts sends, drops the queue and the session
stop() has no undo on this page: to measure again, load the tag on the next navigation.
data-baker-replay="true" is the site's permission for replay. What actually records is the project policy — drop the attribute if you never want recording, whatever the policy says.
2. Confirm it is live
baker:configured marks the tag's lifecycle: the project policy arrived, and from there on track and observe are accepted.
window.addEventListener("baker:configured", () => {console.log("B4ker session:", window.baker.sessionRef());}, { once: true });
page_view is automatic, including SPA navigation (pushState, replaceState and the back button).
3. Fire events
On clicks, without writing JavaScript
Mark the element with data-baker-event:
<button data-baker-event="cta_clicked" data-baker-element-id="hero">Book a demo</button>
From code
window.baker.track("cta_clicked", { featured: true });
When a section comes into view
observe fires the event after the element stays at least 50% visible for 1 second, once per path-and-properties combination. Keep the return value to stop observing:
const stop = window.baker.observe(document.querySelector("#pricing"),"section_viewed",{ section_id: "pricing" },);
Every event must be declared in the project's installation. The tag silently drops any event, path or property outside the policy — that is what guarantees your site never sends unplanned data. If a
tracknever reaches Insights, check the event name, the path and the property types.
Accepted properties
Each property is declared with a type: enum (a closed list of values), boolean, integer or number. There is no free-text property — for textual values, declare an enum. An undeclared property, or one whose type differs from the declaration, invalidates the whole event.
The name page_view is reserved: it belongs in the policy, never in track.
4. Server-confirmed conversions
Business metrics (approved sale, confirmed appointment) never leave the browser: a browser can lie, and the conversion key is a secret. Send them from your backend, tied to the sessionRef() you stored on the front end:
await fetch("https://tracking.b4ker.io/v1/conversions", {method: "POST",headers: {"Content-Type": "application/json",Authorization: `Bearer ${process.env.BAKER_CONVERSION_KEY}`,},body: JSON.stringify({event_name: "appointment_confirmed",conversion_id: appointment.id,session_ref: appointment.bakerSessionRef,}),});
Never expose BAKER_CONVERSION_KEY in the browser, in a public repository or in GTM. The tag's site_id is public; the conversion key is not.
5. Campaign attribution
To tie a paid click to the session, add these parameters to your Meta ads' destination:
bkr_campaign_id={{campaign.id}}&bkr_adset_id={{adset.id}}&bkr_ad_id={{ad.id}}
6. Session replay and privacy
Replay is decided by the project policy, not by the snippet — the same single tag covers every case. While it is active, the recording already excludes:
checkout,payment,login,accountandadminpaths;- forms, input fields,
iframe,canvas, video and audio.
You extend that from your own HTML:
data-baker-privateon the element — its content is masked in the recording.data-baker-private-pageanywhere on the page — nothing is recorded there.
To turn replay off from code while keeping measurement:
window.baker.init({ sessionReplay: false });
Common problems
- Nothing shows up in Insights — the site's origin has to be authorized in the installation, and the path has to be in the allowed path list.
trackrecords nothing — undeclared event, a path outside the policy, or a property with the wrong type.- Installed through GTM — restrict the trigger to the authorized origins and fire the tag exactly once per page.
- Two snippets on one page — the tag ignores the second installation; remove the duplicate.