Suppose I want to add a label of “customers” to any visitor who reaches my shopping cart’s receipt page. I would add an additional line of code to the Google Analytics Tracking Code (GATC) on my receipt page. It would then look something like this:
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); try { var pageTracker = _gat._getTracker("UA-XXXXXXX-1"); pageTracker._trackPageview(); pageTracker._setVar(”customers”); } catch(err) {}
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); try { var pageTracker = _gat._getTracker("UA-XXXXXXX-1"); pageTracker._trackPageview(); pageTracker._setVar(”customers”); } catch(err) {}
Notice the line in bold that includes _setVar. If you take a look at the code example above, you will see that I used the term “customers,“ the label that I want to appear in the User Defined report.
When a user visits the page he will be identified as a part of the “customers” segment in the User Defined report, allowing you to perform analysis on all visitors who have purchased something from your online store. Neat, huh?
Can I use _setVar when someone clicks on a link instead of visiting a page?
Yes - you can also use the pageTracker._setVar function when someone clicks on an important link on your site, or makes a key selection on an important form that you want visitors to fill out. For example, if you wanted to add a custom label to any visitor who clicks on your “Live Help” applet, you can ask your IT department or webdesigner to add an “onClick” event, and give them the following line of code:
What will this look like in the end?
No comments:
Post a Comment
Speak your mind