DataStudio how to create a Google Analytics Custom Channel Grouping

Google DataStudio is an excellent addition to the Google Suite tool arsenal which deals with the reporting / exploration part.  A much more complex system than what we are used to with Google Analytics Dashboards yet still really easy to use! The product is still in Beta but looks very promising.

For more information about DataStudio here are some useful links to get you up and running:

  1. Product overview – http://online-behavior.com/analytics/google-data-studio
  2. Help center – https://support.google.com/360suite/datastudio?hl=en#topic=6267740
  3. Creating a report (case) – http://datarunsdeep.com.au/blog/visualising-m-night-shyamalan-google-data-studio

Back to the issue at hand:

How to create a Google Analytics Custom channel grouping inside DataStudio

Most of avid Google Analytics users are really keen on redefining the default channel grouping or adding custom channel grouping to have a better understanding of how ‘channels’ perform on a high / low detail level. Unfortunately GA Reporting API / Core API still does not have such a dimension exposed / available so in our reporting and analysis effort we have to resort to recreating the conditions with filtering. Same process has to be applied when reporting in DataStudio. So, whenever you want to widen the Default channel grouping by creating a Custom Channel grouping inside GA and want this to be accessible via DataStudio you need to do this:

  1. Add a data source – Google Analytics – procedure described in links above
  2. Add a custom field to the data source – which I will describe next

To begin with here is the official support for calculated fields – https://support.google.com/360suite/datastudio/answer/6299685?hl=en.

Step 1
Create the field
04 datastudio create a calculated field

 

Step 2
The formula

07 datastudio building blocks

 

This is the tricky part. You need to mimic the order and definitions as you would in the GA Admin interface using prebuild DataStudio functions (https://support.google.com/360suite/datastudio/table/6379764).  The basis will be the function CASE (https://support.google.com/360suite/datastudio/answer/7020724) which uses this simple syntax:

CASE
WHEN X1 THEN Y1
WHEN X2 THEN Y2
WHEN Xn THEN Yn
ELSE Y
END

This will translate to:

CASE
WHEN our source or campaign matches ‘some string’ THEN the dimension output will be ‘desired channel grouping dimension value’
ELSE if we missed to group some traffic inside a group it will output ‘You missed this’
END

The best way to proceed is to open Notepad or similar text editor and do it there as DataStudio formula entry has auto fill feature and you can only write in a single line so it will eventually strat to be extremely hard to track what is defined or what needs to be corrected.

Examples:
‘Referral’ channel group
WHEN Default Channel Grouping = “Referral” THEN “Referral”

‘Paid listings’ channel group
WHEN
REGEXP_MATCH(Medium, “.*(listing|xyz).*”) AND REGEXP_MATCH(Source, “.*(tripadvisor|abc).*”) THEN “Paid Listings”
In this case we are using REGEXP_MATCH function where we evaluate Medium AND Source for phrases we use when creating Custom Channel Grouping in Google Analytics.  We can also use other logical operators to create a more complex condition. Please note that REGEX we are used to in Google Analytics does not behave the same as in DataStudio (after some tinkering guys from http://datarunsdeep.com.au/ confirmed it – thanks!)  – more on DS regex – https://github.com/google/re2/wiki/Syntax.

Your end result should have the following structure:

CASE 
WHEN Default Channel Grouping = “Referral” THEN “Referral”
WHEN Default Channel Grouping = “Direct”  THEN “Direct”
WHEN Medium = “cpc” AND REGEXP_MATCH(Campaign, “.*(brand|bcmp).*”) THEN “Paid Brand Campaign”
WHEN REGEXP_MATCH(Medium, “.*(listing|xyz).*”) AND REGEXP_MATCH(Source, “.*(tripadvisor|abc).*”) THEN “Paid Listings”
… add more definitions as you see fit
ELSE “Other”
END

Copy your entire code and paste it inside the formula field:

05 datastudio fill in the formula

Step 3
Update the data source

07 update data source

 

 

Step 4
Change the Dimension in your widget from Default Channel grouping to your Custom Channel grouping one.

Click on the current dimensions.
09 choose the calculated field

Choose the newly created one.

10 My custom channel grouping

A small hint – add a secondary dimensions – Source / Medium just to check if all the traffic is indeed in predefined and expected channel group.

11 make sure it is applied

Step 5
Refresh the data

12 refresh the data

 

Final notes:

  • Any change you do inside GA should be redone inside DataStudio Custom field (at least till GA surfaces some kind of a custom channel grouping dimension via API)
  • The same approach can be used for any kind of filtering / segmentation and once you get used to the syntax it is pretty useful and offers nice customization options

 

One thought on “DataStudio how to create a Google Analytics Custom Channel Grouping”

  1. Great article – saved me a lot of time earlier picking through this.

    Something I would add is that for the REGEXP_MATCH(*) you can perform a negative by adding NOT in front of it. As negatives aren’t easily supported in Regex, and I’m not sure at all in GA. The Data Studio documentation is also pretty limited.

    e.g. In my situation, an email channel grouping was being incorrectly logged in Direct as there was only an “/email-url/” string in the landing page that was identifying it (no UTM params). I could have moved Email Channel up the priority list, but that would have caused some other undesired effects. Therefore my “Direct” Channel Grouping looked like this:

    WHEN Default Channel Grouping = ‘Direct’ AND NOT REGEXP_MATCH(Landing Page, ‘.*(email-url).*’) THEN ‘Direct’

Leave a Reply

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