the library
Contexture, the instrument.
A 6 KB, zero-dependency, source-available client-side library. One normalized surface to collect signals, calculate context, and syndicate it to the tools you already own.
Gzipped, loads first. Runs on every page without slowing it.
Dependencies, ever. No framework, no build step, no runtime to install.
Anonymous, consent-gated. Storage you and the visitor own.
PolyForm Noncommercial for personal use. Free to read; licensed to deploy commercially.
One line, first in your tag manager
You self-host the single file and load it as the first on-page snippet. It is stable by design: frozen, dependency-free, and it will never push a breaking change to a client site.
<!-- first tag in the container, before everything else --> <script src="/assets/Contexture.js"></script>
Read context with io()
Out of the box, Contexture assembles nine data groups into one query surface. Call io() for the full context, io(dataGroup) for one group, or io(dataType, dataName) for one item.
Contexture.io() //==> { metaData, cookieData, ... } CX.io("behavior", "totalPageViews") //==> "10" CX.io("param", "utm_campaign") //==> "spring_launch" CX.io("behavior") //==> { visit, sessionPageViews, ... } // CX and CXTR are aliases
Hook the calc lifecycle
Custom calculations are global hooks, not library methods. Define them once; Contexture runs them during the calc lifecycle. Record engagements with track() using the documented object form.
// record an engagement (goal, product view, step) CX.track({ event: "click", action: "goal", data: { id: "newsletter" } }); // custom calculation hooks (runs during calc lifecycle) window.CXcalculate = function () { /* after each page calc */ }; window.CXsessionCalc = function () { /* once per session */ }; window.CXpageCalc = function () { /* once per pageview */ };
source: appendix a and the debugger's window.documentation. Advanced calculation patterns (affinity, scoring, cart) are documented in the book and install per engagement.
Push context with window.CXExport
Syndication is a global hook, not a method. Define window.CXExport and the library runs it automatically 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 };
You already bought the testing tool. This makes it do things it couldn't.
The page-parameters seam, defined before at.js loads. Feed first-party affinities and scores into audiences Target could never compute on anonymous traffic.
// define before at.js loads (Ch 10) window.targetPageParamsAll = function () { return { "user.visitorType": CX.io("visitorType"), "user.visitCount": CX.io("visit"), "audience.highIntent": CX.io("audience.highIntent") }; };
Owned audiences and targeting inputs from persistent behavioral context, not just this-session signals (Ch 11).
window.CXExport = function () { window.optimizely = window.optimizely || []; window.optimizely.push({ type: "user", attributes: { visitorType: CX.io("visitorType") } }); };
Consistent custom dimensions and events from one source, exposed to every tag through the dataLayer (Ch 12).
window.CXExport = function () { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: "cx_context", cx_visitor_type: CX.io("visitorType"), cx_visit_count: CX.io("visit") }); };
One context, many tools, consistent segments. The beacon hook runs after every calculation (Ch 13).
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 };
source: ebook part iii, chapters 10 to 13.
The privacy model
Anonymous by default. An anonymous first-party UUID, behavioral attributes only, no PII, no third-party sharing. Storage and any beacon wait for consent, exactly as the book's privacy chapter prescribes. The ticker at the top of this page is that pattern, live.
Next steps
Read the full getting-started and API reference in the docs, or open the Toolkit to debug the calculation layer in isolation before you syndicate.
The library is free to read. Licensed to deploy.
PolyForm Noncommercial covers personal and noncommercial use. Commercial deployment requires a license. Read everything freely; license the library to deploy it commercially.