Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
integration:googleanalytics [2010/10/08 08:23] – external edit 127.0.0.1integration:googleanalytics [2017/04/26 07:02] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ---- dataentry ---- ---- dataentry ----
 type          : integration # do not change this line type          : integration # do not change this line
 +supports-foxycart-version-from : 0.3.0    # Minimum required FoxyCart version for this to work
 +supports-foxycart-version-to   : 0.6.0    # Last FoxyCart version that supports this (leave empty if unknown)
 system        : Google Analytics system        : Google Analytics
 name          : Ecommerce Tracking for Google Analytics name          : Ecommerce Tracking for Google Analytics
 description   : Tutorial to set up ecommerce tracking for Google Analytics and FoxyCart description   : Tutorial to set up ecommerce tracking for Google Analytics and FoxyCart
-tags_tags     : analytics, tutorial, tracking+tags          : analytics, tutorial, tracking
 date_dt       : 2010-01-08 date_dt       : 2010-01-08
 version       : FoxyCart v060. Google Analytics as of 2010-01-08 version       : FoxyCart v060. Google Analytics as of 2010-01-08
Line 13: Line 15:
 ====== Google Analytics Ecommerce Tracking ====== ====== Google Analytics Ecommerce Tracking ======
 ===== Read This First: ===== ===== Read This First: =====
-<note warning>NOTE: This page describes Google Analytics integration for FoxyCart v0.6.0. If you need v0.7.0 instructions please nudge us on [[http://forum.foxycart.com|the forum]].</note>+<note warning>NOTE: This page describes Google Analytics integration for FoxyCart v0.6.0 and prior. If you need v0.7.0 instructions please [[.:googleanalytics_async|see the Google Analytics Asynchronous for v0.7.0+]] docs.</note>
 === Assumptions === === Assumptions ===
   - The instructions and code below is current as of FoxyCart v060 and Google Analytics as of 2009-01-08. If you notice things that should be changed please let us know on our forum.   - The instructions and code below is current as of FoxyCart v060 and Google Analytics as of 2009-01-08. If you notice things that should be changed please let us know on our forum.
Line 25: Line 27:
   * This code may not work correctly if you're doing direct-to-checkout (''cart=checkout'') links originating from outside the site being tracked by Google Analytics. For instance, if you have ''cart=checkout'' links in an email, the referrer or campaign may not be maintained. If this is an issue for you please [[http://forum.foxycart.com/|let us know]].   * This code may not work correctly if you're doing direct-to-checkout (''cart=checkout'') links originating from outside the site being tracked by Google Analytics. For instance, if you have ''cart=checkout'' links in an email, the referrer or campaign may not be maintained. If this is an issue for you please [[http://forum.foxycart.com/|let us know]].
   * While ''http:'' ''href''s will work for add-to-cart requests, the redirect from ''http'' to ''https'' will cause problems for GA. Ensure that all link ''href'' and form ''action'' attributes go to ''https'' URLs.   * While ''http:'' ''href''s will work for add-to-cart requests, the redirect from ''http'' to ''https'' will cause problems for GA. Ensure that all link ''href'' and form ''action'' attributes go to ''https'' URLs.
 +
 +=== Changes To This Page ===
 +  * <wrap important>2011-08-08: Critical change to the include code</wrap>. Details on [[http://forum.foxycart.com/comments.php?DiscussionID=4924&page=1#Item_7|our forum]]. The important pieces are:<code>On the cart, change this line:
 +  window.location.hash = fc_json.custom_fields['ga'];
 +to this:
 +  window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
 +
 +And this line:
 +  var href_link = $(this).attr('href') + fc_json.custom_fields['ga'];
 +to this:
 +  var href_link = $(this).attr('href') + fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
 +
 +On the checkout, change this line:
 +  window.location.hash = fc_json.custom_fields['ga'];
 +to this:
 +  window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
 +
 +On the receipt, change this:
 +  window.location.hash = fc_json.custom_fields['ga'];
 +to:
 +  window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
 +</code>This has been changed in all the examples below.
 +
 +
 ===== Setup Your Tracking Code ===== ===== Setup Your Tracking Code =====
 <note tip>The steps below are for the "standard" *box (like the default Thickbox/Foxybox) is used, or in other situations where you're loading the cart inside an iframe. If you're displaying the cart full screen, using a ''JSON(P)'' based cart, or are otherwise doing something custom you may need to modify this code, depending on your needs. As always, test test test.</note> <note tip>The steps below are for the "standard" *box (like the default Thickbox/Foxybox) is used, or in other situations where you're loading the cart inside an iframe. If you're displaying the cart full screen, using a ''JSON(P)'' based cart, or are otherwise doing something custom you may need to modify this code, depending on your needs. As always, test test test.</note>
Line 32: Line 58:
 If your cart and checkout are at something like ''example.foxycart.com'', follow the steps below. If you're using a custom subdomain and your checkout is at something like ''secure.example.com'', skip to the next section. If your cart and checkout are at something like ''example.foxycart.com'', follow the steps below. If you're using a custom subdomain and your checkout is at something like ''secure.example.com'', skip to the next section.
  
-  - On Step 1 under Google Analytics "Instructions for adding tracking" in your Google Analytics account, select the "Multiple top-level domains" radio button. It should give you something like this: <code html><script type="text/javascript">+  - On Step 1 under Google Analytics "Instructions for adding tracking" in your Google Analytics account, select the "Multiple top-level domains" radio button. <wrap alert>//Don't use the new asynchronous code//,</wrap> as this tutorial is not designed to work with the older GA code. It should look something like this: <code html><script type="text/javascript">
 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
Line 108: Line 134:
  if (fc_json.custom_fields['ga']) {  if (fc_json.custom_fields['ga']) {
  $('a.fc_link_nav').each(function(){  $('a.fc_link_nav').each(function(){
- var href_link = $(this).attr('href') + fc_json.custom_fields['ga'];+ var href_link = $(this).attr('href') + fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
  $(this).attr('href', href_link);  $(this).attr('href', href_link);
  });  });
Line 120: Line 146:
 pageTracker._setAllowAnchor(true);</code> pageTracker._setAllowAnchor(true);</code>
     - Add this right before the "try" statement:<code javascript>// Ensure the GA info is in the URL //     - Add this right before the "try" statement:<code javascript>// Ensure the GA info is in the URL //
-if (window.location.hash.search(/utma/) == -1 && fc_json.custom_fields['ga'].length > 0) { +if (window.location.hash.search(/utma/) == -1 && typeof(fc_json.custom_fields['ga']) != "undefined") { 
- window.location.hash = fc_json.custom_fields['ga'];+ if (fc_json.custom_fields['ga'].length > 0) { 
 + window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' ); 
 + }
 }</code> }</code>
     - Your finished code for the checkout will look like this (of course you must replace the ''XXXXXXX-X'' with your appropriate Google Analytics account info):      - Your finished code for the checkout will look like this (of course you must replace the ''XXXXXXX-X'' with your appropriate Google Analytics account info): 
Line 130: Line 158:
 <script type="text/javascript"> <script type="text/javascript">
 // Ensure the GA info is in the URL // // Ensure the GA info is in the URL //
-if (window.location.hash.search(/utma/) == -1 && fc_json.custom_fields['ga'].length > 0) { +if (window.location.hash.search(/utma/) == -1 && typeof(fc_json.custom_fields['ga']) != "undefined") { 
- window.location.hash = fc_json.custom_fields['ga'];+ if (fc_json.custom_fields['ga'].length > 0) { 
 + window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' ); 
 + }
 } }
 try { try {
Line 149: Line 179:
 <script type="text/javascript"> <script type="text/javascript">
 // Ensure the GA info is in the URL // // Ensure the GA info is in the URL //
-if (window.location.hash.search(/utma/) == -1 && fc_json.custom_fields['ga'].length > 0) { +if (window.location.hash.search(/utma/) == -1 && typeof(fc_json.custom_fields['ga']) != "undefined") { 
- window.location.hash = fc_json.custom_fields['ga'];+ if (fc_json.custom_fields['ga'].length > 0) { 
 + window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' ); 
 + }
 } }
 try { try {

Site Tools