⬆️ ⬇️

Traffic segmentation with _setCustomVar in Google Analytics

For traffic segmentation, Google Analytics has such a great _setCustomVar method.



Method signature: _setCustomVar (index, name, value, opt_scope)



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

name is the name of the variable.

value is the value of the variable.

opt_scope - variable context: 1 (visitor-level), 2 (session-level), 3 (page-level).



My examples of using this method are:

  1. 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

    );

    I use this segment to track the behavior of registered visitors.

  2. pageTracker._setCustomVar (

    2, // This custom var is set to slot # 2

    "User", // The name of the custom variable

    "$ username", // Sets the value of "User" to "$ username" depending on current visitor

    2 // Sets the scope to visitor-level

    );

    and this segment to track the behavior of a specific authorized user.



The main problem arises in the allocation of the created segments in the Google Analytics panel, since currently, they are not visible in standard reports.

')

In order to select, for example, a segment of all registered visitors, you must create a new segment. For this:

  1. Go to the link " Segments with advanced settings " in the " My Settings " block in the left GA menu.
  2. Click on the link " + Create a new user segment ."
  3. From the " Sizes -> Visitors " list, drag the " Custom Variable (Value 1) " to the " value or metric " block.
  4. Select the condition " exact match " value " Registered ".
  5. Set the name " Registered Visitors " for the segment.
  6. Click the " Create Segment " button.


The segment has been created; now it can be selected on any report. To do this, simply select " Segments with advanced settings " above the date interval and select the created segment in the " Custom Segments " list.



For the second segment (tracking authorized users) it is convenient to create a custom report.

  1. To do this, go to " My Settings -> Custom Reports -> + Create a new custom report ."
  2. Next, drag the required indicators into blocks " indicator ".
  3. Drag the " Custom Variable (Key 2) " indicator from the " Dimensions -> Visitors " list to the measurement block.
  4. In the nested dimension we drag the indicator " Custom Variable (Value 2) " also from the list " Sizes -> Visitors ".
  5. Save the report.


Now this report can be viewed in custom reports. When we just go into this user report, we see general statistics for all authorized users, and if we go to the next level (in our case, the User variable (Custom Variable (Key 2))), we will see statistics for each authorized user.



These are my examples of real use.



You can also read a detailed manual from Google on custom variables.



Thanks for attention!

Source: https://habr.com/ru/post/76891/



All Articles