Published on

Blocking bottraffic or trafficbot url requests from jacking up your Google Analytics

Authors

I’m going to prefix this with the following: I am not a RegEx expert, I just screwed around for a bit on regexr.com until something looked right.

This is what I came up with regexr.com/5lp2n

(bot.*traffic|traffic.*bot)[.a-z]+

My thought is, any request that starts with “bot” and ends with “traffic” (or visa versa) AND has a period with something after it. I don’t have a single URL on the site that should match those patterns, so I think this is solid, but any Regex Gurus could weigh in if they want @stevemcniven

Here’s the web.config IIS Rewrite rule, it’ll abort the request so your error pages won’t even render (with the GA scripts on them)

        <rule name="Block bottraffic routes" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="(bot.*traffic|traffic.*bot)[.a-z]+" />
          <conditions>
             <add input="{URL}" pattern="((?=bot-?)|(?=traffic))[.a-z]+" />
          </conditions>
          <action type="AbortRequest" />
        </rule>

Boost your online presence.

Let us create the perfect digital experience for your company.

Contact us now