Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created July 27, 2010 07:03
Show Gist options
  • Save hokaccha/491867 to your computer and use it in GitHub Desktop.
Save hokaccha/491867 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name detect_ga_tracking
// @namespace http://webtech-walker.com/
// @description Auto detect for Google Analytics _setCustomVar traking.
// @include http://*
// @include https://*
// ==/UserScript==
(function() {
var messages = [];
var scripts = document.getElementsByTagName('script');
Array.prototype.forEach.call(scripts, function(script) {
var source = script.innerHTML.replace(/[\n\r]/g,'');
source.replace(/_setCustomVar\(([^\)]+)\)/g, function(m) {
var values = arguments[1].split(/,/);
var slot = values[0];
var key = values[1].replace(/['"]/g, '');
var val = values[2].replace(/['"]/g, '');
var scope = values[3] == 1 ? 'visitor' :
values[3] == 2 ? 'session' :
values[3] == 3 ? 'page'
: 'unkonwn';
messages.push("traking["+slot+"] "+ key + ' => ' + val + ' (' + scope + ')');
});
});
if (messages.length) {
var wrap = document.createElement('div');
wrap.setAttribute('style', [
'position: fixed',
'top: 0',
'right: 0',
'background: rgba(0, 0, 0, 0.7)',
'z-index: 999999',
'color: #FFF',
'text-align: left',
'padding: 10px 30px 10px 10px',
].join(';'));
wrap.innerHTML = '<span>this site is traking</span>';
var close = document.createElement('span');
close.setAttribute('style', [
'background: #C00',
'display: inline-block',
'padding: 0 5px',
'margin: 0 0 0 3px',
'cursor: pointer',
'position: absolute',
'top: 5px',
'right: 5px',
].join(';'));
close.innerHTML = 'x';
close.addEventListener('click', function() {
wrap.style.display = 'none';
}, false);
wrap.appendChild(close);
var message = document.createElement('div');
message.innerHTML = messages.join('<br>');
message.style.display = 'none';
wrap.appendChild(message);
wrap.addEventListener('mouseover', function() {
message.style.display = 'block';
}, false);
wrap.addEventListener('mouseout', function() {
message.style.display = 'none';
}, false);
document.body.appendChild(wrap);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment