ddl-json-schema
v2.0.0
Published
JSON Schema for the W3C Customer Experience Digital Data Layer
Downloads
4
Readme
What is the W3C Customer Experience Digital Data Layer?
The W3C Customer Experience Digital Data Layer is a specification that describes a method for exposing customer data through a global JavaScript object in a consistent manner that can be consumed by multiple vendors.
Why do I need this module?
If you are building a service that consumes the contents of the Digital Data Layer you may want to validate the data coming in and verify that it conforms to the expected format.
If you are building an ecommerce website that exposes the Digital Data Layer, you might have a test suite where you verify that the data you are exposing conforms to the expected format.
How do I install and use it?
npm install ddl-json-schema
var schema = require("ddl-json-schema");
schema.root;
// this is a schema defines the entire digitalData object
schema.attributes;
// this schema describes a valid attributes object
schema.security;
// this schema describes a valid security object or string
schema.category;
// this schema describes a valid category object
schema.product;
// this schema describes a valid product object
schema.price;
// this schema describes a valid price object
schema.address;
// this schema describes a valid address object
schema.date;
// this schema describes a valid date string
What's new?
In version 2.0.0 there is an API change in terms of what is exported as the module. Instead of exporting the overall digitalData schema as the default export, we now export schemas for a number of W3C Customer Experience Digital Data Layer components. This is meant to enable more granular validation, for instance if your api only receives a product object (or array) rather than the entire digitalData object, and you still want to validate these objects against the specification.
Looking for more information about the schema?
The window.digitalData
object may be extended in many ways. The objects in the specification are not required to be present, but if they are used they must adhere to the specified property names and types. On the global object the following names are reserved properties on the digitalData
object: pageInstanceID
, page
, product
, cart
, transaction
, event
, component
, user
, privacy
, version
.
| Reserved property | Type | Specification |
| ----------------- | -------- | --------------------------------------------- |
| pageInstanceID
| string
| |
| page
| object
| specification |
| product
| array
| specification |
| cart
| object
| specification |
| transaction
| object
| specification |
| event
| array
| specification |
| component
| array
| specification |
| user
| array
| specification |
| privacy
| object
| specification |
| version
| string
| |
Project logo created by Valeriy from the Noun Project.