13.07.2015 Views

ebook on regular expressions for Google Analytics - LunaMetrics

ebook on regular expressions for Google Analytics - LunaMetrics

ebook on regular expressions for Google Analytics - LunaMetrics

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Regular Expressi<strong>on</strong>s match as much as possible.Most of this <str<strong>on</strong>g>ebook</str<strong>on</strong>g> will be about all the characters that make upthe Regular Expressi<strong>on</strong>s “toolset.” But first – you’ll be lost if youd<strong>on</strong>’t understand the c<strong>on</strong>cept of matching as much as possible.Sometimes you will be very surprised at how much it matches, justas I was when I was new at RegEx.Let’s start with an example: Our company often wants to see allthe keywords that include our company name (branded search)and, more often, we want to see all the keywords that d<strong>on</strong>’t includeour company name (unbranded search). Below are two of theRegular Expressi<strong>on</strong>s we use when we are including or excludingour company name:LunaMetricA friend wrote a questi<strong>on</strong> <strong>on</strong> a <strong>for</strong>um. He wantedto exclude all traffic that was coming from <strong>Google</strong> referringlinks, all around the world. He tried to create a reallyfancy RegEx that would include all countries, something likewww\.google\.(com|co\.(au|uk|il))/(docs|analytics|reader) etc.There are two interesting questi<strong>on</strong>s here, and you might feel somerighteous indignati<strong>on</strong> as you ask them. I know that I felt this waywhen I was first learning RegEx:1. Why would they match? Not a single <strong>on</strong>e of those phrasesincludes the entire name.2. How can those possibly be Regular Expressi<strong>on</strong>s? There are noRegEx characters!answErs1. They match because Regular Expressi<strong>on</strong>s in GA will match andmatch until they aren’t allowed to any more. That’s why Metricmatches the target string, <strong>LunaMetrics</strong> – if it matches any partof the word, it will match the whole word.2. And the characters? You d<strong>on</strong>’t need to have those charactersjust to have a Regular Expressi<strong>on</strong>, and having the charactersdoesn’t necessarily make it a RegEx. All you need to do is put theexpressi<strong>on</strong> into a field that is sensitive to RegEx. For example,when you write a <strong>Google</strong> <strong>Analytics</strong> goal, you get to choose “headmatch,” “exact match” or “Regular Expressi<strong>on</strong>.” As so<strong>on</strong> as youchoose “Regular Expressi<strong>on</strong>,” the field becomes sensitive toRegEx, and all the rules of RegEx apply. You often need to uselittle RegEx characters – but not always.I wrote back: “Why d<strong>on</strong>’t you just usethe word google as your RegEx?”5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!