JavaScript Tag SDK | Kevel Audience
Including the Tag
In order to use the tag in a site, the following snippet is the minimum piece of code that should be included on the page. It should be added as close to the opening <head> tag as possible. This snippet only needs to be included once per page. Refer to Event Collection if unsure which <JAVASCRIPT_TAG_URL> to use for your system.
<script async src="<JAVASCRIPT_TAG_URL>"></script>
<script>
window.pcdpLayer = window.pcdpLayer || [];
window.pcdp = function(){pcdpLayer.push(arguments)};
</script>
Using the Tag
Tracking
pcdp("event", "track", {
"clientId": "velocidi",
"siteId": "velocidi.com",
"type": "pageView",
"title": "My page",
"pageType": "homepage",
"category": "Shopping"
});
Recommended parameters:
- clientId: The client id
- siteId: The site id
- type: The event type
The above parameters are recommended, but the data field can be composed by any number of attributes.
It is possible to explicitly provide an user ID using the following optional parameters:
- user: An object containing: (if defined, it will override the user id sent automatically via cookie)
- type: the type of the User Identifier
- id: the id of the user
pcdp("event", "track", {
"clientId": "velocidi",
"siteId": "velocidi.com",
"type": "pageView",
"title": "My page",
"pageType": "homepage",
"category": "Shopping",
"user": {
"type": "crm",
"id": "12345abc"
}
});
For more information about supported events and their required schemas see the Complete list of events by categories.
Activation
pcdp("event", "activation", {
"configId": "web"
});
Required parameters:
- configId: The string ID of the Activation Trigger.
Optional parameters:
- user: An object containing:
- type: the type of the User Identifier
- id: the id of the user
- reactivationDelay: delay (in milliseconds) until the second activation request is sent. If
0, no second activation request will be executed. Default value is5000milliseconds.
All other received data will be ignored.
CookieSync
pcdp("event", "cookiesync", {
"cookiesyncId": "cs1"
});
Required parameters:
- cookiesyncId: The string ID of the Cookiesync;
Optional parameters:
- uid: The string ID of the user in the 3rd Party Cookie provider.
Match
pcdp("event", "match", {
"providerId": "web",
"user": {
"type": "email_sha256",
"id": "d1df1acbdc99f3d0f80dc298471b0a2a01124e9371ea9e707805b19f4ffe8b6e"
}
});
Required parameters:
- providerId: The string ID of the Match Provider;
- user: An object containing:
- type: the type of the user identifier
- id: the id of the user
Optional parameters:
- configId: The string ID of the Activation Trigger to be used when "Allow extra iFrame Activations" is enabled for this Match Provider.
Observe
If you have a datalayer variable to which you push your e-commerce events, such as with Google's Enhanced Ecommerce, you can leverage the observe method. The observe method allows you to define a function to be executed for a given event type. This enables using a single tag to be included in all pages, that will react appropriately based on the events pushed to the datalayer.
The API for using the method is as follows:
pcdp(
"observe",
dataLayer,
observerConfig,
eventVariableName)
Required parameters:
- dataLayer: The
datalayervariable to observe, into which the events are being pushed. - observerConfig: The object with the configurations the observer uses. The keys are the event names and the values are the functions which will be triggered for each of these events. These functions receive the pushed event as a parameter.
Optional parameters:
- eventVariableName: The name of the variable where the event name is defined.
Advanced Usage
Configuring the Tag
The tag comes pre-configured with the correct hosts for your system as well if they're enabled based on your system configuration. However, you can override these values (E.g. use a host alias) in the following way:
// Overriding the hosts and whether they're enabled
pcdp("config", "track", {
"host": "track.override.com",
"enabled": false
});
pcdp("config", "match", {
"host": "match.override.com",
"enabled": true
});
pcdp("config", "activation", {
"host": "activation.override.com",
"enabled": false,
"reactivationDelay": 1000
});
pcdp("config", "cookiesync", {
"host": "cookiesync.override.com",
"enabled": true
});
Setting Default Data Attributes for Each Event Type
Using the set action, the tag enables configuring default data attributes to be sent for all events of a specific type.
// Set default parameters for the 'track' event type
pcdp("set", "track", {
"clientId": "foo",
"siteId": "bar"
});
pcdp("event", "track", {
"type": "pageView",
"title": "My page",
"pageType": "homepage",
"category": "Shopping"
});
// Set default parameters for the 'match' event type
pcdp("set", "match", {
"providerId": "foo"
});
pcdp("event", "match", {
"user": {
"type": "email_sha256",
"id": "d1df1acbdc99f3d0f80dc298471b0a2a01124e9371ea9e707805b19f4ffe8b6e"
}
});
// Set default parameters for the 'activation' event type
pcdp("set", "activation", {
"containerId": "foo"
});
pcdp("event", "activation", {
});
// Set default parameters for the 'cookiesync' event type
pcdp("set", "cookiesync", {
"cookiesyncId": "foo"
});
pcdp("event", "cookiesync", {
"uid": "694cff55-814b-46c3-b95f-89dbab0f53fc"
});