HP4U events

HP4U publishers can subscribe to events triggered during the swap lifecycle. Common uses cases include:

  • Swap tracking - Monitor when content swaps occur for analytics and optimization.
  • Custom analytics - Send swap events to your analytics platform for performance measurement.
  • A/B testing - Track swap performance compared to standard content delivery.
  • Revenue optimization - Measure the impact of header bidding swaps on user engagement.

Basic implementation

To subscribe to HP4U events, add the following code snippet to your HTML or JavaScript:

function callBack(data) {
    // Your custom code here
    console.log(data.detail);
}

window._taboola = window._taboola || []; 
_taboola.push({
    listenTo: 'hp4uEvents', 
    handler: callBack
});

The callback is triggered once the page receives a list of recommended items, and is about to begin swapping.

An example

function callBack(data) {
    if (data.detail.is_swap) {
        // Handle swap event
        console.log('Content swap detected');
        // Add your custom logic here
    }
}

window._taboola = window._taboola || []; 
_taboola.push({
    listenTo: 'hp4uEvents', 
    handler: callBack
});

The data passed to the swapCallBack function is a simple object with 1 field:

{ 
  "is_swap": true // `true` = page is about to begin swapping
}
๐Ÿ‘

Best practice

Always check for the existence of event data properties before using them, as the payload structure may evolve over time.

Available events

Currently, HP4U supports a single event:

EventDescriptionPayload
swap startedTriggered when a content swap begins (indicates this is a swap variant){ is_swap: true }
๐Ÿ“˜

Event payload

All HP4U events include an is_swap property that indicates whether the current content display is the result of a swap operation.

๐Ÿ‘

See also

Measuring HP4U Swap Yourself