Custom variables at Google Analytics helps you to determine the scope of the visitor engagement. Basically that means in addition to setting just a visitor level segment, you can also set session level segments, which will persist while the visitor is active on the site, and page level segments, which correspond to page views and events on the site. This will help you to get more details from the information you are gathering and storing using custom variables.
The Custom Variable function accepts four parameters: Index, Name, Value, and Scope
The Google definitions for the custom variables are
- index—The slot for the custom variable. This is a number whose value can range from 1 – 5, inclusive. A custom variable should be placed in one slot only and not be re-used across different slots.
- name—The name for the custom variable. This is a string that identifies the custom variable and appears in the top-level Custom Variables report of the Analytics reports.
- value—The value for the custom variable. This is a string that is paired with a name. You can pair a number of values with a custom variable name. The value appears in the table list of the UI for a selected variable name. Typically, you will have two or more values for a given name. For example, you might define a custom variable name gender and supply male and female as two possible values.
- opt_scope—The scope for the custom variable. As described above, the scope defines the level of user engagement with your site. It is a number whose possible values are 1 (visitor-level), 2 (session-level), or 3 (page-level). When left undefined, the custom variable scope defaults to page-level interaction.
The code template for a custom variable is
_setCustomVar(index, name, value, opt_scope)
A detailed documentation with samples on the use of custom variables are available here