How to Remove Test Users from Analytics

ListenLayer allows you to formulate and write rules that customize your data layer activity. For example, you can write rules to identify insiders and test users that you do not want inside your website analytics data without any programming. This use case shows you how to quickly build and execute a strategy to do this using ListenLayer.

Filter Out and Remove Test Users from Analytics Using the Data Layer

If you have a large marketing or development team constantly visiting and testing your website, you need to formulate a strategy to remove them from your website analytics. Unfortunately, the traditional method of filtering out IP addresses doesn’t work well as IPs often change, and more of your team is working remotely. ListenLayer allows you to structure a strategy to identify and filter our test users before they even hit your website analytics or marketing data platforms. Then, execute and maintain the framework with no programming knowledge required!

Steps & Code Examples

Step 1: Add Your Domain Name Inside ListenLayer
Step 1: Add Your Domain Name Inside ListenLayer

Navigate to the Website screen of your ListenLayer account and add your website domain name. Then copy the Website Script to place on your website using Google Tag Manager.

Step 2: Deploy Your ListenLayer Website Script
Step 2: Deploy Your ListenLayer Website Script

Create a Custom HTML Tag inside of Google Tag Manager that fires on All Pages. Place the tracking script from your ListenLayer account. A sample is shown here, but you must use the code from your account, not this example code!

<script type="text/javascript">(function(c,a,d,b,e) {c[b] = c[b] || [];
c=a.getElementsByTagName(d)[0];a=a.createElement(d);b="dataLayer"!= b ?"&l="+b:"";a.async = !0;
a.src = "https://assets.listenlayer.com/datalayer.min.js?id="+e+b;
c.parentNode.insertBefore(a,c)})(window,document,"script","dataLayer",
"00000000-0000-0000-0000-0000000000000");</script>
Step 3: Enable Custom Values & Browser Storage
Step 3: Enable Custom Values & Browser Storage

Enable the URL Parameters Listener and then navigate to the Features screen. Enable the Custom Data Layer Values Feature and the Browser Storage Feature.

Step 4: Create a Custom Data Layer Variable
Step 4: Create a Custom Data Layer Variable

Under the Global Settings, open the Custom Data Layer Variables screen and define a variable that you will hold a value inside of to identify test users in the data layer.

Step 5: Create Your Browser Storage Variable
Step 5: Create Your Browser Storage Variable

Navigate to Browser Storage under Global Settings. Create a record for the Browser Storage element you want to store your test users’ information. In our example, we use a Session Storage Key. In addition, you can choose to set a First Party Cookie or use Local Storage, depending on your situation.

You will use Browser Storage to save a value that identifies a user as a test. Then, you can get this value inside of GTM to use it in your variables, triggers, and tags.

Step 6: Create A Rule For Your Custom Data Layer Variable
Step 6: Create A Rule For Your Custom Data Layer Variable

Create a new rule under Custom Values inside the URL Parameters Listener. In our example, we have chosen to use a Simple Rule.

Define the Condition you want to meet to identify a test user. In this case, we are simply looking for a URL parameter “test” to contain 1.

Step 7: Define Your Data Layer Variable Value
Step 7: Define Your Data Layer Variable Value

Now, define the value you want to use to identify test users. This will be stored inside of the data layer variable that we created a few steps before this.

You could identify the URL parameter directly in GTM by setting it as a variable; however, this limits our flexibility significantly. For example, what if we want to use 2 different methods to identify test users, this being only one of them. In that situation, we would use multiple rules to define the value of this variable, adding flexibility and power to our configuration.

Step 8: Create Your Browser Storage Rule
Step 8: Create Your Browser Storage Rule

Navigate to Browser Storage inside the URL Parameters Listener and create a rule. Next, select the correct rule type based on whether you are using a Cookie, Session Storage, or Local Storage.

Then, define a condition similar to what you used in the Custom Data Layer Value.

Step 9: Define Your Browser Storage Value
Step 9: Define Your Browser Storage Value

Next, create the value you will push into the Browser Storage when the condition is met.

When we identify a test user, we surface the information in the Data Layer and Browser Storage.  Depending on your situation, you will likely not need both of these, but we have configured both in this Use Case as a point of illustration.

Make sure to publish your ListenLayer changes so you can test them!

Step 10: Test Your Data Layer Variable
Step 10: Test Your Data Layer Variable

After publishing ListenLayer, test your Data Layer Variable using the URL parameter “test=1,” and you should see your rule at work!

Step 11: Test Your Browser Storage
Step 11: Test Your Browser Storage

Next, test your browser storage by navigating to the Application in your browser inspector.  You should find your storage key or cookie name under the appropriate Browser Storage medium.

Step 12: Capture Your Data Layer Variable Inside GTM
Step 12: Capture Your Data Layer Variable Inside GTM

Now that your data layer has information about test users, we need to make this available inside of Google Tag Manager as a variable.  This will allow us to use the information to filter test users out of our conversion and analytics tag activity.

Create a new variable inside of Google Tag Manager and select Data Layer Variable as the type. Then place the path to the variable in the Data Layer Variable Name. Name and save the variable.

Step 13: Capture Your Browser Storage Inside GTM
Step 13: Capture Your Browser Storage Inside GTM

You can also capture Cookie values or Local Storage and Session Storage values inside of Google Tag Manager.

For Cookies, use the 1st Party Cookie variable type in GTM, and enter the name of your cookie (see screenshot).

For Local Storage or Session Storage, write a simple script to get your values. You can read more about this example, taken from Simo Ahava’s excellent tutorial here.

if (window['Storage']) {
  var localSession = localStorage.getItem('session');
  var sessionSession = sessionStorage.getItem('session');
}