Analytics Log - Adil Khan

View Original

Use Regex Match/Case Function To Create Custom Field in Google Data Studio

In Google Data Studio, you can create new fields that appends on to your existing data sources. What's more important is that the values in these fields can be kept conditional using Regex Match.

This is very helpful in assigning categories to campaigns or even ad sets from Facebook ads.

Regex Match can be used in combination with the CASE function to create IF conditions.

CASE > When X > Then Y > ELSE

When Z > Then A > ELSE

Other

Let's use Google Merchandise store data as example:

Access this property on GA 

https://analytics.google.com/analytics/web/demoAccount

Sorting primary dimension by Campaign and Secondary by Ad content, you see a few examples here:

Once inside Google Data Studio, Go to Resources > Manage Data Sources > Go to GA as your source > Add Field

Here's what the case function does. If the Ad content field contains 'accessories', it will classify all such ad content as 'Accessories'.

Once you have setup the field to cover possible combinations, you can then chart this as a bar to see how much of the field is classified and what's remaining under 'Other' - which might require more classification. 

In the above case, 'Others' dominates while Apparel, Paraphernalia and Swag have some traffic to them. The more conditions that are created, the fewer 'Others' , we'll have.