I believe that every business can use Google Analytics custom variables. Especially ecommerce businesses. Custom variables inject new data dimensions that are crucial for segmentation. As analysts we need to do segmentation to understand user behavior. And ecommerce sites have certain unique behaviors that are not tracked with a basic Google Analytics implementation.
For those that have not used custom variables before you can get read Mastering Custom Variables for overview.
Now on to the custom variables!
Tracking Coupon Codes and Promotional Codes
I think this is a pretty obvious use of custom variables. If you sell something you probably run various promotions. And you need to track these promotions to see how they perform. Some promotions can be tracked using campaign tracking. I’ve seen lots of people use the utm_content parameter to identify the promotion in a marketing campaign, like an email. But a custom variable works just as well.
When coming up with a strategy think about how you might scale this as time goes on. Do you want all of your promotional codes aggregated together under one variable? You could do something like this:
_gaq.push(['_setCustomVar',1,'PromoCode','
Or you could get fancy and use different custom variables to bucket groups of promotions, like seasonal promotions. For example, if you lots of promotions during the holiday season you might want to create a custom variable named HolidayPromos and then a unique name for each of the codes, something like this:
_gaq.push(['_setCustomVar',1,'HolidayPromo','Free2DayShip',3]);
_gaq.push(['_setCustomVar',1,'HolidayPromo','FreeWrapping',3]);
_gaq.push(['_setCustomVar',1,'HolidayPromo','10perOff',3]);
The above code would need to appear on your receipt page. And remember, the slot, or index, in the code above may be different for you. It all depends on your use of custom variables.
You might be wondering why I decided to go with a page level custom variable here. Remember, Google Analytics will sessionize a page level custom variable. So even though the custom var will only fire on the receipt page the data will be applied to the entire visit.
Tracking Payment Method
Remember, we study visitor behavior to understand the impact on business. One of these behaviors is how people pay for a purchase. Is there a difference between a visitor who pays with a credit card vs one who pays with PayPal? Does one spend more, on average, than the other? You’ll never know unless you capture payment type and review metrics like average order value and conversion rate.
To capture payment type use a page level custom variable. The resulting GA code will look something like this:
_gaq.push(['_setCustomVar',2, 'PaymentType','
Don’t forget to replace
with the customer’s payment method.
Tracking Shipping Method
Like payment method, it’s interesting to see what shipping method people choose with various products. Why? Perhaps people who buy certain products choose certain types of shipping. If so, maybe you can build a new promotion using this information. Could there be no insights here? ABSOLUTELY! But you’ll never know unless you have some data and do a bit of analysis.
_gaq.push(['_setCustomVar',3,'CustType','Repeat',1]);
Tracking Repeat Customers
I remember reading Eric Peterson’s book Web Analytics Demystified a looong time ago. Besides being one of the first books on analytics it was exceedingly actionable. One of the ecommerce key performance indicators Eric talked about, and rightfully so, was the repeat-buyers.
The behavior of repeat customers is different than first time customers. This segment of customers usually takes less time to purchase due to a knowledge of your products and services. Normally it costs you less money to get these people to convert. So it’s a good idea to understand what marketing they respond to and how they use your website.
To track repeat customers in Google Analytics you must use a visitor scope custom variable. Remember a visitor scoped custom variable persists on the visitor’s computer as a cookie. The trick is when you set the custom variable.
Most people think you can set the custom variable when the transaction happens, like this:
_gaq.push(['_setCustomVar',4,'CustType','Repeat',1]);
But in reality this will not work. When you set a visit level custom variable the value gets applied to the CURRENT visit and all future visits. So you need to wait until the SECOND purchase before setting the above custom variable. Then it should work just fine.
[UPDATE: Elizabeth Brings up a good point in the comments. This method will only work if the visitor comes back and makes a second purchase on the site. You can tweak the above logic and set the custom variable on the visitor’s return to the website, rather than when they make a second purchase. While this is not perfect it is a workaround.]
I should note that this is an AWESOME custom variable to use in an advanced segment. Actually, they’re all great to use in Advanced segments, but segmenting repeat buyers is especially useful
Purchase History
This is where things get a little more complicated. Tracking things like purchase history requires a bit of configuration on the server side, meaning you or your nerds need to create some code to categorize customers based on the number of purchases they’ve made in the past. Rather than track every single purchase I prefer to bucket the purchases, like this:
- 1 to 3 purchases
- 4 to 6 purchases
- 7 + purchases
You need to have the logic on the server to review the custom’er purchase history and set the custom variable accordingly. The GA JavaScript will look something like this:
_gaq.push(['_setCustomVar',5,'PurchHistory','1-3',1]);
Now you’re probably thinking that there is some duplication with the previous custom variable, and you’re right. The repeat customer variable is a bit more generic and gives you a quick view of new and returning customers. The purchase history variable is geared towards deeper analysis of customer behavior.
So there you have it, five custom variables for ecommerce websites. This is by no means an exhaustive list, but I think these can help any commerce based business to better segmentation and analysis.
Are you using custom variables on your ecommerce website? If so I’d love to hear how!
Hi Justin,
Useful Article. It will be even more useful when more than 5 CustomVars are available ;)
Regarding “Tracking Repeat Customers”…
Do you have an example of the php serverside code used to set the repeat customer?
[e.g. GroupBy CustomerID where count(Transactions) >=2 ]
Many Thanks
Phil
Note: if scope is left empty it defaults to visit-level
[‘_setCustomVar’,4,’CustType’,’Repeat’]
@Phil: I agree, having more custom variables will be helpful. I tried to use mostly page level custom vars to minimize the impact on an implementation, but sometimes it’s hard to keep it to 5 custom vars. Most of my clients do the server side coding, and my PHP skills are rusty! Let me see if I can get one of our guys to bang something out. (And thanks for the edits!)
Sweet little GA ninja tricks!
Funny, I did a post (in Danish) just last week about tracking repeat customers:
http://www.afdeling18.dk/blog/2011/6/3/ga-tricks-skaffer-mine-kampagner-nye-eller-gamle-kunder.aspx
(Sorry for the plug, feel free to remove it if you’d like)
But instead of custom vars I usually choose to use the “Affiliation” field of the eCommerce tracking code instead. Mostly because it’s at that point in time in your backend code that you’ve got the customer details anyways, so you can figure out whether it’s a repeat customer or not.
Anyways, being able to track repeat customers in Google Analytics does wonders with your Google Adwords campaigns, as you’re then able to better grasp customer lifetime value (or cost rather) and take your campaigns to the max.
@Soren: Thanks so much for the link to your post! While I don’t know exactly what you wrote I’m more than happy to leave it up.
Using the Affiliation field to track repeat buyers is a good idea. The reason I chose to use a custom variable is:
1. Ecommerce dimensions can not always be combined with click-related metrics in a custom report.
2. The Affiliate field does not persist across multiple visits. So while it does provide data about the purchase behavior it does not help us understand cross-session browsing behavior.
Thanks for the link and comment.
Great suggestions Justin, have added to my list of standard custom variables for ecommerce clients.
Can I also suggest:
* On the Product Details page
– Availability (proportion of sizes/colours available)
– Brand
– Price Range (group into buckets so low, medium, high)
– Sale (flag if at a reduced price)
* On the Search Results page
– Number of search results
@Peter: Great suggestions Peter, thanks for adding them here. As a note, I would add most of those a page-level variables or perhaps even events, especially if I’m using all 5 custom variables.
Thanks Justin — I am interested in the repeat customer custom variable. I previously implemented it as a visitor-level custom variable, because I think the original Google Analytics documentation said it would apply to future visits only, rather than the current visit, but as you point out I was frustrated to notice that it actually applies to the current visit as well. I would love to be able to identify a return visitor as a prior customer, to compare their visit conversion rates to other visitors. Your solution will only identify them when they purchase the second time (so it will be a 100% conversion for that visit) — do you know any solution for tracking ALL return visits for prior customers and excluding the visit of that first purchase?
@Elizabeth: You make a fantastic point. I’ve updated the post to include info that aligns more with your comment. It’s probably better to bucket a customer on the following visit, not purchase. In all honesty, OMTR is way better at this than GA. They’re able to draw a clear line in the sand when a visitor moves from one custom segment to another.
Excellent tips. Custom variables are something we are playing with and it’s an area that most Analytics users don’t even know exist. Track everything, should be the Google Analytics motto.
Just to clarify Phil’s note at the beginning, if scope is left blank it defaults to page level, not visitor level. More on that here: Custom Variables.
Cutroni has just written an excellent post on five Google Analytics custom variables that ecommerce companies should definitely use. – We vouch for that, great post.
Great article Justin :)
Though I didn’t already applied this to our current implementation, one thing came to my mind.
In the case of custom variables used for ecommerce, most of the people would probably like to get ecommerce data to be attached to custom var reports (Audience => Demographics => Custom Variables) to get a revenue perspective of their custom variables.
Problem is that using Custom Variables with Page level scope (3), eCommerce data won’t get parsed to the custom var inside those reports.
So, as you mention that Google Analytics will sessionize a page level custom variable, you might want to apply a Session level scope (2) to custom var used in eCommerce context to be able to see eCommerce data for each custom var.
Hello,
i have a small site mentioned above i have created a payment hub called as mypaymenthub.com for the mentioned website, there i have page where user registers and fills the form on that page,
I wanted a goal that shows me the visitors from my site to the register page on the my payment hub
can anyone please help me with the query.
Thanks,
Charmis
@ Charmis – I’m assuming that everything is on the same domain. If so, then you should be able to create a goal (specifically a URL destination goal) for the registration page. If your payment hub is NOT on the same domain then you need to look into cross domain tracking. And if you don’t control the code on the payment hub then you need to work with the payment hub provider to get things working. Cross domain tracking can be really messy.
Hope that helps.
Webmasters usually me know the detailed settings. Those who claim to know too lazy. Those who have used them you are reading now! :)
Justin,
We recently added a page-level custom variable to our site to track “Content Groups” (which is a pretty standard CV implementation). We were surprised, however, to see that the page-level CVs do not have any revenue metrics attached to them.
How would you go about creating a revenue breakdown of the areas of your site (Content Groups) using CV? I thought that the page-level CV would certainly retain the revenue aspect, if that visitor checks out, but it’s not that way for us.
Thanks for your input,
-T
@ Thiago – All of the ecommerce metrics should be compatible with a page level custom variable. Are you just looking at the Ecommerce tab in the Custom Variable reports or are you trying a Custom Report of the API?
Justin,
Great article. I know this is old, so not sure if I will receive a response, but here goes.
Your repeat customer custom variable brought up another piece of information I am wanting. We run PPC campaigns and some of those campaigns are geared to be introducers/informers rather closers. So I want to see if visitors are making return visits after a visit (preferably their first) from one of those campaigns. I figured you would need to use a visitor level CV, but not positive. Or how the advanced segment would look.
Any insight?
Thanks.
@DavidG: Yes, you would need to use a visitor-scoped custom variable to identify people coming from those PPC campaigns. But what about using the Multi-channel funnels report? If the visitor converts then you’ll see that campaign/adgroup/keywords in the MCF reports.
Thanks for the response Justin. I did consider it, but the MCF reports only look back 30 days, right? Our buying window often is longer. Plus, having it as a CV would allow me to apply other advanced segments to it.. Where, as far as I can tell, I can’t do that in the MCF.
Thanks again.
Hello,
Is it possible to add a coupon code at order level and/or order-product level?
What i need to do, if possible, is to generate a report where i can see the something like this:
For An Order:
Product | Quantity | Unit Price | Promo Code | Revenue
Obviously the revenue has to have the (UnitPrice * Quantity) – (CouponDiscount)
Hope you can help me out with this. Thanks!
@Ramos: Unfortunately no, there is no simple way to do that. You can hack this. The easiest way is to create a secondary product line foe each coupon/product combination. That would be the only way to create a product-specific coupon. The coupon “product” could have a negative value to subtract the correct amount from the total transaction value.
That’s about it. There really is no easy way to do this.
Great question, thanks for asking.
Thank you for the informative post about CV for ecommerce sites. I’m about to implement CVs for a site I manage and I read the news about Universal Analytics. I wanted to know if we no longer needed a CV for repeat customers given that would be a tracking metric that would now be available to us. Is that correct?
Thank you,
Matt
@Matt: Once we get true user segmentation you will no longer need to use a custom variable (or custom dimension in the new Universal Analytics) to track repeat customers. I should point out that user segmentation is a separate feature from Universal Analytics.
Hope that helps.