---- dataentry ---- type : integration # do not change this line system : Google Analytics name : Ecommerce Tracking for Google Analytics description : Tutorial to set up ecommerce tracking for Google Analytics and FoxyCart tags_tags : analytics, tutorial, tracking date_dt : version : developer_url : ---- ====== Google Analytics Ecommerce Tracking ====== ===== Read This First: Assumptions ===== - We're using ''ga.js'' and not ''urchin.js'', because it's way more hip. If you need to use ''urchin.js'', it should be similar to this but there will be a few things you'll have to change. - If you've applied any advanced filters to rewrite your request URIs you'll need to take that into account when setting your goal and funnel. If you don't know what that means, you probably don't have to worry about it, but rewriting the request URI can be useful when you're tracking multiple subdomains in one profile. ===== Other important Google Analytics stuff ===== * [[integration:googleanalytics:campaign_tracking|Tracking your banner ads and email marketing links]]. Very cool, and you should definitely do it if you're going to do anything described below. ===== Setup Your Tracking Code ===== ==== With a Custom Subdomain (ie. secure.yourdomain.com) ==== - Because you're tracking users across multiple subdomains (ie. ''yourdomain.tld'', ''www.yourdomain.tld'', ''secure.yourdomain.tld'') you'll need to change your tracking code slightly: http://www.google.com/support/googleanalytics/bin/answer.py?answer=55532 - So your tracking code (for your //entire site//, not just the FoxyCart pages) should look something like this: - Follow the steps below. ==== With a *.foxycart.com Subdomain ==== - We're still working on this one. The GA code messes with FoxyBox a bit, but we're working on a solution. http://www.google.com/support/googleanalytics/bin/answer.py?answer=55532 ===== Setup Everything Else ===== - **TESTING:** Because Google Analytics doesn't allow you to undo or remove data you've collected, you want to make sure you get it right before you go adding it to your main profile. For this reason, we recommend doing the following steps on a //new profile//. Call it "Testing" or something, and make sure it's working correctly there before applying it to your main profile, otherwise you'll have a bunch of wrong data throwing off your analytics. - **PROFILE:** Edit your Profile Settings - Add ''PHPSESSID,fc_PHPSESSID'' to the "Exclude URL Query Parameters" in your analytics settings. [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55499|Details]] - Set it to "Yes, an E-Commerce Site" and set your currency as desired. - You probably want to set your "Default Page" to ''index.html'' or ''index.php'' or etc. Make sure you understand what this means, as it affects stuff like ''yourdomain.com/'' as well as ''yourdomain.com/dir/sub/''. - **GOAL:** Go back to your Profile Settings and click "edit" on one of your four goals. It doesn't matter which, but Goal #1 will show up by default in most of your GA reports, so if this is your only (or your primary) goal, you probably want to set it up as Goal #1. - Make sure it's set to "Active" up top. - Switch the Match Type to "Exact Match" - Enter for your Goal URL: ''/receipt'' - Enter a "Goal Name" that makes sense to you, like "Orders" - Go down to Step 1 and enter ''/cart'' for the URL and "Cart" for the Name. - Step 2: ''/checkout'' for the URL and "Checkout" for the Name. - Hit the "Save Changes" button down at the bottom. (The receipt page is the goal, so you don't need to add it in the steps.) - **CART:** Edit your cart in the FoxyCart admin, or on your site if you use AutoMagiCache on the cart. - Add the Google Analytics script to the bottom of your cart template [[http://www.google.com/support/googleanalytics/bin/answer.py?answer=55488&topic=11126|as directed]] in your account. **Make sure you actually get the code from your profile**, and not the XXXXX code from the documentation. Edit your profile, then hit the "Check Status" link towards the top of the page if you need to get this code again. Use the //New Tracking Code (ga.js)// code, not the urchin.js code. - **Change the bottom line** from ''pageTracker._trackPageview();'' to ''pageTracker._trackPageview("/cart");'' - If you're using FoxyCart with the default "FoxyBox" (Thickbox), which you probably are, we'll need a workaround: * Edit your code to look like this: * The important piece is the stuff in between the ''Workaround'' comments, which delays the Google Analytics slightly. The ''2000'' is 2000 milliseconds (2 seconds). You could probably change the ''2000'' to ''1000'' or ''1500'' if you're concerned that people might close the cart before that time. However, if you set it too low it will error and Google Analytics won't record the page view. - Update your cart template in the FoxyCart admin. (AutoMagiCache -> Save or just paste in the new one and save). - **CHECKOUT:** - Add your GA code to the bottom of your checkout template just like you did with the cart. - **Change the bottom line** from ''pageTracker._trackPageview();'' to ''pageTracker._trackPageview("/checkout");'' - **RECEIPT:** - Set up a receipt template separate from your checkout template if you haven't already done so. It can be identical to your checkout template for all intents and purposes, except for the very bottom GA code. - **Change the bottom line** from ''pageTracker._trackPageview();'' to ''pageTracker._trackPageview("/receipt");'' - Beneath your GA script tags, add ''^^analytics_google_ga^^''. This generates code that tracks the sale, is what actually tracks the ecommerce transaction. (If you're using ''urchin.js'', use ''^^analytics_google_urchin^^''.) - Your finished code should look something like this: ^^analytics_google_ga^^ The ''^^analytics_google_ga^^'' will output the cart array, as described [[http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55528|here]]. GA will pick up on this automatically. - **TEST:** This //should// work, but testing is always required.