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:

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:

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:

Optional parameters:

All other received data will be ignored.

CookieSync

pcdp("event", "cookiesync", {
  "cookiesyncId": "cs1"
});

Required parameters:

Optional parameters:

Match

pcdp("event", "match", {
  "providerId": "web",
  "user": {
    "type": "email_sha256",
    "id": "d1df1acbdc99f3d0f80dc298471b0a2a01124e9371ea9e707805b19f4ffe8b6e"
  }
});

Required parameters:

Optional parameters:

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:

Optional parameters:

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"
  });