JavaScript Tag

The DMP provides a JavaScript Tag that facilitates the process of sending events from the browser to the DMP.

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 in the page.

<script async src="/path/to/pcdp.js"></script>
<script>
  window.pcdpLayer = window.pcdpLayer || [];
  window.pcdp = function(){pcdpLayer.push(arguments)};
</script>

The path/to/pcdp.js is system specific and should be replaced with the specific URL for your system.

Using the tag

Once that snippet is in the page, you can interact with the tag using the pcdp function. The function is structured in a way that always takes 3 parameters: pcdp(<action>, <event_type>, <data>).

Available actions are:

  • event: Create an event for a specific event type.
  • config: Configure settings for a specific event type.
  • set: Set default data to be included in each event.

Available event_types are:

  • track: Track user actions.
  • match: Match multiple user identifiers.
  • activation: Activate a user.
  • cookiesync: Perform cookie syncronization.

The required data to be passed are dependent of the previous parameters and are explained in detail in each event type's api.

Example of how to use the tag to capture a page view, match an user ID, make an activation request and doing a cookie sync request:

<script async src="/path/to/pcdp.js"></script>
<script>
  window.pcdpLayer = window.pcdpLayer || [];
  window.pcdp = function(){pcdpLayer.push(arguments)};

  // Track an event
  pcdp("event", "track", {
    clientId: "c1",
    siteId: "s1",
    type: "pageView",
    title: "My page",
    pageType: "homepage",
    category: "Shopping"
  });

  // Execute a match
  pcdp("event", "match", {
    providerId: "m1",
    user: {
      type: "email_hash",
      id: "23463b99b62a72f26ed677cc556c44e8"
    }
  });

  // Execute an activation
  pcdp("event", "activation", {
    configId: "m1"
  });

  // Execute a cookiesync
  pcdp("event", "cookiesync", {
    receiverId: "m1",
    uid: "694cff55-814b-46c3-b95f-89dbab0f53fc"
  });
</script>