At the company I work for, I was already using Google Analytics to track visitors to the website, but I wanted a little more information. I wanted to see how many visitors were staff, versus other visitors.
Put the Pieces on the Table
The first piece we needed was already in place. We are using Drupal for our website, and every staff member needs to log in from time to time for various staff only resources. Regardless of any other permissions they may have, everyone who is staff is made part of the role “staff”.
Google lets you add up to 5 custom variables to your Google Analytics tracking with the _setCustomVar() function. There are 4 parameters: Slot Number, Variable Name, Variable Value, Variable Scope.
The Variable Scope can be set to 1,2 or 3. 1 is for visitor level scope. A variable with scope 1 will be tracked even if the user has logged out of the site. 2 is session level scope. A variable with scope 2 will be tracked as long as their current session lasts — usually till they close their browser. 3 is page-level scope, which I did not use.
I decided to set two variables, a Visitor scope variable, and a Session scope variable. This way I could not only tell when users were logged in, but compare logged in staff visits to logged out staff visits. I needed to only set these variables when the user is logged in however, which takes us to the next step…
Putting the Puzzle Together
Granted, this isn’t really a hard puzzle, each piece is really simple…which is probably why when I searched for how to do it initially I didn’t find a tutorial .
Stepping Back and Looking at the Results
The last thing to do is to set up your segmentation in Google Analytics. In the left column of Analytics you should see Advanced Segments in the My Customizations area. Once you have clicked that, choose Create a new custom segment. The custom variables you defined in the steps above should be listed under the Visitors area of the Dimensions section. Drag the custom key and/or values desired to your segment creator, then save it.
If you are tracking company computers for logged off users as I am, you will need to wait a few days or weeks for all of the appropriate cookies to be set. The cookies aren’t set unless the user is logged in, and not all of our staff members log in every day.