Skip to content

JQSON and Orbee Context

The Web SDK provides context to model different parts of state, events, and common browser variables. Orbee also provides a query language for navigating this context in an easy, digestible format, especially when modeling parameters in JSON, rather than JavaScript.

Orbee Context

The Context is a way to provide a query-able format to all the major variables within the Web SDK. The below table maps out those variables, objects, and fields.

Key Type Description
$.event EventSpecWrapper or other the current event object, or datalayer input
$.state State the currently stored state in the datalayer
$.url URL the current URL
$.referrer URL the current page referrer URL

Core defined structures

There are core defined structures that are used within the Web SDK, and provided through the context variables. Each are detailed below.

Event Spec Wrapper

{
    event: "",      // the event action
    eventModel: {}  // the event spec definition of the event
}

Event Spec

{
    object: "",
    label: "",
    vendor: "",
    product: "",
    ...             // other fields provided by the event
}

State

{
    isNewVisit: false,
    isNewVisitor: false,
    optOut: {
        optedOut: false
    },
    user: {
        id: ''
    },
    pageview: {
        id: '',
        page: {
            url: URL{},     // document.location.href
            referrer: URL{} // document.referrer
        }
    },
    visit: {
        id: '',
        originalURL: URL{},
        originalReferrer: URL{},
        source: '',
        medium: '',
        campaign: '',
        stats: {
            firstSeenTstamp: '',
            currentVisitTstamp: '',
            lastVisitTstamp: '',
            visitCount: 4
        }
    }
}

URL

{
    scheme: 'http',
    host: 'google.com',
    port: '',
    path: '/search',
    query: {
        q: 'testing query'
    },
    fragment: '',
    raw: 'http://google.com/search?q=testing%20query'
}

JQSON

JQSON is a simple query language for querying JSON objects in JavaScript. Some simple examples are below (all examples use $, Orbee's context variable):

$.event.eventModel.label
$.event.event
$.url.path
$.event.eventModel.elements.*.id
$.event.eventModel.elements.0

The language utilizes JavaScript's simple usage of objects and arrays -- they both support the [] lookup syntax:

var a = {b: 2}

console.log(a['b']); // 2

var c = [4];

console.log(c[0]); // 4
console.log(c['0']); // 4