我正在尝试将Facebook跟踪像素添加到我的Woocommerce结帐页面。
<head>
<!-- Facebook Conversion Code for GRC Domains - Domain Purchase -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '6019759883360', {'value':'0.01','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6019759883360&cd[value]=0.01&cd[currency]=USD&noscript=1" /></noscript>
</head>
我将此添加到页面中,显然像素处于活动状态。但是,我需要做的是用实际结账值替换正在跟踪的值。我知道有一些像$ checkout-&gt; get_value()但我不确定这是否会起作用。理想情况下是这样的:
<head>
<!-- Facebook Conversion Code for GRC Domains - Domain Purchase -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '6019759883360', {'value':'GET CHECKOUT VALUE','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6019759883360&cd[value]=GET CHECKOUT VALUE&cd[currency]=USD&noscript=1" /></noscript>
</head>
非常感谢你的时间, 贡萨洛
答案 0 :(得分:2)
这就是你正在寻找的我相信https://www.social-response.co.uk/facebook-conversion-pixel-woocommerce-values/
这是它的基本代码
// FB Pixel Tracking Code
add_action( 'woocommerce_thankyou', 'fb_pixeltracking' );
function fb_pixeltracking( $order_id ) {
$order = new WC_Order( $order_id );
$order_total = $order->get_total();
?>
<!-- Facebook Conversion Code for Sales from Facebook Ads -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', 'XXXXXXXXXXXXXX', {'value':'<?php echo $order_total ?>','currency':'GBP'}]);
</script>
<noscript>
<img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/trev=XXXXXXXXXXXXXX&cd[value]=<?php echo $order_total ?>&cd[currency]=GBP&noscript=1" />
</noscript>
<!-- END FB Tracking -->
<?php
}
只需将XXXXX替换为您的像素代码,然后选择您的货币。
答案 1 :(得分:0)
<head>
<!-- Facebook Conversion Code for GRC Domains - Domain Purchase -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '6019759883360', {'value':'<?php echo $order_total ?>','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6019759883360&cd[value]=0.00&cd[currency]=USD&noscript=1" /></noscript>
</head>