These instructions are new, and while we have done some testing on the set up - the following are new instructions. Where possible we recommend testing this set up on a test profile before setting to your live analytics account, to ensure it works perfectly for your store. Any questions or issues, please get in touch with us.
Using FoxyCart 2.0? Google Analytics is now a configuration option within your store's administration. Take a look at Store Analytics for more information.
SKU
parameter in Google Analytics, which is the code
parameter in FoxyCart. If your products do not include a code
value (as passed to FoxyCart) FoxyCart will attempt to generate one from the name
attribute, but FoxyCart will not take into account duplicate product names, which can clobber your data. If you are not using the code
parameter for your products, this Google Analytics tracking may not work correctly.https://your_foxycart_domain
and not http://your_foxycart_domain
.foxycart.colorbox.js
(the default behavior) or foxycart.js
in your website template (do not include this in your cart, checkout, or receipt template). If you don't know what you're using, you're probably using foxycart.colorbox.js
and don't have to worry, but you can view your template source to confirm. The code below assumes that fcc
has been declared as a new FC.client
, so if you're using foxycart.raw.js
you'll need to create fcc
or modify the FC.ga
object accordingly.analytics.js
and not urchin.js
or ga.js
. If you need to use urchin.js
or ga.js
, see these instructions.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 let us know.fcsid
to the “Exclude URL Query Parameters” in your analytics settings. Details here./receipt
/cart
for the Screen/Page. (You won't have this step if you are using “direct to checkout” with the parameter “cart=checkout”). Do not check the “required step” checkbox, as there are situations where the cart can be skipped./checkout
for the URL.If you're using a hosted payment method like PayPal Express Checkout or Amazon FPS, you can create additional goals to track specific conversions for those options.
PayPal Express Checkout
Name: “Sale (PayPal as Checkout)“
Destination: /receipt_paypal_from_cart
Funnel:
/cart
/paypal_checkout
/checkout
Name: “Sale (PayPal as Payment Method)”
Destination: /receipt_paypal_from_checkout
Funnel:
/cart
/checkout
/paypal_payment
Amazon FPS
Name: “Sale (Amazon FPS as Checkout)“
Destination: /receipt_amazon_fps_from_cart
Funnel:
/cart
/amazon_fps_checkout
/checkout
Name: “Sale (Amazon FPS as Payment Method)“
Destination: /receipt_amazon_fps_from_checkout
Funnel:
/cart
/checkout
/amazon_fps_payment
Other Hosted Gateways
If you use other hosted gateways, you can set up goals for them as well, the goal would look like this:
Name: “Sale (NAME as Payment Method)“
Destination: /receipt_CODE_from_checkout
Funnel:
/cart
/checkout
/CODE_payment
In that gateway, you'd set NAME
to be the actual name of the gateway - this is for your reference within Google Analytics. You'd also change CODE
to match the code for your gateway:
Name | Code |
---|---|
DIBS | dibs |
iDEAL Ogone | ogone |
Dwolla | dwolla |
Bitpay | bitpay |
CyberSource | cybersource_hosted |
2Checkout | twocheckout |
Proceed to the next section.
</head>
tag - ensuring that it's included after the foxycart.js file you copied from the Sample Code section of your stores FoxyCart administration. Also, make sure you update the UA-XXXX-Y
with your correct Analytics account identifier:<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXX-Y', 'auto'); ga('send', 'pageview'); </script> <script type="text/javascript" charset="utf-8"> fcc.events.cart.preprocess.add(function (e, arr) { if (arr['cart'] == 'checkout' || arr['cart'] == 'updateinfo' || arr['output'] == 'json') { return true; } if (arr['cart'] == 'checkout_paypal_express') { if (window.ga && ga.loaded) { ga('send', 'pageview', '/paypal_checkout', { 'hitCallback': function () { jQuery.getJSON('https://' + document.domain + '/cart?' + fcc.session_get() + '&h:_fcpm=paypal|cart&output=json&callback=?', function (cart) { fcc.events.cart.preprocess.resume(); }); } }); return "pause"; } else { return true; } } return true; }); //CAUSING LOOPING ISSUES IN CHROME fcc.events.cart.process.add_pre(function (e, arr) { if (window.ga && ga.loaded) { ga(function (tracker) { jQuery.getJSON('https://' + storedomain + '/cart?' + fcc.session_get() + '&h:ga=' + escape(tracker.get('clientId')) + '&output=json&callback=?', function (data) { fcc.events.cart.process.resume(); }); }); return "pause"; } else { return true; } }); </script>
Copy the following and paste it above the closing </head>
tag in the respective templates. This can be directly in your FoxyCart admin or (preferably) in a template on your server that you will load into FoxyCart via FoxyCart's template caching functionality. Again, make sure you update the UA-XXXX-Y
with your correct Analytics account identifier.
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXX-Y', 'auto', { 'clientId': fc_json.custom_fields['ga'], 'storage': 'none' }); ga('set', 'page', '/cart'); ga('send', 'pageview'); </script> <script type="text/javascript" charset="utf-8"> jQuery(function($){ if ($('a.fc_cart_checkout_paypal').length > 0) { $.getJSON('https://' + document.domain + '/cart?fcsid=' + jQuery("input[name='fcsid']").val() + '&h:_fcpm=&output=json&callback=?', function(cart) { fc_json = cart; }); } $('a.fc_cart_checkout_paypal').click(function(e){ if (window.ga && ga.loaded) { e.preventDefault(); var link_url = jQuery(this).attr("href"); var gateway = (jQuery(this).hasClass("fc_cart_checkout_amazon")) ? "amazon_fps" : "paypal"; ga('send', 'pageview', '/' + gateway + '_checkout', { 'hitCallback': function() { $form = jQuery('<form method="post" target="_top"></form>').attr("action", link_url).appendTo("body"); jQuery.getJSON('https://' + document.domain + '/cart?fcsid=' + jQuery("input[name='fcsid']").first().val() + '&h:_fcpm=' + gateway + '|cart&output=json&callback=?', function(cart) { $form.submit(); }); } }); } }); }); </script>
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXX-Y', 'auto', { 'clientId': fc_json.custom_fields['ga'], 'storage': 'none' }); ga('set', 'page', '/checkout'); ga('send', 'pageview'); </script> <script type="text/javascript" charset="utf-8"> var originalValidateAndSubmit = FC.checkout.validateAndSubmit; function ga_tracker() { var wait = false; if (typeof(fc_json.custom_fields['ga']) != "undefined") { var method, method_co, source = ""; if (typeof(fc_json.custom_fields['_fcpm']) != "undefined" && fc_json.custom_fields['_fcpm'] != "") { var fcpm = fc_json.custom_fields['_fcpm'].split("|"); method = fcpm[0]; source = fcpm[1]; } if (jQuery("input[name='fc_payment_method']:first").attr("type") == "radio") { method_co = jQuery("input[name='fc_payment_method']:checked").val(); } else if (jQuery("input[name='fc_payment_method']:first").attr("type") == "hidden") { method_co = jQuery("input[name='fc_payment_method']").val(); } if (method != method_co || source == "checkout") { method = method_co; source = "checkout"; wait = true; jQuery.getJSON('https://' + document.domain + '/cart?' + FC.checkout.config.session + '&h:_fcpm=' + method + "|" + source + '&output=json&callback=?', function(cart) { fc_json = cart; if (method != "plastic" && method != "purchase_order" && source == "checkout") { ga('send', 'pageview', '/' + method + '_payment'); } originalValidateAndSubmit(); }); } } if (!wait) { originalValidateAndSubmit(); } } FC.checkout.override('validateAndSubmit', 'ga_tracker'); </script>
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXX-Y', 'auto', { 'clientId': fc_json.custom_fields['ga'], 'storage': 'none' }); var pageview = "/receipt"; if (typeof(fc_json.custom_fields['_fcpm']) != "undefined" && fc_json.custom_fields['_fcpm'] != "") { var fcpm = fc_json.custom_fields['_fcpm'].split("|"); if (fcpm[0] != "plastic" && fcpm[0] != "purchase_order") { pageview += "_" + fcpm[0] + "_from_" + fcpm[1]; } } ga('set', 'page', pageview); {% if first_receipt_display %} ga('send', 'pageview'); {% endif %} </script> {% if first_receipt_display %} ^^analytics_google_ga_universal^^ {% endif %}
First off, we strongly recommend creating a new profile in Google Analytics to test with. That way you don't have to worry about running 100 transactions and completely destroying the accuracy of the analytics, which is the entire point.
For testing, Google Analytics has a great feature called “Real-Time” which is the first option under “Standard Reports” when looking at an individual analytics profiles reports. Using this section, you can pretty quickly track whether your analytics code is correctly set up. What you'll be doing is switching between Google Analytics Real-Time Overview page and your store as you perform different actions to ensure it's tracking you correctly. If it is, you should see an individual session being tracked as you move throughout the checkout flow - changing pages as you do.
Before starting, try clearing your browser's cookies (at least for the domains in question: your site domain and FoxyCart.com) and preferably using a browser that you don't use to develop in. So if you use Firefox to administer your site through a CMS and to login to the FoxyCart admin, try testing in Chrome or Safari. The goal is to pretend you're a normal customer.
_utm*
.Working with Analytics can be a big undertaking at times, and as changes to your set up isn't retroactively applied to previous statistics, can lead to some confusion in your data. We recommend setting up an analytics journal to keep track of any and all changes you make to your analytics profile and tracking code. By doing that, you can quickly compare your statistics to when you applied a certain change to make sure it's working, and possibly explain why the data is different to an earlier time period.