Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
integration:googleanalytics [2010/12/07 22:41] – [Set Up Everything Else] foxybrettintegration: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 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 122: Line 148:
 if (window.location.hash.search(/utma/) == -1 && typeof(fc_json.custom_fields['ga']) != "undefined") { if (window.location.hash.search(/utma/) == -1 && typeof(fc_json.custom_fields['ga']) != "undefined") {
  if (fc_json.custom_fields['ga'].length > 0) {  if (fc_json.custom_fields['ga'].length > 0) {
- window.location.hash = fc_json.custom_fields['ga'];+ window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
  }  }
 }</code> }</code>
Line 132: 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 && typeof(fc_json.custom_fields['ga'])) {+if (window.location.hash.search(/utma/) == -1 && typeof(fc_json.custom_fields['ga']) != "undefined") {
  if (fc_json.custom_fields['ga'].length > 0) {  if (fc_json.custom_fields['ga'].length > 0) {
- window.location.hash = fc_json.custom_fields['ga'];+ window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
  }  }
 } }
Line 153: 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 && typeof(fc_json.custom_fields['ga'])) {+if (window.location.hash.search(/utma/) == -1 && typeof(fc_json.custom_fields['ga']) != "undefined") {
  if (fc_json.custom_fields['ga'].length > 0) {  if (fc_json.custom_fields['ga'].length > 0) {
- window.location.hash = fc_json.custom_fields['ga'];+ window.location.hash = fc_json.custom_fields['ga'].replace( /\&amp;/g, '&' );
  }  }
 } }

Site Tools