

- Tracking Google Analytics events with Tag Manager in our Help Center
- Auto event tracking with Google Tag Manager at Justin Cutroni’s Analytics Talk blog
- Event Listener documentation and Event Tracking Macros documentation in our Help Center







![]() |
| Click image for full-size |
![]() |
| Click image for full-size |
Once you save your changes, we’ll generate a new code snippet. Copy it from the Get Code page, paste it into your site and setup is complete!
You can then access Site Search reports from the Content section of Google Analytics.
Happy analyzing! If needed, you can find help with setup here and an explanation of the differences between Google Analytics and Custom Search statistics here. Let us know what you think in our discussion forum.
Finally, visit a page that contains the tracking code you want to test and open up the Chrome JavaScript console to see the messages (detailed instructions). That's it!
Have you ever been in the Visitors section of your favorite Google Analytics profile and wondered what the heck “User-Defined” was? Well today it's time to find out.So, what is “User-Defined?"
The user defined variable allows you to "label" a visitor if they complete a certain action on your site, such as making a purchase or visiting a key page. These labels are useful because they last across multiple visits to your site.
These labels are often called Custom Segments (or Custom Segmentation). You can see the data from these Custom Segments in the User Defined report, which is the last report of the Visitors section in Google Analytics.
How do I add these “labels” to my website visitors?
Making use of the User-Defined report in Google Analytics requires a bit of extra coding help from your IT department or webmaster, but it’s often well worth the effort.
For example, let’s say that I want to add a label of “customers” to any visitor who reaches my shopping cart’s receipt page. In order to do this, 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:
<script type="text/javascript"> 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")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-XXXXXXX-1"); pageTracker._trackPageview(); pageTracker._setVar(”customers”); } catch(err) {}</script>
Notice the line in bold that includes _setVar. When this is present on a page within the Google Analytics Tracking Code, an additional cookie (called the __utmv cookie) gets set on a visitor’s computer, with its sole purpose being to identify the visitor by the label (or value) that you used in the code. 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.
Now, on their next visit to the site, they 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 webmaster to add an “onClick” event, and give them the following line of code:
What will this look like in the end?
When all of your coding is complete, check the User Defined report after about a day or so and you should see something like this:
After the data has been collected by Google Analytics, you can interact with it just like you would with any other report. Click on the “Goal Conversion” tab directly above the table to see how many customers have reached key pages of your site, or use the dimensioning feature to see what sources of traffic were responsible for bringing these special visitors to your website!
Are there any other ways to use _setVar?
One neat usage of the _setVar function is to use it to exclude your own traffic from reports when using a dynamic IP address. For example, let’s say that you wanted to exclude your entire company’s traffic from appearing in reports, and your company uses dynamic IP addresses.
Because it would be nearly impossible to write a filter to exclude traffic from a dynamic IP address, you can create an HTML page that is not a part of your website and add Google Analytics Tracking Code with the call to _setVar and a label of “employees” (or something similar).
Next, you can ask each employee to visit that page from their browser of choice – this will drop a cookie on their computer, identifying them as “employees.” Finally, you can then apply a filter with the following specifications to your profile, and your internal traffic will be excluded:
Some technical notes about Custom Segmentation:
A full, technical explanation of _setVar and the User-Defined Report can be found here.
Summary
The User Defined report in Google Analytics is a great place to start segmenting your traffic. With a little bit of help from your IT department, you can not only begin to collect awesome data, but you can also begin to gain advanced knowledge about what makes your VIP website visitors register, sign-up for your newsletter, or purchase something from your online store. This will definitely help you become that Analysis Ninja that Avinash Kaushik loves to talk about!
Written by Joe Teixeira of MoreVisibility, a Google Analytics Authorized Consultant.