Fightpandemics: GTM - Dynamic IP filtering for internal traffic

Created on 16 Oct 2020  路  2Comments  路  Source: FightPandemics/FightPandemics

Edit: Please read @ddveloper's comment below! We will implement the localStorage option for IP filtering. However, we will need to find a solution that will work for mobile devices.


To create a "developer cookie" that we can use to filter out data generated by internal traffic (QA testing on prod env).

  1. Replace/edit existing GA code snippet to check for the "developer cookie" in the scripts before sending any data to GA
  2. For each QA using Chrome, install the extension, set the developer cookie value
  3. Test

If we are successful in filtering out IP with this method, we will look into how to insert cookies in other browsers!

BI Metrics P1 馃敟

Most helpful comment

@doheekim93 @ddveloper
I think the localStorage is the best way to do it, but on mobile devices you can't set a new localStorage value, so I was thinking maybe add a hidden route on front-end that will set the QA key to true.
So like you can go to fightpandemics.com/enableqa and that will set the localStorage key for you and redirect you.

All 2 comments

as @joshmorel suggested, the localStorage can be manually configured and the GA code can be updated based on that, this can be applied to a wider range of browsers since they all support setting localStorage value.

I tested the below code with my GA account, after manually configuring my Chrome and Microsoft Edge, with a pair key-value qa_dev: true, it works as expected

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-xxxxx"></script>
    <script>
        if (localStorage.getItem("qa_dev") === "true") {
            alert('welcome! QA team');
        } else {
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', 'G-xxxxx');
        }
    </script>

@doheekim93 @ddveloper
I think the localStorage is the best way to do it, but on mobile devices you can't set a new localStorage value, so I was thinking maybe add a hidden route on front-end that will set the QA key to true.
So like you can go to fightpandemics.com/enableqa and that will set the localStorage key for you and redirect you.

Was this page helpful?
0 / 5 - 0 ratings