(upbeat music)
- [Patrick] I've opened up my own Analytics account again,
and I'm going to look at 2016 when I got hit
by some spam bots.
If I scroll down; I can see the language section has
some language spam in it.
Just from this one page,
I can see that it's approximately 9% of my traffic;
that's definitely messing up data for landing pages,
exit pages, time on site, et cetera.
So let's create a filter that will exclude fake languages.
Now before we do any of this,
it's worth noting that you have to have
admin privileges to work with filters;
if you don't have them yet, you can still follow along.
Now, we could copy and paste each
of these spammy languages into a filter
that would eliminate these three languages.
But as soon as the spammer has a different message,
those new messages would get through.
We want to create a filter that can be a bit more flexible.
And for that, we're going to use regular expressions.
If you've never used regular expressions before,
think of them as advanced pattern matching;
they can be a little confusing to write,
but they're very powerful,
and I'll explain it each step of the way as I write them.
Now I'm going to use this online tool
to help me visualize the regular expressions.
At the top, I have valid languages,
and at the bottom, I have some of the spammy messages.
We have two options here:
We can write an inclusive filter
that matches all of these languages,
or we can write an exclusive filter
that matches all the ones on the bottom.
Regular expressions are hard to write,
and I find it easier to write regular expressions
that look for something out of place
rather than look for every single valid thing,
so let's do it that way.
When I look at the spam below,
I notice all of them include spaces.
Valid languages only include letters,
dashes, and occasionally numbers.
So I'm going to write a filter
that will exclude languages that have spaces,
and we can do that
by typing in \s+.
Now, in regular expressions,
that \s means any space character:
It could be a space, a tab, a return, et cetera;
and that "+" symbol means one or more.
So in this tool, notice that it's highlighting
the spaces in the spammy languages;
that means it's matching them.
We can now copy this regular expression
into our Google Analytics account,
so it's this "\s;"
I'm going to go back to Google Analytics.
Let's go to Admin and then Filters,
and I'm going to quickly switch to a new account
that doesn't yet have this filter.
(mouse clicks)
I'll go to ADMIN, Filters, and then ADD FILTER;
(mouse clicks)
Create a new Filter.
(mouse clicks)
I'll call this Exclude Spam Languages,
(mouse clicks)
and then click down to Custom, Select the fields,
(mouse clicks)
Language, and then the Filter Pattern,
which is that \s+.
Then click Verify filter
(mouse clicks)
because you want to make sure that
this isn't excluding any legitimate data.
Now you might see two errors at this point:
The first one, which is the one we're seeing right now,
is that this filter would not have changed your data.
Now, this means that you may not have hit
by language spam yet,
or it means that you've written your pattern incorrectly;
or it could mean that Google took
a random sample of your data,
and the language spam wasn't included in that sample.
Now, if you get this error, it's fine;
it's better to have a filter that's too weak
rather than exclude actual data.
You could also be ahead of the curve
and prevent language spam from ever hitting
your site in the first place.
The secondary you might see is language not set.
I actually got this on my site when I first set it up.
There were four visits that had the language,
parentheses, not space set and parentheses,
and there was a space in there.
But I decided that four visits was
less than 0.2% of my data,
so I thought it was fine to exclude that.
So this is good to go; I'll just click Save.
(mouse clicks)
And now we're excluding all spam languages.
(upbeat music)