Modular Merchant: Shopping Cart Software

Shopping Cart Software Service

Advanced SearchAdvanced Search RegisterRegister ProfileProfile FAQFAQ MemberlistMemberlist Log inLog in
Google Analytics integration
Post new topic   Reply to topic
Modular Merchant Forum Index -> 3rd Party Service Integration
Author Message

vsergiu




Joined: 13 Dec 2006
Posts: 2


PostPosted: Dec 13, 2006 02:43am    Post subject: Google Analytics integration Reply with quote

Hi

I want to track my store with Google Analytics. While tracking the visitors isn't a problem, 'cause it can be done by adding the Analytics code to the templates defined in ModularMerchant, I don't see how am I gonna track the e-commerce transactions, since I don't have access to receipt page's transaction details (or do I?).

Can someone help me with this issue?

Sergiu V.

Mail Bag


Answering Your Questions Since... 9:30am

Joined: 28 Aug 2005
Posts: 113


PostPosted: Dec 13, 2006 08:26pm    Post subject: Tracking Shopping Cart Transactions with Google Analytics Reply with quote

Quote:
I don't see how am I gonna track the e-commerce transactions, since I don't have access to receipt page's transaction details (or do I?).

Actually, you do! By adding the sample scripts below to the "Checkout Receipt" Skin Template in your store, you will be able to pass the transaction details back to your Google Analytics account.

Prerequisites
Before using the scripts below, you will need the following:
1. A Google Analytics account with a Profile for your domain.
2. The domain's Profile should be configured to track e-commerce transactions. (See Google Help article at: http://adwords.google.com/support/bin/answer.py?answer=27203&topic=8115 for more information.)

Step 1 of 4 - Build the transaction data for Analytics
Open the Checkout Receipt Skin Template for editing. The Skin Editor is located in your store's Administration area at: [Navigation Menu > Design > Skin Editor]. In the Checkout Receipt Skin Footer field, add the following script:

Code:
<?php
/* This runs a script that builds a copy of the
 * transaction details, which will be used when
 * we connect to Google Analytics. */
$mm_google_utm = mm_fetch_google_utm();
?>


Step 2 of 4 - Add the standard Google Analytics code to the Skin
The second step is to ensure that the the standard Google Analytics tracking code is included in the Checkout Receipt Skin. This creates the connection to Google's service. Copy your standard Google Analytics tracking script into the Checkout Receipt FOOTER field after the script from step 1.

The standard Google Analytics code looks something like this:
Code:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
  _uacct="UA-xxxx-x";
  urchinTracker();
</script>


Step 3 of 4 - Include the Google Analytics "Transaction Data" script
Next, in the Checkout Receipt FOOTER Skin below the tracking code from step 2, the following script needs to be included. This code should be copied into the Skin template exactly as shown below.
Code:
<form style="display:none;" name="utmform"> <textarea id="utmtrans">UTM:T|<?=$_SESSION['order_arr']['order_id']?>|store|<?=$_SESSION['order_arr']['grand_total']?>|0|<?=$_SESSION['order_arr']['ship_fees']?>|<?=$_SESSION['cmr_arr']['ship_city']?> |<?=$_SESSION['cmr_arr']['ship_state']?>|<?=$_SESSION['cmr_arr']['ship_country_iso']?> <?=$mm_google_utm?> </textarea> </form>


Step 4 of 4 - Add the Google's "utmSetTrans" function to the page
Finally, the utmSetTrans function must be called after the form is submitted in order to record the transaction. This can be most easily accomplished through a body onLoad event. To accomplish this, add the following item within the <body> tag in the Checkout Receipt Skin's HEADER field:
Code:
onLoad="javascript:__utmSetTrans()"


The four steps above will allow the store to create a copy of the transaction information in a format compatible with Google Analytics, connect to your Google Analytics account, and submit the transaction data to their service.

IMPORTANT: Official support for the Google Analytics code above is scheduled to be released in the next Modular Merchant software update, version 2.022, scheduled for release in January 2007. If you would like to use the above scripts prior to that, submit a request to Modular Merchant Tech Support by opening a Support Ticket in your store's administration area. (Located at: [Navigation Menu > Support > Support Tickets]). Upon request, your account can be updated with a pre-release version of the update, which will support the scripts listed in this article.

For more information on the code Google provides for tracking shopping cart transactions, see their How-To article at:
http://adwords.google.com/support/bin/answer.py?answer=27203&topic=8115
_________________
Modular Merchant Mail Bag
Answering your questions, queries and puzzlers.
Modular Merchant shopping cart software, website hosting, and custom programming.

vsergiu




Joined: 13 Dec 2006
Posts: 2


PostPosted: Dec 18, 2006 02:55am    Post subject: Reply with quote

Correction on Step 2:
Are you sure that the code should not be
Quote:

<script>
_uacct="UA-xxxx-x";
_udn="none";
_ulink=1;
urchinTracker();
</script>


At least for the merchants that redirect their customers from their websites to their ModularMerchant shopping cart.

Mail Bag


Answering Your Questions Since... 9:30am

Joined: 28 Aug 2005
Posts: 113


PostPosted: Dec 18, 2006 10:33am    Post subject: Reply with quote

Quote:
Are you sure that the code should not be...
The example we provided above is an excerpt from Google's How do I track e-commerce transactions? webpage at:
http://adwords.google.com/support/bin/answer.py?answer=27203&topic=8115

If Google has provided a different script for your own account, we'd recommend contacting Google to ask about the differences between the version they've provided you with and the version in their tutorial; and then use whichever version they recommend.
_________________
Modular Merchant Mail Bag
Answering your questions, queries and puzzlers.
Modular Merchant shopping cart software, website hosting, and custom programming.

CMarier


Modular Merchant: Administration

Joined: 06 Mar 2006
Posts: 38
Location: Oregon


PostPosted: May 03, 2007 04:33pm    Post subject: Google Analytics Function Code Reply with quote

Some clients have been trying to make their own version of the "mm_fetch_google_utm()" PHP function mentioned above, to use with Google and other tracking systems. To help these developers, we're posting a copy of the code of the "mm_fetch_google_utm()" function below. The function simply loops through the $_SESSION array containing the customer's shopping session information. (The real trick is knowing how all of the bits and pieces of the cart's shopping $_SESSION array are put together.) Hopefully, developers can use this code as a starting point to build other tracking functions!

Code:
<?php
function mm_fetch_google_utm() {
   /* This script will build a variable containing the
    * transaction data, which can be used for the
    * "GOOGLE UTM" value in a Google Analytics script. */
   
   unset($mm_google_utm);
   
   // Loop through each shipping address in the order...
   foreach($_SESSION['basket_arr']['ship_addr_id_arr'] AS $a) {
      $i=0;
      // Loop through each product in current address' order...
      foreach($_SESSION['basket_arr'][$a]['prod_id'] AS $b) {
         
         // Just in case there's no order ID, set the order ID to the customer's email address...
         if($_SESSION['order_arr']['order_id'] == '') {
            $oid=$_SESSION['cmr_arr']['email'];
         } else {
            $oid=$_SESSION['order_arr']['order_id'];
         }
         
         // Look up the primary category for the current product...
         $fetch = mysql_query("SELECT prod_cats.name AS category_name FROM prod_cats,prod_cat_assoc WHERE prod_cat_assoc.prod_id = '".$b."'
         AND prod_cats.id = prod_cat_assoc.cat_id LIMIT 1");
         if (!$fetch) { echo("<P>Line ".__LINE__.": Google Analytics Script; Error retrieving info from DB: " . mysql_error()); }
         while ($result = mysql_fetch_array($fetch)) {
            $category_name = $result["category_name"];
         } // end while
         
         // Append the current product data to the $mm_google_utm variable...
         $mm_google_utm .= 'UTM:I|'.$oid.'|'.$_SESSION['basket_arr'][$a]['sku'][$i].'|'.$_SESSION['basket_arr'][$a]['prod_name'][$i].'|'.$category_name.'|'.number_format($_SESSION['basket_arr'][$a]['unit_price'][$i],2,'.','').'|'.$_SESSION['basket_arr'][$a]['qty'][$i].' ';
         
         $i++;
      } // end foreach
   } // end foreach
   return $mm_google_utm;
} // end function
?>

_________________
CMarier
Modular Merchant - Shopping Cart Software
Specializing in digital delivery, subscription products, and add-on also available.

CMarier


Modular Merchant: Administration

Joined: 06 Mar 2006
Posts: 38
Location: Oregon


PostPosted: Apr 30, 2008 08:18pm    Post subject: Reply with quote

Update!
Integration of Google Analytics into your shopping cart is now easier than ever! Modular Merchant has developed new tools that will allow you to add Google Analytics to all your store pages without the need to touch any source code!

See this forum article for complete details and instructions:
http://forums.modularmerchant.com/viewtopic/540/
_________________
CMarier
Modular Merchant - Shopping Cart Software
Specializing in digital delivery, subscription products, and add-on also available.
Display posts from previous:   
Post new topic   Reply to topic    Modular Merchant Forum Index -> 3rd Party Service Integration All times are GMT - 7 Hours
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group