JavaScript Tag

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: "c1",
siteId: "s1",
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.

For more information about supported events and their required schemas see the Complete list of events by categories.

note

Any provided information not part of the schema of the specific event type will be ignored. If you need to send additional information not part of a certain event type schema, review the customFields field which allows you to pass arbitrary data albeit with restricted capabilities to interact with the rest of system. If you need to track an event whose type doesn't fit any of the categories, consider using a Custom event as a last resource.

Activation#

pcdp("event", "activation", {
configId: "a1",
});

Required parameters:

Optional parameters:

  • user: An object containing:
  • reactivationDelay: delay (in milliseconds) until the second activation request is sent. If 0, no second activation request will be executed. Default value is 5000 milliseconds.

All other received data will be ignored.

note

Having a reactivationDelay is useful for first-time visitors and when the initial activation is triggered together with other tracking events. These tracking events update the user's profile which may cause the second request to activate more up-to-date information about the user.

Cookiesync#

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

Required parameters:

Optional parameters:

  • uid: The string ID of the user in the 3rd Party Cookie provider.

All other received data will be ignored.

Match#

pcdp("event", "match", {
providerId: "m1",
user: {
type: "email_sha256",
id: "23463b99b62a72f26ed677cc556c44e8"
}
});

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

Alternatively, you can match multiple user IDs in the same match request by defining user as an array of objects with the schema defined above. Example: user: [{type: "email_sha256", id: "id1"}, {type: "crm", id: "id2"}].

Optional parameters:

All other received data will be ignored.

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", {
// clientId: "foo", // No need to include as it will already be included
// siteId: "bar" // No need to include as it will already be included
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", {
// providerId: "foo", // No need to include as it will already be included
user: {
type: "email_sha256",
id: "23463b99b62a72f26ed677cc556c44e8"
}
});
// Set default parameters for the 'activation' event type
pcdp("set", "activation", {
containerId: "foo"
});
pcdp("event", "activation", {
// configId: "foo" // No need to include as it will already be included
});
// Set default parameters for the 'cookiesync' event type
pcdp("set", "cookiesync", {
cookiesyncId: "foo"
});
pcdp("event", "cookiesync", {
// cookiesyncId: "foo", // No need to include as it will already be included
uid: "694cff55-814b-46c3-b95f-89dbab0f53fc"
});
Last updated on