docs & api reference
Everything, code-first.
Getting started and the verified API surface. Public, indexable, and ungated. Start with a first query in 60 seconds, then dive into the full reference.
Five layers, one instrument
profile
- whotraits
- whatbehaviors
- howaffinities
segment
- whymotives
- wheremilestones
- whenthresholds
collect at the base · calculate in the middle · syndicate from the top
Your first query in 60 seconds
Load Contexture first in your tag manager, then query yourself. That is the demo: one file, one surface, immediate context.
<!-- first tag in the container --> <script src="/assets/Contexture.js"></script> <script>console.log(CX.io("behavior", "visitorType"));</script>
The docs and API reference are free to read on this site under standard copyright. Deploying the library commercially requires a license. Read the license summary →
Getting started
These docs cover the library at the heart of the Contexture SDK. Contexture is a single client-side file. You self-host it and load it first in your tag manager, before any other tag. Namespace: window.Contexture, aliases CX and CXTR.
Install the library
<!-- first tag in the container --> <script src="/assets/Contexture.js"></script>
Reading context · io()
Contexture.io() returns the full assembled context across nine data groups. io(dataGroup) returns one group. io(dataType, dataName) returns one item; dataType is one of: meta, cookie, param, browser, location, document, data, behavior.
CX.io() //==> { metaData, cookieData, behavioralData, ... } CX.io("behavior", "totalPageViews") //==> "10" CX.io("param", "utm_campaign") //==> "spring_launch" CX.io("behavior") //==> { visit, sessionPageViews, ... }
Contexture.context is the same full object as io().
Lifecycle
Contexture.update() runs a new page-view calculation. Call once per page load, or on content change in a single-page app. It re-fires runtime events, extensions, and exports.
Contexture.export() triggers window.CXExport (also runs automatically after each calculation).
CX.send(url) sends a beacon (used inside CXExport for syndication).
Contexture.UUID is the anonymous visitor identifier.
Debug: load any page with ?CXdebug=1 for console logging.
CX.update(); // recalc on route change (SPA) CX.export(); // manually fire CXExport CX.UUID // anonymous visitor id
On this site, CX.consent() gates first-party persistence via the site bridge. See the privacy policy for the consent pattern.
Syndication · window.CXExport
Syndication is a global hook, not a library method. Define window.CXExport; Contexture runs it after every calculation (or fire manually with CX.export()).
// runs automatically after every calculation; also fire manually with CX.export() window.CXExport = function () { var url = 'https://data.mysite.io/log?' + CX.io('behavioral', 'params'); CX.send(url); // gate on consent; keep PII out of the URL };
Calculations · global hooks
Custom calculations hook into the calc lifecycle. The shipped library checks for window.CXcalculate, window.CXsessionCalc, and window.CXpageCalc.
window.CXcalculate = function () { /* after each page calc */ }; window.CXsessionCalc = function () { /* once per session */ }; window.CXpageCalc = function () { /* once per pageview */ };
track()
Records an engagement (a goal, a product view, a step). Pass an object with event, action, and optional data.
CX.track({ event: "click", action: "goal", data: { id: "newsletter" } });
Full reference: appendix a in the book and the debugger's window.documentation / window.queryExamples. P2: fuller pages for calculations, syndication, and privacy.