How To Set Up Google Analytics eCommerce And Goal Tracking

By
Posted In: How To Guides 

It’s a wet and windy morning here in Yorkshire, which means it is perfect weather for me to write part 2 of my Google Analytics guide. In part 1 I showed you why Google Analytics is so cool, and I gave you some very basic instructions on how to set it up on your website.

In part deux, I’m going to give you a comprehensive step by step guide, showing you how to use Google Analytics to track your e-commerce transactions.

Before I start let me just give you a quick run-down about the different “goals” and e-commerce tracking options, depending on your site some of the guide might not apply to you.

In this example, as well as setting up basic tracking so I can see what the conversion rate for my product is, I’m also going to be setting some goals. Goals can be used for any number of things, you could have a goal set up to see how many visitors sign-up to your newsletter through your opt-in form, or you could use it to see how many people go through your shopping cart and go on to make a purchase.

In my example I’ll be showing you how I use Goals to track how many customers make it through the D9 Hosting shopping cart! Don’t worry if it isn’t making sense, it should all start to come together when you read the guide.

So with that out of the way, let’s get started!

Step 1

This is a nice easy start for you, if you already have an Analytics account then simply log in to your dashboard (admin) area. If you don’t yet have an account then you’ll need to sign-up first – it’s free!

http://www.google.com/analytics/

Step 2

Next we need to create a profile for the website that you wish to generate the stats for. With you now logged into your dashboard, click on the “Add Website Profile” link.

You then need to fill out the small form with the details of your website, it’s all very straightforward but I’ve added a screenshot showing you my settings if you need to use them as a guide.

When you have entered all of the information, click on the “Continue” button.

Step 3

Moving swiftly on to step 3 and one of the most important parts of the process – The Tracking Code!

After clicking on “Continue” in step 2, you will see a screen like the one below:

You are presented with 2 types of tracking code, Legacy and New. I prefer using the New tracking code as it helps get your site ready for any future Analytics features that wouldn’t be available if you were using the old code.

So select the new style code, highlight it and “Copy” it to your clipboard. (Right click on the highlighted code and select “Copy”)

After you have copied the code, click on the “Finish” button. Don’t worry if you lose the code, you can always retrieve it later!

Step 4

Next we need to add the code that we just copied in Step 3 to EVERY page we wish to track – this should be every page on your website, not just the home page!

You should paste in the code just before your closing </body> tag in your HTML source code.

If you have a site with a lot of pages, you could do a global find/replace and find:

</body>

And replace it with:

**The google tracking code here** </body>When you have added the tracking code to all of your pages, you then need to upload the pages to your web space.

If you then go back into your Google Analytics account and look at the Status of your tracking code, you should see a “Tracking code installed” message next to your website profile. If you don’t see this message try again in a few minutes, if you still see errors after a few minutes you need to double check you have pasted the tracking code into your pages correctly.

Step 5

With the tracking code installed, we need to then tell Analytics that our site is an e-commerce website and that we wish to track sales and conversion rates!

To do this, click on the “Edit” link that appears next to your website profile.

You will then see a set of e-commerce options that you can edit, make sure you select “Yes, this is an e-commerce website” and that you select the correct currency that your site sells items in.

When you are done, click on finish.

Step 6

I am now moving onto “Goals”. If you only have a 1 page website and just want to track sales, you can skip to part 7!

In this example I’m setting up Analytics for www.d9hosting.com

One of the things I wish to track is the effectiveness of the shopping cart. The cart is made up of multiple stages, part 1 you select the hosting package, part 2 you select the domain name and so on.

Setting up goals allows me to track visitors as they go through the different steps, it also shows me if the abandon the cart, and at which point they abandon. If a lot of people abandon the cart at the same stage, I know there is a problem and I need to take a closer look!

So now you know why I’m setting up the goal, here’s how you do it:

Find the “Goals” section for your website profile, and click on the “Edit” button:

You will then be presented with a screen asking you to input your goal details.

To save typing out everything here, I’ve taken a screen shot showing you how I set up my goals for my hosting shopping cart:

Your funnel URL’s will obviously be different to mine but as long as you get the URL’s in the correct order you shouldn’t have any problems!

You can also make things easier by not defining a funnel at all. This would be useful if you wanted to track newsletter sign-ups. You would just set the “Completed Goal” URL as:

http://www.yoursite.com/Thankyouforjoining.htm (Or whatever your opt-in success page is called!)

When you are happy with the settings, click on the Finish button and you are done, wasn’t so bad was it?

Step 7

The final step for setting up e-commerce tracking is to add some extra code to our “Thankyou” or “Download” page, in simple terms this is the page that the users gets sent to after they purchase your item/s.

You should already have the default tracking code installed on this page, but you also need to add an extra bit of code, this allows you to enter the sale amount, the order ID and so on.

You can see full details here:

http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55528

But in short, you just need to add the following code under the “pageTracker._trackPageview();” line of the default code:

pageTracker._addTrans( “1234”, // Order ID”Mountain View”, // Affiliation

“11.99”, // Total

“1.29”, // Tax

“5”, // Shipping

“San Jose”, // City

“California”, // State

“USA” // Country

);

pageTracker._addItem(

“1234”, // Order ID

“DD44”, // SKU

“T-Shirt”, // Product Name

“Green Medium”, // Category

“11.99”, // Price

“1” // Quantity

);

pageTracker._trackTrans();

*Please don’t copy/paste the above code, copy it from Google instead. WordPress tends to make a mess when you copy/paste code.

Your final code should look like the code on the Google page here:

http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55528

If you are only selling 1 product then you can enter the values manually, if you are using a shopping cart you should be able to use it to pass the details into the Analytics tracking code. Please contact your script vendor if you are unsure about how to do this.

That brings to an end this guide, Analytics usually takes around 24 hours to update so you’ll have to wait until this time tomorrow to see your results, but once you have everything set up correctly it’s a great resource for any webmaster to use!

Thanks for reading, and I hope you have found it useful.

Let me know if you have any questions,

Regards,
Dan




Receive Free Email Updates When A New Entry Is Posted. Join Them!

Comments

29 Responses to “How To Set Up Google Analytics eCommerce And Goal Tracking”
  1. Hugh Fraser says:

    Dan,
    It possible to setup and uese this with PayPal?
    I use it to track my website and my blog(this is easy to setup if you know what your doing, if not it’s a right bugger as you need a plug in for WordPress).
    Hugh Fraser.

  2. Dan (el_passo) says:

    Hi Hugh,
    I’m sure there will be an IPN script out there that posts the sale data back to your thankyou page.

    Most scripts will do this for you though, DLGuard for example let’s you use loads of variables on your download pages, from memory I think they look something like this:

    %%order_ID%%
    %%order_cost%%

    You’ll need to double check with Sam though as I could be wrong!

  3. sally neill says:

    Hey Dan

    Excellent post well done, hope you enjoyed Prison Break!

    Sally 🙂

  4. So that’s how you do it! 😀 (Well, the ecommerce part)

    This could be your ULTIMATE stats weapon, and use it to your total advantage! Being able to see were abouts your visitors get distracted/don’t understand is pretty cool I think. 🙂

    As always Dan, another GREAT lesson. Looking forward to what you’ve got planned for the next one…

    Thanks
    Mark

  5. Dan (el_passo) says:

    Thanks for the comments everyone.

    @Sally – The ending was nothing great but overall the episode was ok, it had some good moments, but you could tell that the writers strike messed up a lot of the planned story 🙁

  6. Amit says:

    Hi Dan,

    Everytime ur blog learn me something new… this is very helpful..

    Thanks,

    Amit Chivilkar
    Mumbai, India
    http://www.justmoneymaking.info

  7. John says:

    Well that is what I call a detailed explanation, and I was thinking about how this was done. Thank you for sharing.

  8. Moe says:

    Great post, Dan. I’m hoping you could provide a small bit of advice.

    I’m running a Google Adwords campaign that drives traffic to a survey page.

    I understand that it’s possible to track which ad groups lead to a survey completion by using e-commerce goals.

    But I have no idea how to alter the e-commerce script to include the one variable that I would like to track (i.e. the survey response ID).

    Any suggestions for how a non-techie could learn how to do this?

  9. Dan (el_passo) says:

    Hi Moe,
    To be honest I’ve spent many an hour pulling my hair out using eCommerce tracking, just when you think you’ve got everything perfect…BOOM, it doesn’t work!

    In theory (!) your survey should be passing varibles to the success page, so all you’d need to do is find the variable name, then add that to the eCommerce tracking code that you can find from within your Google Analytics admin area.

  10. Moe says:

    Thanks a lot for your quick response to my question, Dan. I’ll try that.

    Moe

  11. ana says:

    Hi Dan,

    Thanks for sharing. I’m a web designer that’s been asked to set-up Google Analytics and boy was I confused big time!

    I started to hate it, then I saw your article. Somehow it gave me hope that I’ll be able to pull it through 😉

    Great blog.

  12. Dan says:

    No problem Ana!

    Just give us a shout if you get stuck 🙂

  13. SAntosh says:

    Hi the information provided by you is very useful thanks for this…but i have 1 doubt pls clear this …like i have to do ecommerce tracking for a shopping cart website….I dont understanf that how and where to paste this code and what would be the format of the code if i m selling 1000s of product with different price….how will google track each product…and what information do i have to enter on this page pls clear me this as i want to track exact sale price or revenue from the sale pls guide…

    pageTracker._addTrans( “1234″, // Order ID”Mountain View”, // Affiliation

    “11.99″, // Total

    “1.29″, // Tax

    “5″, // Shipping

    “San Jose”, // City

    “California”, // State

    “USA” // Country

    );

    pageTracker._addItem(

    “1234″, // Order ID

    “DD44″, // SKU

    “T-Shirt”, // Product Name

    “Green Medium”, // Category

    “11.99″, // Price

    “1″ // Quantity

    );

    pageTracker._trackTrans();

    • Dan says:

      To track sales, you’d need to paste the code in your thankyou/receipt page. You’d then need to find out the variable names that are passed onto that page, and the names of them.

      It will vary depending on the script you are using, but the vast majority will pass on important info like the price, product name, receipt number and so on.

      So all you need to do is find the variable names from the scripts developer, and add them to the analytics code.

      Eg:

      pageTracker._addTrans( “1234″, // Order ID”Mountain View”, // Affiliation

      “$total″, // Total

      “$tax″, // Tax

      The above would work if the variable name for the total cost was $total, but check with the script developers to get the actual names.

  14. SAntosh says:

    1 more question do i have to define separate Goal for ecommerce tracking as i already have 1 goal defined for conversion tracking… 🙂 pls guide me soon….:)

    • Dan says:

      You could have a goal set up for anyone that lands on the receipt page, but if you are using conversion tracking and ecommerce tracking then you probably wouldn’t need to, but it’s up to you really.

  15. SAntosh says:

    how much time it will take to show the results for ecommerce tracking if i already have analytics code on my website running since 2 years….

    • Dan says:

      The analytics reporting isn’t in real time, it seems to update every few hours or so. So if you give it 24 hours just to be on the safe side you should start to see some results.

  16. SAntosh says:

    Hi Dan

    I have implemented the code yesterday itself and it was working fine as the data was showing on the Thankyou page for purchasing order…but it is still not reflecting on analytics ecommerce section can u guide me on this how much more time it will take….coz its almost 24 hrs

    • Dan says:

      Hi,
      If it still isn’t showing them you have implemented it incorrectly, I’d advise you to go through the documentation and double check you’ve got everything set up correctly.

  17. Santosh says:

    Hi Dan,

    I have implemented the ecommerce tracking code on my site and the data is also displayed under the ecommerce section but the problem is there is a difference between the adwords conversion and between the Ecommerce data. I mean if i have 2 conversion on adwords account for 17th may then it is showing 1 conversion under the ecommerce section under analytics. why there is difference between the data is it a problem of google or something problem at my end because the same situation is for my 2 clients…can you please help me out here why the difference is…pls

  18. Santosh says:

    Hi Dan,

    I have implemented the ecommerce tracking code on my site and the data is also displayed under the ecommerce section but the problem is there is a difference between the adwords conversion and between the Ecommerce data. I mean if i have 2 conversion on adwords account for 17th may then it is showing 1 conversion under the ecommerce section under analytics. why there is difference between the data is it a problem of google or something problem at my end because the same situation is for my 2 clients…can you please help me out here why the difference is…pls

    • Dan (el_passo) says:

      Hi Santosh,
      Unfortunately I have no idea why it’s bringing back different data, I’ve never used it in conjunction with Adwords so don’t really know how it works. I’d suggest contacting the Big G.

      Sorry I couldn’t be of more help!

  19. Olivia says:

    We are a little hotel with a little marketing budget so my question is how can I track revenue when guests book rooms? When they click on book now and it directs them to a 3rd party booking engine – how can I track that?

    Thanks

  20. ACT says:

    Hej, first of all thanx for the tips. I implemented the code in google analytics and works fine with one sale product. But couldn’t get it work with more than one sale product. Any ideas? Where can i find a script that generates automatically a value of each product?

    Thanks

    • Dan (el_passo) says:

      Hi,
      It would depend on what script you were using on your site, but most will allow you to pass on the value of each product in a variable. If you check the documentation of the script you use, you should be able to find the answer.

Speak Your Mind

Please do feel free to leave a comment, I read them all...

and oh, I'm sure you don't look like a monster, so why not go get a free gravatar so a pic can be displayed with your comment!