Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2019 06:49
What would you like to do?
track cloudflare's edge location by using GA event
var request = new XMLHttpRequest();'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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment