Blocking Internal Traffic in Google Analytics with Local Storage

Google Analytics 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.


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.


Setup a Custom HTML tag with JS code to set a Local Storage key when a user lands on a unique URL like this:

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:

window.localStorage.setItem('internal_traffic', 'true');

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


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