Guides
Log In
Guides

Measuring HP4U swap yourself

Tracking HP4U events in your analytics solution

Overview

As a publisher, you may want to track HP4U events within your own tracking system. You can track HP4U at different levels of granularity:

  1. Page tracking: Track page views where HP4U swap is enabled.
  2. Page region tracking: Track swap activity for a given region on your homepage.
  3. Page item tracking: Track swap activity for a given item on your homepage.
  4. User-session tracking: Track if an article was reached via a swapped item.

Page tracking

Allows you to track page views where HP4U swap was enabled.

Sample use cases include: tracking how many users interact with HP4U, performing user segmentation, etc.

Callback function

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

function swapCallBack(data){
	// Your event handling code goes here
}
window._taboola = window._taboola || [];
_taboola.push({listenTo: 'hp4uEvents', handler :swapCallBack}); // Register the `swapCallBack` function

Callback params

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

{ 
  "is_swap": true // `true` = page is about to begin swapping
}

Page region tracking

You can leverage the HTML data attribute to identify page regions with HP4U swap activity.

Using an observer, you can check for the presence of the data-region-swapped="true" attribute on the HTML element that encompasses the page region.

The following example illustrates:

Item tracking

As above, you can leverage the HTML data attribute to identify page items with HP4U swap activity.

Using an observer, you can check for the presence of the data-region-swapped="true" attribute on the HTML element that wraps the item.

The following example illustrates:

Session tracking

Each time a user navigates to an article page from a swapped item, a query string (?tbref=hp) is appended to the article URL. Your analytics solution can track page views with this query param.

Example:

https://hp4u-demo.taboola.com/news/archdiocese-will-file-for-bankruptcy?tbref=hp