我使用的Magento 1.7.0.2,並在過去,我下面的代碼添加到我的success.phtml頁面和谷歌正在跟蹤我的轉換:Magento的:谷歌Analytics(分析)電子商務跟蹤
<?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不再跟蹤任何內容。我已經聯繫了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;?>
可有人請確認這是正確的嗎?