Custom Google Analytics variables, or new features to segment your traffic

    As you probably already know, Google Analytics has been updated recently. This update was also covered here on the hub, - A grand update of Google Analytics

    In particular, the changes affected:
    • The number of goals has been increased to 20 (4 sets of 5 goals each)
    • There are goals of new types (time spent on the site and the number of pages viewed)
    • Web analytics of mobile sites. Statistics from applications on Android and IPhone platforms as well as for websites
    • Adapting Analytics code to the selected platform
    • The appearance of Pivot tables in reports is something that many lacked, and because of which Excel had to be used
    • Filter data in reports on the fly
    • New metric added - unique visitors
    • Extended ability to work with events
    • Completely changed the principles of working with user variables


    On the latter, I would like to stop my attention.

    For a long time, the only way GA was able to segment its traffic in statistics was _setVar () . With the help of this feature, it was possible to set a user variable (only one!) And thus, add the user to a certain category. It looked something like this: Let's say the code above could be on the thankyou_for_registration.html page and here we establish that the user has registered on the site in order to further monitor separately only the behavior of registered users on the site. You can do this in the section Visitors-> User-Defined How it worked: When setting a variable, an additional cookie was set for the user

    pageTracker._setVar(”registered”);
    pageTracker._trackPageview();






    __utmv , the value of which was assigned the name of the variable from the _setVar function, i.e. in our case: "registered". This cookie was set for 2 years.

    Further receiving this cookie, Analytics considered that the user belongs to the segment of registered users on the site.

    In some cases, this was enough, for example, if you wanted to gender-sensitive, whether the user is registered or not, whether you have already made a purchase. But if you wanted to add several such filters, then everything went awry, because if the user has already set this cookie, say, to the value of “registered”, and after that he filled in the info about himself in the profile and indicated his gender, and we called again f-ju pageTracker._setVar (”male”); then the call of this function erased the previous set value ("registered").

    In this way, GA saved only the last value of the variable recorded in __utmv cookies.

    There was a partial solution to this problem, which can be read by clicking on this link.
    The main idea of ​​this solution: do not overwrite the variables in __utmv cookies, but add to the current value of the variable a new one (concatenate a new label to the one already set)

    For example, after successive calls:
    pageTracker._setVar (”male”);
    pageTracker._setVar ("registered");
    In reality, we will only have data that the user is “registered”

    Using the concatenation method:
    superSetVar ('/ male');
    superSetVar ('/ registered');

    We will create the / male / registered variable which will reflect the composite meaning of our segmentation.

    But there was still the problem of calculating such important criteria as the bounce rate and time on site, namely they very much changed bounce rate - growing, time on site - falling. This was because after setting the _setVar variable, the visit was considered new.

    All this together led to the fact that after updating GA the _setVar method became deprecated

    And what appeared instead of him?



    And the __setCustomVar method actually appeared. The

    signature of this method is as follows:
    _setCustomVar (index, name, value, opt_scope)

    In addition to the variable name (name) and value (value), there are 2 more interesting

    opt_scope parameters : there are 3 contexts of variables: 1 (visitor -level), 2 (session-level), 3 (page-level).
    • visitor-level - The lifetime is eternal. It is useful when it is set for the user once and for all (for example, gender, registered or not, whether made a purchase, whether the VIP is a user (client)).
    • session-level - Session lifetime. Useful, for example, for tracking login users and anonymous users.
    • page-level - Used to track events or specific pageviews.


    index - slot. There are 5 slots (1 to 5). The variable must be placed in one of the slots.

    I will not go further into the details, because There is a very good manual from Google on custom variables . True in English. There are examples and described in detail what, how and why.

    I will give an example only how I use it.

    For example, for segmentation by sex and whether the user is registered, on the first page after registration (the same thankyou_for_registration.html) I add When using various scopes, you need to be extremely careful that the variables do not overwrite each other. You can also read about it here.

    pageTracker._setCustomVar(
    1, // This custom var is set to slot #1
    "Users", // The name of the custom variable
    "Registered", // Sets the value of "Users" var
    1 // Sets the scope to visitor-level
    );

    pageTracker._setCustomVar(
    2, // This custom var is set to slot #2
    "Gender", // The name of the custom variable
    "$Gender", // Sets the value of "Gender" to "Male" or "Female" depending on field in registration form
    1 // Sets the scope to visitor-level
    );

    pageTracker._trackPageview();





    In this article I just told you what tools I use to segment traffic, I will be glad to hear what you use :-)

    Also popular now: