Blocking Internal Traffic in Google Analytics with Local Storage

Mar 10, 2019

Fed up with filtering dynamic IPs for internal traffic? Try the Local Storage method here. We will be using combination of – Browser Local Storage, GTM  and GA Filters to filter out internal traffic.

Logic

We set a LS (local storage) key for internal traffic with GTM and value of this LS will be used as a custom dimension in GA. Inturn at the GA filter setup, we will exclude user traffic with this value.

Steps

Setup a Custom HTML tag with JS code to set a Local Storage key when a user lands on a unique URL like this: http://your-company.com/?block_internal_traffic=true

We are setting up a unique URL like above so its easy to set LS key for internal  users by just giving an URL to visit.

Here is the Custom HTML TAG to be used:

<script>
window.localStorage.setItem('internal_traffic', 'true');
</script>

Now create a TRIGGER  to fire this script at page views that contain the unique URL strings we mentioned in STEP 1.

 

  Create a Java Script variable with name internal_traffic_ls in GTM to fetch the LS value. 

 

   Create a user scope custom dimension in your Google Analytics account and add that to GTM GA Settings.

If you don’t know how to create custom dimension read this article.

   Create exclude filter at Google Analytics, to filter out all traffic that contains  internal_traffic value as true for your filtered traffic view.

 

  Publish and we are all done. Reach out to co-workers to click on custom URL you setup  http://your-company.com/?block_internal_traffic=true

 

[ NOTE: that first page load for this URL will be recorded in GA as LS value will be undefined; Successive pageviews will get filtered]