简体   繁体   English

Magento:Google Analytics(分析)电子商务跟踪

[英]Magento: Google Analytics Ecommerce tracking

I am using Magento 1.7.0.2 and in the past I have added the following code to my success.phtml page and Google was tracking my conversions: 我使用的是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&amp;currency_code=GBP&amp;label=xxxxxxxxxxx&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

Now after I have switched to Universal Analytics, Google is no longer tracking anything. 现在,当我切换到Universal Analytics之后,Google不再跟踪任何内容。 I have contacted Google and they could not explain clearly what I need to do. 我已经与Google联系,他们无法清楚说明我需要做什么。

My understanding is that now I need to add the following to my success.phtml page. 我的理解是,现在我需要将以下内容添加到我的success.phtml页面中。

Before: 之前:

  <?php if ($this->getOrderId()):?>
  <?php if ($this->getCanViewOrder()) :?>
   ...
   <?php endif;?>
   <?php endif;?>

After: 后:

 <?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;?>

Can someone please confirm that this is correct? 有人可以确认这是正确的吗?

Use this: 用这个:

    <?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 ?>&amp;currency_code=EUR&amp;label=YYYYYYYYYYYYYYYY&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

I must admit that I am bit confusion with your above post, the first piece of code you mentioned is google adwords conversation tracking code which you don't need to change at all even if you are switching from traditional to universal analytic tracking. 我必须承认,我对您的上述帖子感到有些困惑,您提到的第一段代码是google adwords会话跟踪代码,即使您从传统分析跟踪转换为通用分析跟踪,也无需进行任何更改。

And second piece of code you mentioned is universal analytic conversation tracking code which will be taken care by universal tracking module and you don't need to add it manually to your success page. 您提到的第二段代码是通用分析对话跟踪代码,通用跟踪模块会处理该代码,您无需手动将其添加到成功页面。 If you do need to add then you might not be using good module and may want to try magento connect module like http://www.magentocommerce.com/magento-connect/google-analytics-enhanced-ecommerce-tracking.html 如果确实需要添加,那么您可能没有使用好的模块,并且可能想尝试使用magento connect模块,例如http://www.magentocommerce.com/magento-connect/google-analytics-enhanced-ecommerce-tracking.html

Hope the above makes sense, feel free to ask in case of any further confusion. 希望以上内容有意义,如有任何进一步的混淆,请随时提出。 Thanks 谢谢

Cheers S 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM