我正在尝试使用 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/

10-13 02:51