Google Analytics: custom dimensions

Published by Chao Yu on

Google Analytics allow developers to collect custom data (parameters) and create custom dimensions to make use custom data. In this blog, i will try to go through the steps of creating custom dimensions and make use of the custom dimensions.

I will be using previous blog mentioned Search Event, in the search event I collected Search_item / Value. I will use the value and create a report and check the most searched strings.

Use Existing Dimensions

before we go to create our own dimensions, we will go check out the existing Dimensions and what we can do with it on a high level. I will take Engagement=> Pages And Screens section as an example.

To start playing around with dimensions, we need to click on

This will bring a panel on the right, where we can add and remove dimensions. Say I would like to know the page views in the last 30 days segmented by City names. How would we do it.

Here is an interesting result, we can see now which city is more interested in which page. Based on your need, i believe you can make it much more interesting. Looks like our admin lives in the city called Vught, as that was the only traffic to the admin page.

Creating Customs Dimensions

Notice the Dimension name, we will need it on our apex page. Event Parameter is used to passing data to this custom dimension.

Let us save the above settings and go to our APEX page. On APEX page we need to do the following changes.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YOUROWNID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-YOUROWNID',{
      'custom_map': {'dimension2':  'search_term'
                    ,'dimension3':  'apex_user'
                    ,'dimension4': 'terminal'
                    ,'dimension5': 'tank_id'
                    ,'dimension6': 'action_type'  }
  });
</script>

See more about this code from google link.

Of course, when we trigger search event, we need to mention search_term and pass value to it. like this:

let val = apex.item( "P2_TANK_ID" ).getValue();
gtag("event", "search", {
  search_term: val,
  apex_user: '&APP_USER.'
});

Use Custom Dimensions

Let us make sure of the dimensions we created and make some tables. (please note that when you create a new dimension, you would only be able to use it after 24 hours.)

Let us open this very simple report and find out what it is all about.

there are lots of information on this page, to come up with a simple report.

To reach the goal of finding the most searched string, we set Technique as Free Form, visualization as a flat table. Event Name and search_term as rows, I left columns empty and count events as Values.

Before we can use search_term , we need to click on the

plus sign next to DIMENSIONS and find search_term and add it.

To see search event only, i also made a filter for this report, which is here.

Recap:

we have seen how to create custom dimension and make use of it in google analytics explorations.

Categories: APEX