Magento Facebook像素跟踪代码

时间:2016-04-12 22:04:00

标签: php facebook magento

我正在尝试将Facebook Pixel跟踪添加到Magento网站。具体来说,我想跟踪添加到购物车的点击,点击添加到心愿单以及成功页面。我在head.phtml文件中使用以下代码。然而,我的Chrome浏览器Facebook Pixel Helper扩展说" Facebook Pixel没有加载"。我想知道是否有人可以帮助我在下面的代码中找出错误。



   <!-- FACEBOOK CONVERSION TRACKING -->
<?php if((strpos($_SERVER['REQUEST_URI'],'success')==true)):
  $orderObj = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); 
?>
<script type="text/javascript">
var fb_param = {};
fb_param.pixel_id = 'xxxxx';				   
fb_param.value = '<?php echo number_format($orderObj->getBaseGrandTotal(),2) ?>';
fb_param.currency = '<?php echo $orderObj->getOrderCurrencyCode()?>';
(function(){
  var fpw = document.createElement('script');
  fpw.async = true;
  fpw.src = '//connect.facebook.net/en_US/fp.js';
  var ref = document.getElementsByTagName('script')[0];
  ref.parentNode.insertBefore(fpw, ref);
})();
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/offsite_event.php?id=xxxxx&value=<?php echo number_format($orderObj->getBaseGrandTotal(),2) ?>&currency=<?php echo     $orderObj->getOrderCurrencyCode()?>" [^] /></noscript>
<?php 
endif;
if($this->getRequest()->getControllerName()=='product')
 {
   $asku = Mage::registry('current_product')->getSku();
   $pname = Mage::registry('current_product')->getName();
   $pprice = number_format(Mage::registry('current_product')->getPrice(),2);
?>
<script type="text/javascript">
 $('.btn-cart').click(function(){fbq('init','xxxxx');
 fbq('track','AddToCart',{content_name:'<?php echo "$pname"; ?>',content_category:'',content_ids:['<?php echo "$asku"?>'],content_type:'product',value:<?php echo "$pprice"; ?>,currency:'USD'});

  $('.link-wishlist').click(function(){fbq('init','xxxxxx');
 fbq('track','AddToWishlist',{content_name:'<?php echo "$pname"; ?>',content_category:'',content_ids:['<?php echo "$asku"?>'],content_type:'product',value:<?php echo "$pprice"; ?>,currency:'USD'});
});
</script>
<?php
  }else{
?>
<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', 'xxxxx');
fbq('track', "PageView");
</script>
<noscript>
 <img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=xxxxx&ev=PageView&noscript=1"/>
</noscript>
<?php
  }
?>
<!-- END FACEBOOK CONVERSION TRACKING -->
&#13;
&#13;
&#13;

0 个答案:

没有答案