Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 5
Magento & Google Analytics eCommerce Tracking <<SOLVED>>
 
Smokersroom
Member
 
Total Posts:  63
Joined:  2007-09-04
 

Hello Everyone,

I am looking to integrate Google Analytics very powerful eCommerce tracking into magento, which requires a further chunk of javascript to be inserted onto the confirmation page of the magento site.

Here is the code:

Here is a complete example:

<
script type="text/javascript">

var 
gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." "http://www.");

[removed](unescape("&#x3C;script src='" gaJsHost "google-analytics.com/ga.js' type='text/javascript'&#x3E;&#x3C;/script&#x3E;"));

</script>


<script type="text/javascript">

  var 
pageTracker _gat._getTracker("UA-XXXXX-1");


  
pageTracker._trackPageview();


  
pageTracker._addTrans(

    
"1234",                                     // Order ID

    
"Mountain View",                            // Affiliation

    
"11.99",                                    // Total

    
"1.29",                                     // Tax

    
"5",                                        // Shipping

    
"San Jose",                                 // City

    
"California",                               // State

    
"USA"                                       // Country

  
);


  
pageTracker._addItem(

    
"5678",                                     // Item Number

    
"DD44",                                     // SKU

    
"T-Shirt",                                  // Product Name 

    
"Green Medium",                             // Category

    
"11.99",                                    // Price

    
"1"                                         // Quantity

  
);

  
pageTracker._trackTrans();

</script>

As you can see, this code passes Google information about the Transaction, and the items bought in that transaction.

I would like to know how I can populate this Javascript with the correct values to pass to Google, for all of the above fields (Order ID, Total, Tax etc.)

I would also like to know how to add multiple instance of the pageTracker._addItem code, because the cart is likely to have more than one item at checkout.

I guess that it would be good to pass these values at the same time they are inserted into the Magento database, but I don’t know how to do that. I’m totally stumped, so any help very greatly appreciated!

Thanks,
S.

 
Magento Community Magento Community
Magento Community
Magento Community
 
iiNTENSE
Guru
 
Avatar
Total Posts:  432
Joined:  2008-11-06
Lansing, MI
 

place the code on your “home” CMS page, that should be sufficient.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

Huh? In the home page??

Doesn’t the Google Analytics portion of the Magento code handle this for you?  If you look at the code in app/code/core/Mage/GoogleAnalytics/Block/Ga.php, you’ll see that it’s doing all that stuff for you.
Just turn it on and supply your unique account number.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Smokersroom
Member
 
Total Posts:  63
Joined:  2007-09-04
 
joyously - 18 November 2008 09:30 AM

Huh? In the home page??

Doesn’t the Google Analytics portion of the Magento code handle this for you?  If you look at the code in app/code/core/Mage/GoogleAnalytics/Block/Ga.php, you’ll see that it’s doing all that stuff for you.
Just turn it on and supply your unique account number.

Thanks!

Solved.

 
Magento Community Magento Community
Magento Community
Magento Community
 
iiNTENSE
Guru
 
Avatar
Total Posts:  432
Joined:  2008-11-06
Lansing, MI
 
joyously - 18 November 2008 09:30 AM

Huh? In the home page??

Doesn’t the Google Analytics portion of the Magento code handle this for you?  If you look at the code in app/code/core/Mage/GoogleAnalytics/Block/Ga.php, you’ll see that it’s doing all that stuff for you.
Just turn it on and supply your unique account number.

Yes, however his request was to insert his own code, not to merely turn on Analytics.

 
Magento Community Magento Community
Magento Community
Magento Community
 
daddyg
Sr. Member
 
Total Posts:  77
Joined:  2008-12-10
 

Hi

I’m a magento newbie and have GA set up in magento but I’m trying to figure out how to configure the GA ecommerce reporting. 
Can you clear some things up for me:-

Q1) The op’s code example was clearly taken from this Google Analytics help page
How do I track e-commerce...

On that page it says put the code onto the receipt page.  Shouldn’t that be a page the customer lands on after purchase rather than the Home page in the CMS?

Q2) Sorry if I’m being daft but I don’t understand this part of the google code example:-

pageTracker._addTrans(

    
"1234",                                     // Order ID

    
"Mountain View",                            // Affiliation

    
"11.99",                                    // Total

    
"1.29",                                     // Tax

    
"5",                                        // Shipping

    
"San Jose",                                 // City

    
"California",                               // State

    
"USA"                                       // Country

  
);


  
pageTracker._addItem(

    
"1234",                                     // Order ID

    
"DD44",                                     // SKU

    
"T-Shirt",                                  // Product Name 

    
"Green Medium",                             // Category

    
"11.99",                                    // Price

    
"1"                                         // Quantity

  
);

As you can see, the fields are already populated with values.  Surely we don’t put that actual code into magento?  If so, do those values get overwritten by our real sales data?

Thanks for any help?

Graham

 
Magento Community Magento Community
Magento Community
Magento Community
 
back2007
Member
 
Total Posts:  59
Joined:  2009-03-30
 

hi,

If you want to add GA to you magento-driven site - just log in as admin, go to the System>Configuration>Google API> Google Analytics and enable tracking. 

Hope it wiil help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
daddyg
Sr. Member
 
Total Posts:  77
Joined:  2008-12-10
 

@Adjustware,

Thanks but I’ve already got GA installed via the Google API link inside Magento.  But it’s my understanding that for GA ecommerce tracking then you need the additional coding I listed in my previous post.  Are you saying that’s not the case?

Graham

 
Magento Community Magento Community
Magento Community
Magento Community
 
back2007
Member
 
Total Posts:  59
Joined:  2009-03-30
 

Hi,

fortunatelly no additional coding need.  You can check app\code\core\Mage\GoogleAnalytics\Block\Ga.php.

$html  '<script type="text/javascript">' "\n";
        
$html .= "//<![CDATA[\n";
        
$html .= 'pageTracker._addTrans(';
        
$html .= '"' $order->getIncrementId() . '",'
// and so on .....
 
Magento Community Magento Community
Magento Community
Magento Community
 
daddyg
Sr. Member
 
Total Posts:  77
Joined:  2008-12-10
 

That is a real time saver, thanks a lot.

Graham

 
Magento Community Magento Community
Magento Community
Magento Community
 
cellfservices
Sr. Member
 
Total Posts:  84
Joined:  2009-04-17
 

Also a Magento newb...Can I just clarify?  Am I just supposed to replace this code from app\code\core\Mage\GoogleAnalytics\Block\Ga.php.

<!-- BEGIN GOOGLE ANALYTICS CODE -->
<
script type="text/javascript">
//<![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." "http://www.");
[removed](unescape("&#x3C;script src=\'" gaJsHost "google-analytics.com/ga.js\' type=\'text/javascript\'&#x3E;&#x3C;/script&#x3E;"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var pageTracker _gat._getTracker("' . $this->getAccount() . '");
pageTracker._trackPageview("'.$this->getPageName().'");
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->

With the following code from http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer;=55528

<script type="text/javascript">

var 
gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." "http://www.");

[removed](unescape("&#x3C;script src='" gaJsHost "google-analytics.com/ga.js' type='text/javascript'&#x3E;&#x3C;/script&#x3E;"));

</script>


<script type="text/javascript">

try 
{

  
var pageTracker _gat._getTracker("UA-XXXXX-1");


  
pageTracker._trackPageview();


  
pageTracker._addTrans(

    
"1234",                                     // Order ID

    
"Mountain View",                            // Affiliation

    
"18.28",                                    // Total

    
"1.29",                                     // Tax

    
"5",                                        // Shipping

    
"San Jose",                                 // City

    
"California",                               // State

    
"USA"                                       // Country

  
);


  
pageTracker._addItem(

    
"1234",                                     // Order ID

    
"DD44",                                     // SKU

    
"T-Shirt",                                  // Product Name 

    
"Green Medium",                             // Category

    
"11.99",                                    // Price

    
"1"                                         // Quantity

  
);

  
pageTracker._trackTrans();

catch(err{}</script>

If that’s it, this will be the best fix ever!!  Please let me know

 
Magento Community Magento Community
Magento Community
Magento Community
 
cellfservices
Sr. Member
 
Total Posts:  84
Joined:  2009-04-17
 

Also a Magento newb...Can I just clarify?  Am I just supposed to replace this code from app\code\core\Mage\GoogleAnalytics\Block\Ga.php.

<!-- BEGIN GOOGLE ANALYTICS CODE -->
<
script type="text/javascript">
//<![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." "http://www.");
[removed](unescape("&#x3C;script src=\'" gaJsHost "google-analytics.com/ga.js\' type=\'text/javascript\'&#x3E;&#x3C;/script&#x3E;"));
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var pageTracker _gat._getTracker("' . $this->getAccount() . '");
pageTracker._trackPageview("'.$this->getPageName().'");
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->

With the following code from http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer;=55528

<script type="text/javascript">

var 
gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." "http://www.");

[removed](unescape("&#x3C;script src='" gaJsHost "google-analytics.com/ga.js' type='text/javascript'&#x3E;&#x3C;/script&#x3E;"));

</script>


<script type="text/javascript">

try 
{

  
var pageTracker _gat._getTracker("UA-XXXXX-1");


  
pageTracker._trackPageview();


  
pageTracker._addTrans(

    
"1234",                                     // Order ID

    
"Mountain View",                            // Affiliation

    
"18.28",                                    // Total

    
"1.29",                                     // Tax

    
"5",                                        // Shipping

    
"San Jose",                                 // City

    
"California",                               // State

    
"USA"                                       // Country

  
);


  
pageTracker._addItem(

    
"1234",                                     // Order ID

    
"DD44",                                     // SKU

    
"T-Shirt",                                  // Product Name 

    
"Green Medium",                             // Category

    
"11.99",                                    // Price

    
"1"                                         // Quantity

  
);

  
pageTracker._trackTrans();

catch(err{}</script>

If that’s it, this will be the best fix ever!!  Please let me know

 
Magento Community Magento Community
Magento Community
Magento Community
 
cellfservices
Sr. Member
 
Total Posts:  84
Joined:  2009-04-17
 

can somebody please confirm if the above procedure I wrote is correct?

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

@cellfservices
No, that will not work. The HTML/Javascript code Google gives you should not be used to replace the PHP code in “Ga.php”.

Magneto already supports GA tracking, including ecommerce tracking. The “Ga.php” file generates the proper (HTML/Javascript) code for you. All you have to do is turn on GA tracking and enter your GA account number (something like “UA-XXXXX-X").

That said… the tracking is working fine for me with the exception of ecommerce categories.
http://www.magentocommerce.com/boards/newreply/52505/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Cubix WS
Guru
 
Avatar
Total Posts:  318
Joined:  2009-07-01
LondON, United Kingdom
 

I just installed eCommerce tracking on my Magento site. It works absolutely fine. Let me answer all questions together:

1. All Google Analytics code is already installed in Magento. You simply need to get the Account number from your google analytics account and install it in Magento. You can activate it by going to Admin Panel > System > Configuration > Google API > Google Analytics

2. Ecommerce tracking code is already built in into Magento. You just simply need to activate it in your google analytics account. No coding is required in Magento

3. You can even configure your website for Goal conversion where you can define a funnel and Order Completion as the goal. No additional coding is required for this.

4. You can even configure each section in the one page checkout to be a step in the funnel for goal conversion feature. So ‘billing address’ will be one step, ‘shipping address’ will be another next, ‘shipping method’ will be next step, ‘payment method’ will be next step, ‘order review’ will be next step and finally ‘order complete’ will be the goal completed step. That requires some additional coding in your opcheckout.js javascript file and needs your google analytics to be setup correctly..

 
Magento Community Magento Community
Magento Community
Magento Community
 
pilare
Jr. Member
 
Total Posts:  9
Joined:  2009-05-13
 
vmadmin - 03 November 2009 01:02 PM

@cellfservices
No, that will not work. The HTML/Javascript code Google gives you should not be used to replace the PHP code in “Ga.php”.

Magneto already supports GA tracking, including ecommerce tracking. The “Ga.php” file generates the proper (HTML/Javascript) code for you. All you have to do is turn on GA tracking and enter your GA account number (something like “UA-XXXXX-X").

That said… the tracking is working fine for me with the exception of ecommerce categories.
http://www.magentocommerce.com/boards/newreply/52505/

I have the same, it all works from the box only without the e-commerce categories. Did anybody found out why?? is there any fix for this issue??
I have installed the google analytics plus extension from fooman to track the checkout funnel. Maybe this is an issue but I really don’t think so.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 5