Use Google Analytics custom variables and simple JavaScript to target site content in real-time

I was reading this on another blog earlier today and thought it was worth passing on. In essence Google Analytics have provided a function to read the custom variables for targeting purposes. Although this is essentially nothing more than being able to read a cookie and use it to segment and target page content, it's nice to be able to use the same variables used by Analytics, as the targeting immediately has context in reports.

If you already use the custom variables (index 1-5), you can now use the following function to read the value and switch out content using some simple JavaScript.

_getVisitorCustomVar()

_getVisitorCustomVar(index)

Returns the visitor level custom variable assigned for the specified index.

pageTracker._getVisitorCustomVar(1); 

Parameters

Int index The index of the visitor level custom variable.

Returns

String The value of the visitor level custom variable. Returns undefined if unable to retrieve the variable for the specified index.

Read the original blog post from Michael Whitaker here or check out the code reference in Google's help section if you want to find out more.

About the author

Check out the Datalicious Supertag: Container tag for smart tag management