- DDLToolsConfigResetOptions
DDLTools reset options.
- DDLToolsConfigLogger
A logger.
- DDLToolsConfigValidator
A digital data layer validator.
- DDLToolsConfigEmitEventsOptions
DDLTools DOM event emission options.
- DDLToolsConfig
DDLTools configuration object.
Kind: global class
See: https://www.w3.org/2013/12/ceddl-201312.pdf
- DDLTools
- new DDLTools()
- .reset() ⇒
object
- .set(path, value) ⇒
object
- .get(path, [defaultValue])
- .merge(path, source) ⇒
object
- .push(path, value) ⇒
object
- .publish(path) ⇒
Promise
- .validate() ⇒
boolean
- .configure() ⇒
object
- .use(plugin) ⇒
object
- .setPageInstanceId(value) ⇒
object
Provides digital data layer helper functions supporting data layer schema validation for highly-decoupled analytics reporting.
Empties the digital data layer prior to populating data for a new page. Provided for single-page apps to call during page-level widget initialization prior to populating new data in the data layer.
Kind: instance method of DDLTools
Returns: object
- - Self reference for chaining
Example
ddlTools.reset();
Updates or inserts a data layer entry at the given path
with the given
value
if the given path and value are valid for the data layer schema.
If the base path does not already exist, it will be created.
Kind: instance method of DDLTools
Returns: object
- - Self reference for chaining
Param | Type | Description |
---|---|---|
path | string | Array.<string> |
Where the data layer entry should reside |
value | mixed |
What the data layer entry should contain |
Example
ddlTools.set("page.pageInfo.pageID", "Nikon Camera");
Retrieves the data layer entry at the given path
if the given path
contains a value, or the default
value if a default value is specified
and the given path does not contain a value.
Kind: instance method of DDLTools
Param | Type | Default | Description |
---|---|---|---|
path | string | Array.<string> |
Where the data layer entry resides | |
[defaultValue] | mixed |
|
Optional value to return if the path does not contain a value |
Example
const pageId = ddlTools.get("page.pageInfo.pageID");
Example
const pageId = ddlTools.get("page.pageInfo.pageName", 'UnknownPage');
Deeply merges the data layer entry at the given path
with the given
value
if the given path and value are valid for the data layer schema.
If the base path does not already exist, it will be created.
Kind: instance method of DDLTools
Returns: object
- - Self reference for chaining
Param | Type | Description |
---|---|---|
path | string | Array.<string> |
Where the data layer entry should reside |
source | object |
Key/value pairs to merge |
Example
ddlTools.merge("transaction.profile", {
profileInfo: {
shippingAddress: {
line1: '1234 Test Dr',
city: 'Portland',
stateProvince: 'OR',
postalCode: '97211',
country: 'USA'
}
}
});
Adds a new data layer entry onto the end of an array at the path
given
within the digital data layer. If the base path does not already exist, it
will be created. If an array does not exist at the path given, a new array
will be created at the given path.
Kind: instance method of DDLTools
Returns: object
- - Self reference for chaining
Param | Type | Description |
---|---|---|
path | string | Array.<string> |
Where the data layer array resides within the data layer |
value | mixed |
The data to be added to the array |
Example
ddlTools.push("transaction.item", {
"productId": "N117MP9",
"sku": "N117MP9-31778",
"color": "blue"
});
With event emission enabled, dispatches a "publish" event. This is useful for some types of analytics event handling.
Kind: instance method of DDLTools
Returns: Promise
- - Promise to be resolved when publish is complete
Param | Type | Description |
---|---|---|
path | string |
Indicates what has been published |
Example
ddlTools.publish('page');
Validates the existing digitalData
object against the DDL Schema,
returning true upon success (digitalData
is valid), or false otherwise.
NOTE: It is not necessary to use this method for validating changes
caused by the DDLTools
objects -- those changes are already
validated. This method is for validating an initialized value of
digitalData
which is typically set by server-side processing.
Kind: instance method of DDLTools
Returns: boolean
- - Whether or not the digitalData
object
is valid
Example
window.digitalData = {
pageInstanceID: 'example-pageInstanceId',
invalidField: 'bad'
};
const ddlTools = new DDLTools(window.digitalData, ddlValidator);
if (!ddlTools.validate()) {
console.warn('`window.digitalData` is invalid');
}
Allows package consumers to customize the functionality of the other methods in this class.
Kind: instance method of DDLTools
Returns: object
- - Self reference for chaining
Params: object
options - The new settings to be used
Example
ddlTools.configure({
logger: specialLogger,
throw: true
});
Extends the DDLTools instance with the methods from the provided plugin.
Kind: instance method of DDLTools
Returns: object
- - Self reference for chaining
Param | Type | Description |
---|---|---|
plugin | object |
The plugin to use |
Example
const pagePlugin = require('ddl-tools-plugin-page');
ddlTools.use(page);
Example
const pagePlugin = require('ddl-tools-plugin-page');
const trxsPlugin = require('ddl-tools-plugin-transactions');
ddlTools.use(pagePlugin, trxsPlugin);
Sets the page instance identifier.
The Page Identifier is among the most widely used web analytics data properties. This value SHOULD distinguish among environments, such as whether this page is in development, staging, or production.
Kind: instance method of DDLTools
Returns: object
- - Self reference for chaining
Param | Type | Description |
---|---|---|
value | string |
value to set |
DDLTools reset options.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
include | Array.<string> |
Keys to be removed upon reset |
exclude | Array.<string> |
Keys to be ignored upon reset |
A logger.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
debug | function |
Function to call for non-critical logging |
error | function |
Function to call for critical logging |
A digital data layer validator.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
operationIsValid | function |
Function called to determine whether changing a property at a path specified to a value specified should be allowed. |
configure | function |
Function called to configure the validator. |
DDLTools DOM event emission options.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
eventPrefix | string |
String to prefix event names with |
publishPrefix | string |
String to prefix publish event names with |
resetName | string |
Name of reset events |
DDLTools configuration object.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
logger | boolean | DDLToolsConfigLogger |
Either true to enable logging with the default logger; false to disable logging; or an actual logger object with appropriate methods to use for logging (default: true). |
throw | boolean |
True if methods should throw an exception when an invalid operation is detected; false if exceptions should be ignored (default: false). |
verbose | boolean |
True to enable extra logging information; false to keep the console clean (default) invalid operation is detected; false if exceptions should be ignored (default: false). |
reset | DDLToolsConfigResetOptions |
Options customizing behavior when the reset method is called. |
validator | DDLToolsConfigValidator |
A digital data layer validator, such as the one presented by ddl-validator . |
emitEvents | boolean | DDLToolsConfigEmitEventsOptions |
Either true to enable automatic DOM event emission; false to disable the same; or a configuration object to enable and configure the same (default: false) |