Magento Forum

Google Analytics code, Category is always Blank
 
Tij Bedi
Jr. Member
 
Total Posts:  11
Joined:  2008-12-31
 

Anybody know why this is happening or has a fix for it?

I have tried going properly through category menu’s to buy a product but the Google API code that get inserted automatically on the final success page never has the category in it

pageTracker._addItem("100000018”,"00XXXX”,"シリマリン・ミルクシスル 175mg”,"”,"1840.0000”,"1.0000");

Any help would be appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
coldwired
Jr. Member
 
Total Posts:  19
Joined:  2008-07-15
 

Hi,

We’ve got the same problem here. Did you find a solution to this?

Thanks,
Colin.

 
Magento Community Magento Community
Magento Community
Magento Community
 
vmadmin
Jr. Member
 
Total Posts:  11
Joined:  2009-05-13
 

I am having the same problem. The category argument is always an empty string.

pageTracker._addItem("100000105","15BZ","My Product","","1.9500","1.0000");

I took a look at /app/code/core/Mage/GoogleAnalytics/Block/Ga.php
On line 112-119 (in version 1.3.2.4) the category should be getting inserted into the tracking. It wasn’t intentionally omitted.

$html .= 'pageTracker._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";

I’m guessing that getCategory is supposed to return an integer rather than a category name since it isn’t being run through “jsQuoteEscape”.

The getCategory method is returning NULL.

 
Magento Community Magento Community
Magento Community
Magento Community
 
vmadmin
Jr. Member
 
Total Posts:  11
Joined:  2009-05-13
 

This topic should be moved to Technical Issues.

I’m running 1.3.2.4 from a fresh install and having this issue.

 
Magento Community Magento Community
Magento Community
Magento Community
 
vmadmin
Jr. Member
 
Total Posts:  11
Joined:  2009-05-13
 

Solution:
IN short:
Magento sucks use something else

IN Long:
/app/code/core/Mage/GoogleAnalytics/Block/Ga.php

Change this at line 106:
foreach ($order->getAllItems() as $item) {
if ($item->getParentItemId()) {
continue;
}
$cProduct = Mage::getModel(’catalog/product’);
$cProductId = $cProduct->getIdBySku($item->getSku());
$cProduct->load($cProductId);
$category_list = “”;
$cats = $cProduct->getCategoryCollection()->exportToArray();
foreach($cats as $cat){
$category_list .= Mage::getModel(’catalog/category’)->load($cat[’entity_id’])->getName()."|";
}

$category_list = rtrim($category_list,"|");
$html .= ‘pageTracker._addItem(’;
$html .= ‘”’ . $order->getIncrementId() . ‘“,’;
$html .= ‘”’ . $this->jsQuoteEscape($item->getSku(), ‘“‘) . ‘“,’;
$html .= ‘”’ . $this->jsQuoteEscape($item->getName(), ‘“‘) . ‘“,’;
$html .= ‘”’ . $category_list . ‘“,’;
$html .= ‘”’ . $item->getBasePrice() . ‘“,’;
$html .= ‘”’ . $item->getQtyOrdered() . ‘“‘;
$html .= ‘);’ . “\n”;
}

Will display all the categories a product is in separated by a “|” symbol

 
Magento Community Magento Community
Magento Community
Magento Community
 
willamm
Jr. Member
 
Total Posts:  6
Joined:  2009-12-20
 

allowScriptAccess is set to always. What troubles me is that it appears there must be
access to the DOM since utmp contains the whole pageview in Firefox 3, but in IE it’s
just blank.

_________________
Download Windows 7

 
Magento Community Magento Community
Magento Community
Magento Community
 
heronfisher
Jr. Member
 
Total Posts:  4
Joined:  2010-03-12
 

Probably the above posted comment would work as this kind of problems are now very among the Google Analytics user.

 
Magento Community Magento Community
Magento Community
Magento Community
 
buitenkeuken
Jr. Member
 
Total Posts:  2
Joined:  2010-05-13
 

Thanks for the solution, going to try this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rubaducky
Member
 
Total Posts:  39
Joined:  2009-10-02
 

I tried the above code and it still didn’t work.

Anyone figure out how to add the category to analytics?

magento 1.3.2.4

 
Magento Community Magento Community
Magento Community
Magento Community
 
subsidies
Jr. Member
 
Total Posts:  2
Joined:  2010-10-06
 

Yes I agree, it still doesn’t work. Anyone has a solution?

 
Magento Community Magento Community
Magento Community
Magento Community
 
subsidie
Jr. Member
 
Total Posts:  6
Joined:  2010-09-30
 

Sorry it works fine, my mistake :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
coolio
Jr. Member
 
Total Posts:  18
Joined:  2010-02-10
 

I have a issue that google somehow never picks up the conversion when a persons checkout all the way, so my official conversion is 0 even-though i know that is the case.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mmabardy
Member
 
Total Posts:  67
Joined:  2010-07-09
 

@ vmadmin

I would like to try your fix.  You say change line in 106 but you dont indicate what to change it from.  Can you post all of the code that needs to be changed or let me know if I am right here. Am I to change all of this:

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

...to what you have posted? 

Thank you!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tusher Khan
Member
 
Total Posts:  66
Joined:  2011-01-07
 

Google Analytics code is already installed in Magento. You need to get only the Account number from your google analytics. You can easily include Google Analytics in your Magento store from admin.

Here is a simple way to do that:

http://www.xpressbangla.com/how-to-add-google-analytics-on-magento-from-admin/

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