Regular expressions, or regex for short, is a string of text used to describe a search pattern. In simple terms, it is find and replace on steroids. In this specific example, we are not replacing anything. There are a ton of applications ranging from parsing data on a web server to manipulating high volumes of text files to what makes SEO permalinks possible on Linux servers, which is done using Apache’s mod_rewrite by editing the .htaccess file. In Google Analytics, you can create Custom Reports using regular expressions to build customized reporting views that allow you to get to the data that you want in the format that you want it presented. I will show you how.
To keep things simple, I will use the example that I want to build a Custom Report to see the traffic coming from Facebook. Traffic from Facebook generally comes in from facebook.com, m.facebook.com, l.facebook.com and lm.facebook.com. The l.* and lm.* are part of their Link Shim release in 2008, which helps protect Facebook users from malicious URLs.
Custom Reports Basics
To create a Custom Report, click on the Customization tab on the top and then click the “New Custom Report” button.
I gave mine the title of “Facebook Traffic” and left the report Name the default. Under Metric Groups, I added “Users”, “New Users”, “Sessions”, “% New Sessions”, “Pageviews” and “Avg. Session Duration”. Under Dimension Drilldowns, I added “Source / Medium”, “Full Referrer” and “Landing Page”. You can change the metrics and dimensions to the ones that you want to see but for this purpose, you can use the ones that I have used to make it easier on your end. If you click on Save, you will see all traffic—I will show you below several methods to filter out just traffic from Facebook.
Go back to Customization, and under the Actions dropdown, click on Edit. Under “Filters – optional”, click on “add filter” and select Source (under Acquisitions).
Continue reading “Regex or Regular Expressions in Google Analytics Custom Reports”