我正在尝试使用 Magento 设置 Facebook 动态产品广告,但我不确定如何设置添加到购物车和成功像素。我已经设置了产品页面 View 像素没问题。
在购物车页面/结帐时,我将以下(粗体)替换为什么 php 代码:
fbq('track', 'AddToCart', { content_name: '购物车', content_ids: ['1234', '1853', '9386'], content_type: '产品', 值:3.50, 货币:美元' });
在成功页面上,我用什么 php 代码替换了以下(粗体):
fbq('track', 'AddToCart', { content_name: '真快跑鞋', content_category: 'A服饰与配饰 > 鞋子', content_ids: ['1234'], content_type: '产品', 值(value):2.99, 货币:“美元”
非常感谢任何帮助!
最佳答案
对于购物车页面,您可以使用以下代码 -:
<?php $quote = Mage::getSingleton('checkout/cart')->getQuote();
$productIds = "";
foreach($quote->getAllItems() as $item):
if($item->getParentItemId()) continue;
if (strlen($productIds)==0){
$productIds = "'".$item->getSku()."'";
}
else{
$productIds = $productIds.",'".$item->getSku()."'";
}
endforeach;?>
<script>
fbq('track', 'AddToCart', {
content_name: 'Shopping Cart',
content_ids: [<?php echo $productIds?>],
content_type: 'product',
value: <?php echo number_format($quote->getGrandTotal(),2,'.','');?>,
currency: '<?php echo Mage::app()->getStore()->getCurrentCurrencyCode();?>'
});
</script>
对于购买或订单确认页面,您可以使用以下代码段-:
<?php $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
$productIds = "";
foreach($order->getAllItems() as $item):
if($item->getParentItemId()) continue;
if (strlen($productIds)==0){
$productIds = "'".$item->getSku()."'";
}
else{
$productIds = $productIds.",'".$item->getSku()."'";
}
endforeach;?>
<script>
fbq('track', 'Purchase', {
content_name: 'Order Confirmation',
content_ids: [<?php echo $productIds?>],
content_type: 'product',
value: <?php echo number_format($order->getGrandTotal(),2,'.','');?>,
currency: '<?php echo Mage::app()->getStore()->getCurrentCurrencyCode();?>'
});
</script>
关于php - Facebook 动态产品广告像素(添加到购物车,成功)- Magento,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33067599/