Magento Forum

   
ECommerce Tracking for Google Analytics NOT WORKING
 
twintailclothing
Jr. Member
 
Total Posts:  16
Joined:  2010-03-17
 

Hi, after reading every post out there that’s related to this topic, I still can’t figure out why my analytics account is not recording transaction data.

- Yes, ecommerce tracking is turned on
- I am using Magento Community version 1.4.0.1
- After looking at the ga.php file, all the coding looks to be intact

I’m not sure where to go from here. Can someone please help!?!?!

Website is http://www.tailwatersflyfishing.com

Thanks so much!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
twintailclothing
Jr. Member
 
Total Posts:  16
Joined:  2010-03-17
 

I just did a test purchase and this is the analytics code that is at the bottom of the success page....

<!-- BEGIN GOOGLE ANALYTICS CODE -->
<
script type="text/javascript">
//<![CDATA[
    
(function() {
        
var ga document.createElement('script'); ga.type 'text/javascript'ga.async true;
        
ga.src = ('https:' == document.location.protocol 'https://ssl' 'http://www') + '.google-analytics.com/ga.js';
        (
document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
    
})();

    
_gaq.push(["_setAccount""UA-12398483-2"]);
    
_gaq.push(["_trackPageview""/checkout/cart/"]);
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
        <
script src="http://checkout.google.com/files/digital/ga_post.js" type="text/javascript"></script>    </div>
</
div>
<
script type="text/javascript">

  var 
_gaq _gaq || [];
  
_gaq.push(['_setAccount''UA-12398483-2']);
  
_gaq.push(['_trackPageview']);

  (function() 
{
    
var ga document.createElement('script'); ga.type 'text/javascript'ga.async true;
    
ga.src = ('https:' == document.location.protocol 'https://ssl' 'http://www') + '.google-analytics.com/ga.js';
    var 
document.getElementsByTagName('script')[0]s.parentNode.insertBefore(gas);
  
})();

</script>

Can someone please help!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Benoit Xylo
Member
 
Avatar
Total Posts:  46
Joined:  2009-10-11
Warsaw, Poland
 

Are you sure, it’s all you have? You should have also something like this in the success page source:

_gaq.push(['_addTrans''100000001''Demo Store''4.4900''0.7200''0.4100''Warsaw''''PL']);
_gaq.push(['_addItem''100000001''micronmouse5000''Microsoft Wireless Optical Mouse 5000''''3.3600''1.0000']);
_gaq.push(['_trackTrans']);

What Magento version do you use?

 
Magento Community Magento Community
Magento Community
Magento Community
 
twintailclothing
Jr. Member
 
Total Posts:  16
Joined:  2010-03-17
 

Positive. I’m running 1.4.0.1

Also what looked strange is that the code above had our account # twice. In other words there were two sets of analytics code.

Here is the code from the Ga.php block:

/**
 * GoogleAnalitics Page Block
 *
 * @category   Mage
 * @package    Mage_GoogleAnalytics
 * @author     Magento Core Team <core@magentocommerce.com>
 */
class Mage_GoogleAnalytics_Block_Ga extends Mage_Core_Block_Text
{
    
/**
     * Retrieve Quote Data HTML
     *
     * @return string
     */
    
public function getQuoteOrdersHtml()
    
{
        $quote 
$this->getQuote();
        if (!
$quote{
            
return '';
        
}

        
if ($quote instanceof Mage_Sales_Model_Quote{
            $quoteId 
$quote->getId();
        
else {
            $quoteId 
$quote;
        
}

        
if (!$quoteId{
            
return '';
        
}

        $orders 
Mage::getResourceModel('sales/order_collection')
            ->
addAttributeToFilter('quote_id'$quoteId)
            ->
load();

        
$html '';
        foreach (
$orders as $order{
            $html 
.= $this->setOrder($order)->getOrderHtml();
        
}

        
return $html;
    
}

    
/**
     * Retrieve Order Data HTML
     *
     * @return string
     */
    
public function getOrderHtml()
    
{

        $order 
$this->getOrder();
        if (!
$order{
            
return '';
        
}

        
if (!$order instanceof Mage_Sales_Model_Order{
            $order 
Mage::getModel('sales/order')->load($order);
        
}

        
if (!$order{
            
return '';
        
}

        $address 
$order->getBillingAddress();

        
$html  '<script type="text/javascript">' "\n";
        
$html .= "//<![CDATA[\n";
        
$html .= '_gaq.push(["_addTrans",';
        
$html .= '"' $order->getIncrementId() . '",';
        
$html .= '"' $order->getAffiliation() . '",';
        
$html .= '"' $order->getBaseGrandTotal() . '",';
        
$html .= '"' $order->getBaseTaxAmount() . '",';
        
$html .= '"' $order->getBaseShippingAmount() . '",';
        
$html .= '"' $this->jsQuoteEscape($address->getCity(), '"') . '",';
        
$html .= '"' $this->jsQuoteEscape($address->getRegion(), '"') . '",';
        
$html .= '"' $this->jsQuoteEscape($address->getCountry(), '"') . '"';
        
$html .= ']);' "\n";

        foreach (
$order->getAllItems() as $item{
            
if ($item->getParentItemId()) {
                
continue;
            
}

            $html 
.= '_gaq.push(["_addItem",';
            
$html .= '"' $order->getIncrementId() . '",';
            
$html .= '"' $this->jsQuoteEscape($item->getSku(), '"') . '",';
            
$html .= '"' $this->jsQuoteEscape($item->getName(), '"') . '",';
            
$html .= '"' $item->getCategory() . '",';
            
$html .= '"' $item->getBasePrice() . '",';
            
$html .= '"' $item->getQtyOrdered() . '"';
            
$html .= ']);' "\n";
        
}

        $html 
.= '_gaq.push(["_trackTrans"]);' "\n";
        
$html .= '//]]>';
        
$html .= '</script>';

        return 
$html;
    
}

    
/**
     * Retrieve Google Account Identifier
     *
     * @return string
     */
    
public function getAccount()
    
{
        
if (!$this->hasData('account')) {
            $this
->setAccount(Mage::getStoreConfig('google/analytics/account'));
        
}
        
return $this->getData('account');
    
}

    
/**
     * Retrieve current page URL
     *
     * @return string
     */
    
public function getPageName()
    
{
        
if (!$this->hasData('page_name')) {
            
//$queryStr = '';
            //if ($this->getRequest() && $this->getRequest()->getQuery()) {
            //    $queryStr = '?' . http_build_query($this->getRequest()->getQuery());
            //}
            
$this->setPageName(Mage::getSingleton('core/url')->escape($_SERVER['REQUEST_URI']));
        
}
        
return $this->getData('page_name');
    
}

    
/**
     * Prepare and return block's html output
     *
     * @return string
     */
    
protected function _toHtml()
    
{
        
if (!Mage::getStoreConfigFlag('google/analytics/active')) {
            
return '';
        
}

        $this
->addText('
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
    (function() {
        var ga = document.createElement(\'
script\'); ga.type = \'text/javascript\'; ga.async = true;
        ga.src = (\'
https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';
        
(document.getElementsByTagName(\'head\')[0] || document.getElementsByTagName(\'body\')[0]).appendChild(ga);
    
})();

    
_gaq.push(["_setAccount""' . $this->getAccount() . '"]);
    
_gaq.push(["_trackPageview""'.$this->getPageName().'"]);
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
        
');

        $this->addText($this->getQuoteOrdersHtml());

        if ($this->getGoogleCheckout()) {
            $protocol = Mage::app()->getStore()->isCurrentlySecure() ? '
https' : 'http';
            $this->addText('
<script src="'.$protocol.'://checkout.google.com/files/digital/ga_post.js" type="text/javascript"></script>');
        }

        return parent::_toHtml();
    }
}

Is everything there? Are there any other files I need to check?

 
Magento Community Magento Community
Magento Community
Magento Community
 
twintailclothing
Jr. Member
 
Total Posts:  16
Joined:  2010-03-17
 

Anyone? Surely someone has an answer out there

 
Magento Community Magento Community
Magento Community
Magento Community
 
Benoit Xylo
Member
 
Avatar
Total Posts:  46
Joined:  2009-10-11
Warsaw, Poland
 

Your GA block class seems to be ok. Are you using default Magento checkout?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top