Talk to a sales representative

+1 844-822-8378

Write to us

How To Connect VWO to Google Analytics Universal Tracking

Posted in How To on

Update: VWO now provides direct integration with Universal Analytics. Read this post to know how to integrate VWO with Universal Analytics in your dashboard.

Google Analytics recently launched a new way of tracking visitors on your site. This new tracking is called Universal tracking and sets the standard for their future. It’s more enhanced and has some cool new features that can be used with Visual Website Optimizer also.

One of those features is the so called Custom Dimension. We’re now able to define a Dimension or Metric ourselves. An example of a self-created metric could be the age of your visitor. If you have that info and use it to put it in Google Analytics you could create reports that show average age per source/medium for example.

For Visual Website Optimizer the Custom Dimension is the most interesting one. I created a script that takes the experiment number and variant out of VWO and puts it in a GA Custom Dimension. That makes us able to use the VWO test-variant number as a dimension compared to for example browsers or countries.

 How does it work?

First of all you have to define a new Custom Dimension in Google Analytics. Go to the Admin section and look for your property settings. There you will find the Custom Definitions option if your are using Google Analytics Universal Tracking for that property.

Open it and choose for the Custom Dimensions. Click on “New Custom Dimension” and fill it in like this:


On the right side in the example codes you will see the number of this new created dimension, it is 1 if you never created a custom dimension before. Remember that number.

Now we have to alter the VWO tracking code on your site so the code can send the right information to Google Analytics. Take this piece of script and put it below the existing VWO and GA code:

<script type="text/javascript">
window._vis_opt_queue = window._vis_opt_queue || [], _vis_counter = 0,
  dimensionMap = {"1": "dimension1","2": "dimension2","3": "dimension3","4": "dimension4","5": "dimension5"};
_vis_opt_queue.push(function () {
    try {
        if (!_vis_counter) {
            var _vis_data = {}, _vis_combination, _vis_id, _vis_l = 0;
            for (; _vis_l < _vwo_exp_ids.length; _vis_l++) {
                _vis_id = _vwo_exp_ids[_vis_l];
                if (_vwo_exp[_vis_id].ready) {
                    _vis_combination = _vis_opt_readCookie('_vis_opt_exp_' + _vis_id + '_combi');
                    if (typeof (_vwo_exp[_vis_id].combination_chosen) != "undefined")
                        _vis_combination = _vwo_exp[_vis_id].combination_chosen;
                    if (typeof (_vwo_exp[_vis_id].comb_n[_vis_combination]) != "undefined") {
                        _vis_data[_vis_id] = "TestId: " + _vis_id + ",VarName: " + _vwo_exp[_vis_id].comb_n[_vis_combination];
            if (_vis_counter) {
                vwo_$(function () {
                    for (var testid in _vis_data) {
                        dimensionMap[testid] &&"set", dimensionMap[testid], _vis_data[testid]);
          'send', 'event', 'VWO', 'Custom', {'nonInteraction': 1});
    } catch (err) {};

This script retrieves the test ID that is conducted and the variation that is shown to the visitor. It will then set custom dimensions corresponding to the test ids as defined in the custom dimension map."set", dimensionMap[testid], _vis_data[testid]);

This picks the dimension name from the dimension map defined in the code so that you can track data of multiple tests running on the website in different dimensions. Same dimension should not be used to track data for more than one test.

For eg. let us say you are running test ids 45, 46 and 47 and you want to send the data to “dimension7″, “dimension8″ and “dimension9″ respectively, just initialize the object (dimensionMap) as:

dimensionMap = {"45": "dimension7", "46": "dimension8", "47": "dimension9"};

Because the above rule doesn’t send anything to Google we have to use an extra line to send this data to Google. I choose to do it with an event like this:'send', 'event', 'VWO', 'Custom', {'nonInteraction': 1});

The event contains information that it is sent by VWO. The event is “non-interactive” so it won’t be used for bouncerate calculations etc.

The results

After some days of testing you can see how your test(s) performed by creating a Custom Report in Google Analytics like this:


 The blurred fields are several Goal conversion percentages, but you could choose any metric you would want to see. Save it and have a look at those cool new numbers: 


You see a column called “VWO Test”. That is the name we used when we created this dimension. You can use this column as a secondary column in each report you want.

If you have a lot of tests running at the same time you could edit this custom report and use the filter in there to get the right experiment by selecting the right dimension. That way the report will be for 1 experiment only and you won’t have to look it up again next time:


That’s it for now, happy testing.

Got questions? Put it in the comments.

Editor’s note: some parts of this post have been edited by Visual Website Optimizer’s engineering team.

Comments (4)

  1. Hi André,

    Thank you for posting this article.

    You give an example with test id 45, 46, 47. Does this mean the custom integration script has to be edited every time a new test is conducted?

  2. AnkitJain@Wingify says:

    Hi Wouter,

    The custom script does require editing for each new test you want to track inside Google UA. It is required to map each test to a specific custom dimension inside UA. Soon we will be having this functionality inside our app.

  3. Wouter, you could change the script so it will always use the same Custom Dimension. But then you can only execute 1 test at a time.

  4. Nicolas says:

    Hi André,
    Thanks for the script, can I use it with the asynchronous version of the tag ?


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>