| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
// Hook to add a custom JavaScript script in the head of every page |
| 8 |
|
| 9 |
require_once 'common.php'; |
| 10 |
|
| 11 |
$tabpx_account_id = tabpx_get_account_id(); |
| 12 |
|
| 13 |
if (!empty($tabpx_account_id)) { |
| 14 |
add_action('wp_head', 'tabpx_add_pixel_to_head'); |
| 15 |
} |
| 16 |
|
| 17 |
function tabpx_add_pixel_to_head() |
| 18 |
{ |
| 19 |
$tabpx_account_id = tabpx_get_account_id(); |
| 20 |
$integration_type = tabpx_get_integration_type(); |
| 21 |
|
| 22 |
// Register and enqueue a dummy script first so we can add inline script to it |
| 23 |
wp_register_script('taboola-pixel-tracker', '', array(), '1.0.0', false); |
| 24 |
wp_enqueue_script('taboola-pixel-tracker'); |
| 25 |
|
| 26 |
// Add the Taboola pixel code as inline script |
| 27 |
$tabpx_script = " |
| 28 |
window._tfa = window._tfa || []; |
| 29 |
window._tfa.push({notify: 'event', name: 'page_view', it: '" . esc_js($integration_type) . "', id: " . esc_js($tabpx_account_id) . ", integration_version: '" . esc_js(tabpx_get_plugin_version()) . "'}); |
| 30 |
!function (t, f, a, x) { |
| 31 |
if (!document.getElementById(x)) { |
| 32 |
t.async = 1; |
| 33 |
t.src = a; |
| 34 |
t.id = x; |
| 35 |
f.parentNode.insertBefore(t, f); |
| 36 |
} |
| 37 |
}(document.createElement('script'), |
| 38 |
document.getElementsByTagName('script')[0], |
| 39 |
'//cdn.taboola.com/libtrc/unip/" . esc_js($tabpx_account_id) . "/tfa.js', |
| 40 |
'tb_tfa_script'); |
| 41 |
"; |
| 42 |
|
| 43 |
wp_add_inline_script('taboola-pixel-tracker', $tabpx_script); |
| 44 |
} |
| 45 |
|
| 46 |
?> |