JavaScript API

DCO Pixel > Set up with JavaScript API

πŸ“

This section refers to the Taboola DCO solution. For the standard e-commerce solution, see here.

Overview

This implementation method involves adding a JavaScript snippet directly to your website code.

Add the base code

Add the following base code to the <head> section of every page on your website. Replace ACCOUNT_ID with the unique ID provided by your Taboola account manager.

<script type='text/javascript'>
  window._tfa = window._tfa || [];
  _tfa.push({notify: 'event', name: 'page_view', id: ACCOUNT_ID});
  !function (t, f, a, x) {
         if (!document.getElementById(x)) {
            t.async = 1;t.src = a;t.id=x;f.parentNode.insertBefore(t,f);
         }
  }(document.createElement('script'),
  document.getElementsByTagName('script')[0],
  '//cdn.taboola.com/libtrc/unip/ACCOUNT_ID/tfa.js',
  'tb_tfa_script');
</script>

Add event tracking code

To track specific user actions, add the relevant event code snippet to the appropriate pages. Before using the _tfa.push() event in a page, verify the events queue is initialized by calling:

window._tfa = window._tfa || [];

Then add the event tracking code. See the Tracking events section below for the specific code snippets and parameters for your industry.

🚧

Important

In case of implementing the pixel using JavaScript, it's important that ONLY the page_view event has notify: 'event'. All other events have notify: 'ecevent'.

Hashed user emails (mandatory)

For optimal DCO performance and accurate audience matching, you must include hashed user email addresses in your pixel events using the unified_id parameter.

🚧

Required for DCO

Hashed email addresses are mandatory for DCO campaigns. They enable better user identification and personalization while maintaining privacy through one-way SHA-256 encryption.

Example of hashed email in pixel event:

window._tfa.push({
  notify: 'event',
  name: 'page_view',
  id: ACCOUNT_ID,
  unified_id: '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b'
});
πŸ“˜

Complete implementation guide

For detailed instructions on how to hash email addresses, including JavaScript and PHP code examples, verification steps, and usage guidance, see our dedicated Email Hashing Guide.

Tracking events

The Taboola Pixel works by tracking user events on your site. While we use standard e-commerce event names for consistency, these can be mapped to a variety of user actions depending on your industry.

Required vs. Optional events: Each event is marked as Mandatory or Optional. Mandatory events are essential for DCO to function properly. Optional events help improve performance but are not mandatory.

General params

All events support the following parameters:

  • unified_id (recommended): Hashed user email for better user identification. See Hashing User Emails for implementation details.
  • additionalInfo (optional): Object containing additional metadata such as:
    • vipUser: "true" or "false" - Indicates VIP customer status
    • bestSeller: "true" or "false" - Flags bestselling products
    • custType: 0 or 1 - Identifies returning (0) or new (1) customers

Special requirements:

  • SEARCH and CATEGORY_VIEW events: Include the first 5 product IDs from the search results or category listing.
  • SEARCH events: Include a searchTerm parameter with the user's search query.

Events

Select your industry below to see relevant examples and code snippets for each event.

This is the baseline implementation. The event names and descriptions are standard for retail and e-commerce platforms.

Mandatory events

Event

Description

Integration example

PRODUCT_VIEW

Visiting a product page.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'PRODUCT_VIEW',
  unified_id: hashed_email,
  productIds: ['product_id'],
  currency: 'USD'
});

ADD_TO_CART

Adding one or more products to the cart.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'ADD_TO_CART',
  unified_id: hashed_email,
  productIds: ['product_id_1', 'product_id_2']
});

PURCHASE

A purchase was completed.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'PURCHASE',
  unified_id: hashed_email,
  orderId: 'order_id',
  currency: 'USD',
  value: 123.45,
  cartDetails: [
    {productId: 'product_id_1', quantity: 1, price: 50.00},
    {productId: 'product_id_2', quantity: 2, price: 36.73}
  ],
  additionalInfo: {
    vipUser: 'true',
    custType: 0
  }
});

Optional events

These events are not strictly required, but sending as many as possible will improve the performance of the product recommendation algorithm.

Event

Description

Integration example

SEARCH

A search results page was displayed to the user. Send the first 5 product IDs of the search result.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'SEARCH',
  unified_id: hashed_email,
  productIds: ['product_id_1', 'product_id_2', 'product_id_3', 'product_id_4', 'product_id_5'],
  searchTerm: 'search term'
});

CATEGORY_VIEW

A product list or category page was displayed to the user. Send the first 5 product IDs on the page.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'CATEGORY_VIEW',
  unified_id: hashed_email,
  productIds: ['product_id_1', 'product_id_2', 'product_id_3', 'product_id_4', 'product_id_5'],
  category: 'category name',
  categoryId: 'category_id'
});

HOME_PAGE_VISIT

The user visited the homepage.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'HOME_PAGE_VISIT',
  unified_id: hashed_email
});

CHECKOUT

The checkout flow started.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'CHECKOUT',
  unified_id: hashed_email,
  productIds: ['product_id_1', 'product_id_2']
});

REMOVE_FROM_CART

One or more products were removed from the cart.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'REMOVE_FROM_CART',
  unified_id: hashed_email,
  productIds: ['product_id']
});

ADD_TO_WISH_LIST

One or more products were added to a wishlist.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'ADD_TO_WISH_LIST',
  unified_id: hashed_email,
  productIds: ['product_id']
});

REMOVE_FROM_WISH_LIST

One or more products were removed from a wishlist.

window._tfa.push({
  id: ACCOUNT_ID,
  notify: 'ecevent',
  name: 'REMOVE_FROM_WISH_LIST',
  unified_id: hashed_email,
  productIds: ['product_id']
});

What's next?

After implementing the JavaScript pixel code, validate that your pixel is firing correctly.