Created
April 1, 2019 02:39
-
-
Save joshuatz/885a976c3db22baa412804b8f311dc75 to your computer and use it in GitHub Desktop.
See https://joshuatz.com/posts/2019/excluding-employee-traffic-from-google-analytics-pixels-and-more
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Use this to set the list of IP addresses you DONT want your tags loading for --> | |
<?php $blockTagsFor = array('216.3.128.12','19.117.63.126','2001:0db8:85a3:0000:0000:8a2e:0370:7334'); ?> | |
<?php if (in_array($_SERVER['REMOTE_ADDR'],$blockTagsFor,false)==false): ?> | |
<!-- Put all the tags you want to conditionally load here. GA example below: --> | |
<!-- Global Site Tag (gtag.js) - Google Analytics --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', 'GA_MEASUREMENT_ID'); | |
</script> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment