Introduction
BeaconSDK is Criteo’s lightweight external JavaScript library that automates beacon tracking on web. It handles the entire beacon lifecycle (load, view, and click) so you don’t have to build or maintain a custom tracking logic. The result is faster integrations, cleaner data, and consistent measurement across all placements and products.For more information on the different levels of beacons, please check the ad tracking introduction page.
Quick Start
Criteo’s Delivery API returns unique beacon URLs for each placement and product (SKU). To start tracking with BeaconSDK using the new static JavaScript bundle, follow these steps:Add Beacon Attributes to your HTML tags
Each beacon URL returned by the Delivery API response must be attached to the corresponding HTML element using adata- attribute in the format data-criteo-[beacon-level]-[beacon-type]
[beacon-level] is one of product or placement, and [beacon-type] is one of onloadbeacon, onviewbeacon, onclickbeacon, onbasketchangebeacon, and onwishlistbeacon.Page Intelligence placements
Placements returned from the Page Intelligence/optimize endpoint use a StructuredBeacon object for onLoadBeacon instead of a plain URL string. To pass the payload to BeaconSDK, set data-criteo-placement-onloadbeacon to the url value and add one data-criteo-placement-onloadbeacon-payload-[key] attribute per entry in the payload object:
data-criteo-placement-onloadbeacon-payload-* attributes are present, BeaconSDK fires the beacon using navigator.sendBeacon(url, data) where data is the application/x-www-form-urlencoded string of all payload parameters.
The
data-criteo-placement-onloadbeacon-payload-* attributes apply only to placements from the /optimize endpoint. For placements from the Delivery API, use the standard data-criteo-placement-onloadbeacon attribute with the plain URL.Load BeaconSDK
At the end of your HTML document, before the closing the<body> tag, include the BeaconSDK bundle using the script tag:
Implementation Examples
Below are example implementations of BeaconSDK in different scenarios.Example 1: Basic integration
Here’s a simple example that uses only sponsored products and BeaconSDK to trackOnLoad, OnView, and OnClick events. We also added a simple JavaScript function to handle add-to-cart (OnBasketChange) and add-to-wishlist (OnWishlist) beacons.
Example 2: Dynamic content (lazy loading / SPA)
When placements are dynamically injected (e.g. infinite scroll or single-page applications), enable dynamic tracking:Example 3: Placement-level Tracking
This example shows a simplified implementation where only placement-level beacons are used.Example 4: Video Placement
This example demonstrates how BeaconSDK can be used with video placements.Usage
In its most basic form, BeaconSDK will automatically observe and track all HTML elements that include attributes matching the formatdata-criteo-[beacon-level]-[beacon-type]
BeaconSDK supports the following beacon types:
OnLoadBeacon— triggered as soon as the SDK detects the HTML element, regardless of its visibility in the viewport.OnViewBeacon— triggered when the element meets IAB’s Viewable Impression Guidelines.OnClickBeacon,OnBasketChangeBeacon, andOnWishlistBeacon— triggered by default when the corresponding HTML element is clicked.
navigator.sendBeacon() method.
All click events (
OnClickBeacon, OnBasketChangeBeacon, and OnWishlistBeacon) are tracked during the capture phase of the dispatched event. That ensure beacons will be sent even if client-side libraries use stopPropagation() in bubbling events.Dynamic Tracking
By default, BeaconSDK will only track HTML elements that are present in the DOM at the time the script is loaded. To enable dynamic tracking of elements added later, use thedata-dynamic-tracking="true" parameter on the script tag:
data-criteo-* pattern.
Restricting Tracking to a Specific Container
By default, the SDK observes all subnodes of the<body> element. If you want to restrict the tracking to a specific container or a shadow DOM root, you can specify a container using the data-container-selector attribute:
Tracking Organic Add-to-cart Events
BeaconSDK introduced support to track organic add-to-cart (ATC) events in version 5. Because add-to-cart events are not beacons, but API calls, it requires setting up a context with the necessary information to send the event correctly. For each page load:- Load BeaconSDK
- Set the organic context after the initial Delivery response
- Tag the organic add-to-cart controls
- (For testing purposes) Verify the
addToCartGET request in Network and/or console logs.
Setting the page-level context
The context can be set either using attibutes in BeaconSDK’s<script> tag or by calling the setOrganicContext interface.
Make sure BeaconSDK is loaded before setting the context.
Required fields
endpoint— Delivery base URL (e.g. https://d.us.criteo.com/delivery/retailmedia in AMER or https://d.eu.criteo.com/delivery/retailmedia in EMEA).partnerId— same value as criteo-partner-id.pageId— page-id used on the initial Delivery call, e.g.viewSearchResult_API_mobileorviewSearchResultApiMobile.
Recommended fields
If these fields are omitted, BeaconSDK will through warnings to the console, but it will still set the context.visitorId— same asretailer-visitor-id. Should only be omitted if the user opted out of tracking.pageUid— thepage-uidsent in the Delivery API response. Omitting this field will inflate the count of page views artificially.
Optional fields
customerId— same ascustomer-id. Should be sent if the shopper is logged in.authToken— if you use authentication tokens on Delivery calls, set the Bearer token. BeaconSDK usesfetch()with the headerAuthorization: Bearer <token>. If fetch isn’t available in the client, BeaconSDK will try to fall back to an image request, but it won’t be able to send the token, and it will log a warning.
Examples
Using thesetOrganicContext interface. Recommended for dynamic pages:
<script> tag. Recommended for static pages or Server-side Rendering (SSR):
setOrganicContext instead.
If you need to reload the organic context, for example, in Single Page Applications (SPAs), you can call
window.BeaconSDK.clearOrganicContext() and then, after the next Delivery response, you can call setOrganicContext again with the new context data.Tagging organic add-to-cart elements
Add the following attributes to the HTML element equivalent to the add-to-cart buttonRequired
data-criteo-organic-atc="true"data-criteo-item="<sku id>"data-criteo-price="<sku price>"
Optional
data-criteo-quantity="1". Defaults to 1. Should only be set if clicking on the button will add more than 1 item to the cartdata-criteo-parent-item="<parent sku id>". Set if you use parent sku ids (item_group_id) in your product feed.
Example
Do not use these attributes on sponsored products — for those, use the product beacon attributes as described in this page (e.g.
data-criteo-product-onbasketchangebeacon).What to verify
After callingsetOrganicContext (or adding the script-tag organic config), clicking a tagged organic ATC button should trigger a GET request to the configured endpoint with parameters including: event-type=addToCart, page-uid, item, price, and the optionals quantity and parent-item.
If you set authToken, the request should go via fetch with a header Authorization: Bearer <token>.
Debugging
BeaconSDK provides two tools to help debug your integration: a logger and a viewability visualizer.Tracking always runs whether or not debug is enabled.
Logging beacons
To help debug beacon tracking in your browser, you can enable debug logs. This can be done through the following ways:- Adding a cookie
criteo-viewability-debug=true
- Adding the parameter
data-debug="true"to the<script>tag
- Using the method
enableDebug()from theBeaconSDKinterface available after it is loaded
Criteo: sent [beacon-level]-[beacon-type] beacon:.
You can filter your browser console by the keyword Criteo to isolate these logs.

BeaconType: a string indicating the type of beacon sentBeaconURL: the URL that was called viasendBeacon()HTMLElement: the actual DOM element that triggered the beacon (hovering it in DevTools will highlight the element)
Universal Beacons
BeaconSDK will track Universal Beacons out of the box. The only difference being that there are no product-levelOnLoad beacons. When logging universal beacons to the console, BeaconSDK will show the beacon URL, the excluded SKUs, and the status codes.

Viewability visualizer
To help debug viewable impressions, i.e.,OnView beacons, BeaconSDK also provides a visualizer that will show a blue check mark for the placement-level OnView beacons and a green check mark for product-level OnView beacons for 2 seconds.

- Adding the parameter
data-visualizer="true"to the<script>tag
- Using setting the property
visualizerfrom theBeaconSDKinterface to true, after the bundle is loaded
Getting BeaconSDK
We offer three options to get started with BeaconSDK.Stable version via <script> tag (Recommended)
You can directly load BeaconSDK by adding the following <script> tag to your website:
<body> tag, just before the closing </body> tag. This ensures that the SDK loads after your page content. If your website dynamically loads content, see the section on Dynamic Tracking
The
/stable/ endpoint will always serve the minified code of the latest (stable) release. By using this endpoint you will auto-update your bundle without having to worry about versioning.Version-specific endpoints
If you need to lock BeaconSDK to a specific version, we also offer the following endpoints that can be used in thesrc parameter:
Major version
This version will include all minor-version updates automatically. These are updates that guarantee no backward compatibility breaks- Minimized bundle
- Expanded-code bundle
Minor version
This endpoint will not change it’s content once released.- Minimized bundle
- Expanded code bundle
OneTag Bundle
If you already use Criteo’s OneTag for Marketing Solutions or offsite campaigns, BeaconSDK can be automatically included via the OneTag bundle. Please consult your Technical Account Manager (TAM) to confirm whether your OneTag setup supports BeaconSDK and to enable it if needed.TypeScript NPM Package
If you prefer to integrate BeaconSDK directly into your build process, you can request the latest version of the npm package from your Technical Account Manager (TAM). See installation instructions below.Installing and Self-hosting
BeaconSDK can be provided as a compressed TypeScript package. Once transpiled, the library is compliant with both CommonJS and ES6+ environments. If you want to install and run BeaconSDK locally, ask your Technical Account Manager (TAM) for the package.Installation
- Run
npm installto ensure that TypeScript is installed in your project. - Download the
.tgzfile received from your TAM. It will be named in the format:criteo-beacon-sdk-x.y.z.tgz(wherex.y.zis the SDK version). - Move the
.tgzfile into your project directory. - Run:
Make sure to replace
x.y.zwith the actual version string.
Use the provided functions
You can then start using the functions provided by BeaconSDK:Placement-level beacon handler
ThePlacementLevelBeaconHandler class provides various methods for handling placement-level beacons. These beacons track user interactions with different ad placements.
triggerOnLoadBeacons(): sendsonLoadbeacons for elements with thedata-criteo-placement-onloadbeaconattribute. This method iterates over all elements with the specified attribute and sends a beacon for each element when the page loads.attachOnViewBeacons(): attaches beacons to placements with thedata-criteo-placement-onviewbeaconattribute. This method uses the IntersectionObserver API to monitor the visibility of ad placements and sends a beacon when an ad placement meets the viewability threshold according to IAB’s Viewable Impression Guidelines.attachOnClickBeacons([jsEvent]): attachesonClickbeacons to placements with thedata-criteo-placement-onclickbeaconattribute. If a JavaScript event is not provided, the default'click'event will be used.triggerOnClickBeacon(beaconUrl, element): sendsonClickbeacons for placement-level elements. You should use this method if you want to handle the click beaconing together with other routines. It should be called with the beacon URL when a user clicks on an ad placement. An optional element parameter can be used to associate the beacon with a specific element.triggerOnFileClickBeacon(beaconUrl, element): sends onFileClick beacons for placement-level elements. This method should be called with the beacon URL when a user clicks on a file within an ad placement. An optional element parameter can be used to associate the beacon with a specific element.triggerOnBundleBasketChangeBeacon(beaconUrl, element): sends onBundleBasketChange beacons for placement-level elements. This method should be called with the beacon URL when there is a change in the bundle basket within an ad placement. An optional element parameter can be used to associate the beacon with a specific element.
Product-level beacon handler
TheProductLevelBeaconHandler class provides various methods for handling product-level beacons. These beacons track user interactions with individual products (SKUs) within an ad unit.
triggerOnLoadBeacons(): sendsonLoadbeacons for elements with thedata-criteo-product-onloadbeaconattribute. This method iterates over all elements with the specified attribute and sends a beacon for each element when the page loads.attachOnViewBeacons(): attaches beacons to products with thedata-criteo-product-onviewbeaconattribute. This method uses the IntersectionObserver API to monitor the visibility of ad placements and sends a beacon when an ad placement meets the viewability threshold according to IAB’s Viewable Impression Guidelines.attachOnClickBeacons([jsEvent]): attachesonClickbeacons to placements with thedata-criteo-product-onclickbeaconattribute. If a JavaScript event is not provided, the click event will be used by default. The function will only attach to products loaded to the DOM with the specified attribute.triggerOnBasketChangeBeacon(beaconUrl, element)Tracks when a user adds or removes an item from their shopping cart. An optionalelementparameter can be used to associate the beacon with a specific element.triggerOnClickBeacon(beaconUrl, element)Tracks when a user clicks on a product within an ad unit. An optionalelementparameter can be used to associate the beacon with a specific element. You should use this method if you want to handle the click beaconing together with other routines.