DataLayer Plugin

JavaScript integration with the Google Tag Manager dataLayer: Store information about the visitor in a remote frame so that it can be accessed from multiple origins.

Data is not stored to a server and can be destroyed by the visitor or the browser during cleanup.


AddFields

Adds one or more key-value fields to the remote storage for the visitor. Will be appended to the existing set of fields.

Usage

center('require', 'dataLayer');
center('dataLayer:addFields', { 'type': 'customer' });

Parameters

Name Type Required Description
command string yes ‘dataLayer:addFields’. May optionally be property targeted.
fields object yes Object of key-value strings to be added.
options object no Optional flags for the property. See table below.

Options

Name Type Default Description
complete function N/A Callback function once the command is complete. Invoked with the complete array of tags after the addition.
complete string N/A Will push the complete set of fields to the named DataLayer array when complete.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:addFields', { 'key': 'value' }, {
  complete: function(fields) {
    // all the fields
  }
});
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:addFields', { 'key': 'value' }, { complete: 'dataLayer' });
// all fields now pushed to `window.dataLayer`


RemoveFields

Removes one or more string field names from the remote storage for the visitor.

Usage

center('require', 'dataLayer');
center('dataLayer:removeFields', ['customer']);

Parameters

Name Type Required Description
command string yes ‘dataLayer:removeFields’. May optionally be property targeted.
fields array yes Array of field names to be removed.
options object no Optional flags for the property. See table below.

Options

Name Type Default Description
complete function N/A Callback function once the command is complete. Invoked with the complete array of tags after the addition.
complete string N/A Will push the complete set of fields to the named DataLayer array when complete.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:removeFields', ['example'], {
  complete: function(fields) {
    // all the fields
  }
});
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:removeFields', ['example'], {
  complete: 'dataLayer'
});
// all fields now pushed to `window.dataLayer`


GetFields

Gets the complete set of custom fields from the remote storage for the visitor.

Usage

center('require', 'dataLayer');
center('dataLayer:getFields', 'dataLayer');

Parameters

Name Type Required Description
command string yes ‘dataLayer:getFields’. May optionally be property targeted.
complete function OR string no Callback function or name of Tag Manager array to push the fields to.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:getFields', function(fields) {
  // all the fields
});
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:getFields', 'dataLayer');
// all fields now pushed to `window.dataLayer`


ClearTags

Clears all the custom fields from the remote storage for the visitor.

Usage

center('require', 'dataLayer');
center('dataLayer:clearFields');

Parameters

Name Type Required Description
command string yes ‘dataLayer:clearFields’. May optionally be property targeted.
options object no Optional flags for the property. See table below.

Options

Name Type Default Description
complete function N/A Callback function once the command is complete. Invoked with the complete array of tags after the addition.
complete string N/A Will push the complete set of fields to the named DataLayer array when complete.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:clearFields');
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:clearFields', 'dataLayer');
// all fields now pushed to `window.dataLayer`

AddTags

Adds one or more string tags to the remote storage for the visitor. Will be appended to the existing list of tags.

Usage

center('require', 'dataLayer');
center('dataLayer:addTags', ['customer']);

Parameters

Name Type Required Description
command string yes ‘dataLayer:addTags’. May optionally be property targeted.
tags array yes Array of strings to be added.
options object no Optional flags for the property. See table below.

Options

Name Type Default Description
complete function N/A Callback function once the command is complete. Invoked with the complete array of tags after the addition.
complete string N/A Will push the complete array of tags to the named DataLayer array when complete.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:addTags', ['example'], {
  complete: function(tags) {
    // all the tags
  }
});
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:addTags', ['example'], { complete: 'dataLayer' });
// all tags now pushed to `window.dataLayer`


RemoveTags

Removes one or more string tags from the remote storage for the visitor. Will be removed from the existing list of tags.

Usage

center('require', 'dataLayer');
center('dataLayer:removeTags', ['customer']);

Parameters

Name Type Required Description
command string yes ‘dataLayer:removeTags’. May optionally be property targeted.
tags array yes Array of strings to be removed.
options object no Optional flags for the property. See table below.

Options

Name Type Default Description
complete function N/A Callback function once the command is complete. Invoked with the complete array of tags after the addition.
complete string N/A Will push the complete array of tags to the named DataLayer array when complete.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:removeTags', ['example'], {
  complete: function(tags) {
    // all the tags
  }
});
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:removeTags', ['example'], {
  complete: 'dataLayer'
});
// all tags now pushed to `window.dataLayer`


GetTags

Gets the complete set of string tags from the remote storage for the visitor.

Usage

center('require', 'dataLayer');
center('dataLayer:getTags', 'dataLayer');

Parameters

Name Type Required Description
command string yes ‘dataLayer:getTags’. May optionally be property targeted.
complete function OR string no Callback function or name of Tag Manager array to push the tags to.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:getTags', function(tags) {
  // all the tags
});
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:getTags', 'dataLayer');
// all tags now pushed to `window.dataLayer`


ClearTags

Clears all the string tags from the remote storage for the visitor.

Usage

center('require', 'dataLayer');
center('dataLayer:clearTags');

Parameters

Name Type Required Description
command string yes ‘dataLayer:clearTags’. May optionally be property targeted.
options object no Optional flags for the property. See table below.

Options

Name Type Default Description
complete function N/A Callback function once the command is complete. Invoked with the complete array of tags after the addition.
complete string N/A Will push the complete array of tags to the named DataLayer array when complete.

Examples

center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:clearTags');
center('create', '9999999999999999999999', 'foo');
center('require', 'dataLayer');
center('foo.dataLayer:clearTags', 'dataLayer');
// all tags now pushed to `window.dataLayer`