在Magento的Facebook转换跟踪

时间:2014-04-23 12:54:43

标签: javascript php magento facebook-graph-api magento-1.7

我试图在我的Magento安装中实现新的Facebook转换代码。根据Facebook我需要复制跟踪代码并将其粘贴    <头>和< /头>在我要跟踪转化的网页中。在Magento,这将是

应用\设计\前端\ XXXX \ YYYY \模板\结帐\ success.phtml

但是,我无法在此文件中找到任何内容。

代码看起来像这样,有没有人知道如何实现它?:

<!-- Facebook Conversion Code for track facebook -->
<script type="text/javascript">
var fb_param = {};
fb_param.pixel_id = 'xxxxxxxxxxxx';
fb_param.value = '0.00';
fb_param.currency = 'USD';
(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=6015688541915&amp;value=0&amp;currency=USD" /></noscript>

1 个答案:

答案 0 :(得分:1)

实现此目的的最简单方法

在template \ checkout \ success.phtml

<?php $order = Mage::getModel(‘sales/order’)->loadByIncrementId($this->getOrderId()); ?>

<!-- Facebook Conversion Code for Checkout -->
<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', 'XXXXXXXXXX', {'value':'<?php echo $order->getBaseGrandTotal() ?>','currency':'SGD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=XXXXXXXXXXXXX&amp;cd[value]=0.01&amp;cd[currency]=SGD&amp;noscript=1" /></noscript>