Created
June 27, 2019 06:49
-
-
Save girvan/ec00a46bfd03674f9cbbed3ac2dd7a92 to your computer and use it in GitHub Desktop.
track cloudflare's edge location by using GA event
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
<script> | |
(function(){ | |
var request = new XMLHttpRequest(); | |
request.open('GET', '/cdn-cgi/trace', true); | |
request.onload = function() { | |
if (request.status != 200) return; | |
var match = request.responseText.match(/(colo|loc)=(\w+)/g), | |
colo = match[0].split('=')[1], loc = match[1].split('=')[1]; | |
ga('send', 'event', 'cloudflare', loc, colo); | |
}; | |
request.send(); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment