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).
If we are successful in filtering out IP with this method, we will look into how to insert cookies in other browsers!
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.
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/enableqaand that will set the localStorage key for you and redirect you.