我正在使用Magento 1.7.0.2,过去我已将以下代码添加到我的success.phtml页面,Google正在跟踪我的转换:
<?php
//-------------------------------------------
// START ADWORDS CONVERSION VALUE TRACKING CODE
//-------------------------------------------
$order_details = Mage::getModel('sales/order')-
>loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$adwords_saleamt = $order_details->subtotal;
?>
<!-- Google Code for Thank you page Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 00000000;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "xxxxxxxxxxx";
var google_conversion_value = 1.00;
var google_conversion_currency = "GBP";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""
src="//www.googleadservices.com/pagead/conversion/00000000000/?
value=1.00&currency_code=GBP&label=xxxxxxxxxxx&guid=ON&script=0"/>
</div>
</noscript>
现在,在我切换到Universal Analytics后,Google不再跟踪任何内容了。我联系了谷歌,他们无法清楚地解释我需要做什么。
我的理解是,现在我需要将以下内容添加到我的success.phtml页面。
在:
<?php if ($this->getOrderId()):?>
<?php if ($this->getCanViewOrder()) :?>
...
<?php endif;?>
<?php endif;?>
后:
<?php if ($this->getOrderId()):?>
<?php if ($this->getCanViewOrder()) :?>
...
<?php endif;?>
<?php
// Transaction Data
$orderID = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
$orderTotal = $order->getGrandTotal();
// Affiliation, shipping and tax
$trans = array('id' => $orderID,
'revenue' => $orderTotal);
// List of Items Purchased
$items = array();
foreach ($order->getAllItems() as $item){
// SKU and category
$items[] = array('name' => $item->getName(),
'price' => $item->getPrice(),
'quantity' => $item->getQtyOrdered());
}
// Function to return the JavaScript representation of a TransactionData object.
function getTransactionJs(&$trans) {
return <<<HTML
ga('ecommerce:addTransaction', {
'id': '{$trans['id']}',
// if affiliation, shipping or tax is added
'revenue': '{$trans['revenue']}'
});
HTML;
}
// Function to return the JavaScript representation of an ItemData object.
function getItemJs(&$transId, &$item) {
return <<<HTML
ga('ecommerce:addItem', {
'id': '$transId',
// if SKU or category is added
'name': '{$item['name']}',
'price': '{$item['price']}',
'quantity': '{$item['quantity']}'
});
HTML;
}
?>
<script>
ga('require', 'ecommerce', 'ecommerce.js');
<?php
echo getTransactionJs($trans);
foreach ($items as &$item) {
echo getItemJs($trans['id'], $item);
}
?>
ga('ecommerce:send');
</script>
<?php endif;?>
有人可以确认这是正确的吗?
答案 0 :(得分:0)
使用此:
<?php // GET SOME VALUES FOR TRACKING PIXELS
$_customerId = Mage::getSingleton('customer/session')->getCustomerId();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData =$order->getData();
$_sub = $_totalData['subtotal'];
$_sub = round($_sub,2);
?>
<!-- Google Code for Website XY Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXXXXXX;
var google_conversion_language = "de";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "YYYYYYYYYYYYYYYY";
var google_conversion_value = <?php echo $_sub ?>;
var google_conversion_currency = "EUR";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"></script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/XXXXXXXXXX/?value=<?php echo $_sub ?>&currency_code=EUR&label=YYYYYYYYYYYYYYYY&guid=ON&script=0"/>
</div>
</noscript>
答案 1 :(得分:0)
我必须承认,我对您的上述帖子有点混淆,您提到的第一段代码是谷歌adwords对话跟踪代码,即使您从传统分析跟踪切换到通用分析跟踪,您根本无需更改。
您提到的第二段代码是通用分析对话跟踪代码,它将由通用跟踪模块处理,您无需手动将其添加到成功页面。如果你确实需要添加,那么你可能没有使用好的模块,可能想尝试像http://www.magentocommerce.com/magento-connect/google-analytics-enhanced-ecommerce-tracking.html这样的magento connect模块
希望以上内容有意义,如果有任何进一步的混淆,请随时提出。感谢
干杯 小号