Skip to content

Instantly share code, notes, and snippets.

@girvan
Created June 27, 2019 06:49
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save girvan/ec00a46bfd03674f9cbbed3ac2dd7a92 to your computer and use it in GitHub Desktop.
track cloudflare's edge location by using GA event
<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