Your code for creating a custom variable must be placed prior to the _trackPageview() method.
Consider that you are managing a website for an online magazine which offers different types of articles for their visitors to read. You want to determine which category is more popular. You can accomplish this task using custom variables.
You will need to define custom variables at the page level for every single article based on how you wish to categorize your articles. Your code snippet may look like:
In the above example you are assigning your custom variable to slot number 1. You are labeling your custom variable as Article Category and for this particular article you are setting the value = Technology. Since this interaction is happening on a pageview level, the scope of your custom variable is set to 3.