August 8th, 2011 → 5:00 pm
by Robert Kingston
// 2 Comments
One of the lesser known features of Google Analytics is that you can use it to target offers and content through JavaScript – much like the features of BTBuckets and many split testing software providers. Unlike these providers however, using Google Analytics can be a cleaner, tidier way that has less of an impact on page load times (since it only needs the GA script to be loaded).
1. You set a custom variable at the visitor level scope (page and session level doesn’t work)
2. Using JavaScript, you read the contents of visitors’ custom variable slots
3. Based on the contents, you can show an offer or message to particular visitors
You can use it for targeting visitors of all sorts of segments – Customer Lifetime Value (high value, low value, none), User type (registered, paying customers, non-member), Facebook demographic data (if you’re using the Facebook Connect API) and many more. I’ll leave that up to you…
It’s all based around the function, _getVisitorCustomVar() – have a read up on Google’s documentation about it here.
Simply place the slot number inside _getVisitorCustomVar() where your visitor level variable is set:
_gaq.push(function () {
var segment = _gat._getTracker('UA-1XXXXXX-X');
var bucket = segment._getVisitorCustomVar(1);
if(typeof(bucket) == undefined) {bucket = '';}
if (bucket == 'xyz') {
// Do this...
}
});
And if you’re using the old synchronous version (or perhaps you just NEED the content to be loaded synchronously):
var segment = _gat._getTracker('UA-1XXXXXX-X');
var bucket = segment._getVisitorCustomVar(1);
if(typeof(bucket) == undefined) {bucket = '';}
if (bucket == 'xyz') {
// Do this...
}
To customise it further, please try my targeting generator script.
Notes:
Alternatively, you can use my free Google Analytics targeting generator to handle all of the customization for you.
Use the Google Analytics Targeting Generator
Sure! I just find this method integrates well with Google Analytics and your segments show up well within your reports. Also, you don’t need redundant scripts for reading/writing cookies.
Show it to your friends:
Tweet
Alexander
6 months ago
Did you can provide some working example with this code? Code example and screenshot of GA report? Thank you.
Robert Kingston
6 months ago
Hi Alexander,
You can find the working code and an example of it right here:
http://www.crotricks.com/content-targeting-ga/example.html
If you’d like to customize the code, there is a simple targeting generator script that I have built:
http://www.optimisationbeacon.com/tools-tweaks/google-analytics-content-targeting-generator/
Try it out and let me know if you have any troubles.