Table of Contents
Add analytics and tracking libraries to your FoxyCart store to discover how customers interact with your site.
Google Analytics (Universal Analytics) Ecommerce Tracking
- You must be including
loader.js(as found on the 'Sample Code' section of your store's administration) in your website template (do not include this in your cart, checkout, or receipt template). If you're not sure if you are, you can view your website source to confirm.
- Your products should use the
SKUparameter in Google Analytics, which is the
codeparameter in FoxyCart. If your products do not include a
codevalue (as passed to FoxyCart) FoxyCart will attempt to generate one from the
nameattribute, but FoxyCart will not take into account duplicate product names, which can clobber your data. If you are not using the
codeparameter for your products, this Google Analytics tracking may not work correctly.
- All your add-to-cart links and forms must point to
Other important Google Analytics stuff
- We strongly recommend setting up a separate Google Analytics profile to test with. This setup can be tricky, it can't be confirmed immediately because Google Analytics has a delay on reporting, and if you use your primary profile it may dirty up your data (which you cannot undo).
- This is all for
ga.js. If you're using an older Google Analytics profile type, we recommend upgrading to the new Universal type.
Setting Up Google Analytics
Getting the Tracking Code
- From the “Admin” section of your Google Analytics account, select the “Account” and “Property” you want to add tracking to. (You may want to create a new profile to test with, so as not to dirty up your real account with test data.)
- In the “Tracking Info” section under “Property”, select “Tracking Code”.
- If you only see the option for the
gtag.jswithin the Analytics administration, you can reference the
analytics.jstracking code you will need from this page.
- Complete the setup as Google Analytics instructs: “Copy and paste it into the code of every page you want to track.” Do not put this code on your FoxyCart cart, checkout, or receipt templates. If you're only using Google Analytics to track FoxyCart transactions, and aren't doing anything else custom with Google Analytics, you can skip the copy/pasting into your own site, and rely on the checkbox in the FoxyCart admin, detailed below.
- Proceed to the next section.
Using Google Tag Manager? Instead of using the Analytics tag that is provided by default with Google Tag Manager, create a “Custom HTML” tag, and paste into that the Tracking Code as detailed above. Also, if you include Google Tag Manager on your cart, checkout or receipt templates, ensure you don't include the Analytics tracking code on those pages - we include it for you automatically.
Configuring Your Profile Settings
- Edit your View Settings in your Google Analytics Settings section. (You can get here by clicking the “Admin” link in the top right, then select your “Account” and “Property” dropdowns.) Select “View Settings” under “View”
fcsidto the “Exclude URL Query Parameters” in your analytics settings. Details here.
- Set your timezone and currency as desired.
- Click the “Save” button at the bottom.
- Click the “Ecommerce Settings” on the left. Enable ecommerce, but leave “Enhanced Ecommerce” off. (If you'd like to see this supported, please let us know. Click the “Submit” or “Save” button.
- Proceed to the next section.
Excluding Referral Sources
- Go back a level in the Google Analytics settings (you may need to click the left arrow on the far left edge of the screen) and click 'Tracking Info', then click 'Referral Exclusion List'.
- Click 'Add Referral Exclusion' and add your website's domain(s). By default, your own website's domain may be present here, but if it's not, you'll need to add it.
- If you're using a FoxyCart subdomain (like
mystore.foxycart.com), click 'Add Referral Exclusion' and enter your store domain and click “Create”. (You can find this in the “store sub domain” value in your FoxyCart admin's “settings” page.) If you're using a custom subdomain like
secure.yourstore.com, you don't need to add it there.
- If you're using a hosted payment option where the customer is redirected to a separate page to complete payment, you will need to add an exclusion for them as well.
|CyberSource Secure Acceptance||
Proceed to the next section
Creating Your Goals
- Go back up a level again (the left arrow at the far left of the screen). Under your property's “View”, click “Goals” and then “Create a goal” or “New Goal”. (Google makes changes to their Analytics interface, so the exact text might be slightly different.)
- Enter a “Goal Name” that makes sense to you, like “E-commerce Sale” or “Transaction” or etc.
- Set the “Goal Type” to “Destination” and click “Next Step”.
- Switch the “Destination” dropdown to “Equals To”.
- Enter for your Goal URL:
- Leave the
Valueswitch off. (It will be calculated dynamically.)
- Turn on the “Funnel” switch and:
- Step 1: use “Cart” for the Name and
/cartfor 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.
- Step 2: “Checkout” for the Screen/Page and
/checkoutfor the URL.
- Hit the “Save Changes” or “Create Goal” button down at the bottom. (The receipt page is the goal, so you don't need to add it in the steps.)
Hosted Payment Method Goals
If you're using a hosted payment method like PayPal Express Checkout or Amazon, you can create additional goals to track specific conversions for those options.
PayPal Express Checkout (Reference Transactions)
Name: “Sale (PayPal as Checkout)“
- PayPal (Checkout),
- Checkout (Confirmation),
- PayPal (Payment Method),
Name: “Sale (Amazon as Payment Method)“
- Amazon (Payment Method),
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)“
- NAME (Payment Method),
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:
|PayPal (Reference Transactions)||
|CyberSource Secure Acceptance||
Proceed to the next section.
Enabling Google Analytics for your store
- Head to your store's FoxyCart administration, and to the template configuration page.
- Enable the 'Configure your third-party analytics' option, and enable 'Google Analytics'.
- Enter your Google Analytics profile tracking ID into the text field.
- If you want FoxyCart to include the Google tracking code on your website, and haven't included it manually yourself - check the option to include it here. This option will include the Google default tracking code within the loader.js file you include on your website. If you're manually including the Google Analytics tracking code on your website, leave this option unchecked.
- Save your updated configuration setting.
Have you customised your cart, checkout or receipt templates? The tracking code is added through the custom footer placeholder within the templates. If you've customised them - double check that you've included the custom code placeholders as detailed on the template customisation wiki page
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.
- Load up your website in one tab and then load up the Google Analytics Real-Time Overview in a second tab. You should see your analytics session tracking that you're looking at your website.
- Add a product to the cart, loading up the cart and then look back and Google Analytics. You should see it change your single user session to be on the cart.
- Complete a checkout, confirming after each stage that your Analytics session is tracking you as you go.
- After completing a checkout, switch to the 'Conversions' tab in the Real-Time section and ensure that your goal has been correctly tracked.
- Clear your cookies, especially any of the Google Analytics cookies, which are named
- If you're using PayPal Express Checkout or Amazon FPS, try testing that a few times both from the cart and from the checkout. Go all the way through, stop before completing, bail out on the PayPal end of things, etc.
- If at any point you see multiple sessions in the 'Overview' page for what you're doing, double check that all of the code is inserted for the page that created a new session as detailed above.
- Once you've tested quite a bit go to your Google Analytics → Conversions → Goals → Funnel Visualization. It should hopefully look something like the image to the right. The key is that the numbers in between the steps are not zero. If you have values there it's tracking the user through the steps, indicating that the Google Analytics info is being passed correctly across domains. If you have zeroes in there, go back through the steps to ensure you have all the code inserted as it should be. Post on our forum if you get stuck.
- Party down! You're done.
Tracking Your Changes
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.
Using Custom Ecommerce Tracking
You can find more information on how to add a custom tracking code here: Using Custom Tracking Code