Onsite targeting with Google Analytics

A logical progression from segmenting your data in web analytics is to then be able to target those segments. For example, you might want to show a special offer only to loyal repeat customers and not to others.

In a very informative webinar last week by the Google Analytics team on custom variables, one particular example caught my attention: the ability to not only set a custom variable, but also to read its value.

Let’s assume that I set a custom variable called CustomerType on the transaction page that has the possible values New or Repeat, then it sounds like we will be able to do something like this:

<script>var customertype = pageTracker._<strong>getVisitorCustomVar</strong>(1);<br /> if (customertype = 'Repeat') {<br /> display special offer on the page<br /> }<br /> </script>

The method _getVisitorCustomVar() is described in the GA code site. Cool stuff!