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.
ImportantIn case of implementing the pixel using JavaScript, it's important that ONLY the
page_view
event hasnotify: 'event'
. All other events havenotify: '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 DCOHashed 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 guideFor 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 statusbestSeller
:"true"
or"false"
- Flags bestselling productscustType
:0
or1
- Identifies returning (0) or new (1) customers
Special requirements:
SEARCH
andCATEGORY_VIEW
events: Include the first 5 product IDs from the search results or category listing.SEARCH
events: Include asearchTerm
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 |
---|---|---|
| Visiting a product page. |
|
| Adding one or more products to the cart. |
|
| A purchase was completed. |
|
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 |
---|---|---|
| A search results page was displayed to the user. Send the first 5 product IDs of the search result. |
|
| A product list or category page was displayed to the user. Send the first 5 product IDs on the page. |
|
| The user visited the homepage. |
|
| The checkout flow started. |
|
| One or more products were removed from the cart. |
|
| One or more products were added to a wishlist. |
|
| One or more products were removed from a wishlist. |
|
What's next?
After implementing the JavaScript pixel code, validate that your pixel is firing correctly.
Updated about 14 hours ago