Code:
<!-- Facebook Dynamic Remarketing Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'xxxxxxxx'); // Insert your pixel ID here.
fbq('track', 'PageView');
<?php
switch($_GET['main_page']) {
case 'shopping_cart': // Changed from FILENAME_SHOPPING_CART to 'shopping_cart'
case 'ajax_shopping_cart': // Changed from 'FILENAME_AJAX_SHOPPING_CART' to 'ajax_shopping_cart'
$products = $_SESSION['cart']->get_products();
$product_ids = array();
foreach ($products as $product) {
$product_ids[] = (int)$product['id'];
}
echo "fbq('track', 'AddToCart', {
content_ids: ['" . implode("','", $product_ids) . "'],
content_type: 'product',
value: " . number_format($_SESSION['cart']->show_total(), 2, '.', '') . ",
currency: '" . $_SESSION['currency'] . "'
});\n";
break;
case 'checkout_shipping': // Changed from FILENAME_CHECKOUT_SHIPPING to 'checkout_shipping'
case 'checkout_payment': // Changed from FILENAME_CHECKOUT to 'checkout_payment'
case 'quick_checkout': // Changed from 'FILENAME_QUICK_CHECKOUT' to 'quick_checkout'
case 'checkout_one': // Changed from 'FILENAME_ONE_PAGE_CHECKOUT' to 'one_page_checkout'
$products = $_SESSION['cart']->get_products();
$product_ids = array();
foreach ($products as $product) {
$product_ids[] = (int)$product['id'];
}
echo "fbq('track', 'InitiateCheckout', {
content_ids: ['" . implode("','", $product_ids) . "'],
num_items: " . (int)$_SESSION['cart']->count_contents() . ",
content_type: 'product',
value: " . number_format($_SESSION['cart']->show_total(), 2, '.', '') . ",
currency: '" . $_SESSION['currency'] . "'
});\n";
break;
case 'checkout_success': // Changed from FILENAME_CHECKOUT_SUCCESS to 'checkout_success'
if ($zv_orders_id > 0) {
if(!class_exists('order')) require_once DIR_WS_CLASSES . 'order.php';
$order = new order($zv_orders_id);
$products = $order->products;
$fbp_pids = array();
foreach ($products as $product) {
$fbp_pids[] = (int)$product['id'];
}
echo "fbq('track', 'Purchase', {
value: " . number_format($order->info['total'], 2, '.', '') . ",
currency: '" . $_SESSION['currency'] . "',
content_type: 'product',
content_ids: ['" . implode("','", $fbp_pids) . "']
});";
}
break;
case 'search_result': // Adding search tracking
if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
echo "fbq('track', 'Search', {
search_string: '" . addslashes($_GET['keyword']) . "'
});\n";
}
break;
default:
if (isset($_GET['products_id'])) {
echo "fbq('track', 'ViewContent', {
value: " . number_format(zen_get_products_special_price($_GET['products_id']), 2, '.', '') . ",
currency: '" . $_SESSION['currency'] . "',
content_type: 'product',
content_ids: ['" . (int)$_GET['products_id'] . "']
});\n";
}
break;
}
?>
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=xxxxxxxxx&ev=PageView&noscript=1"
/></noscript>
<!-- End Facebook Pixel Code -->
Bookmarks