Skip to content

Instantly share code, notes, and snippets.

@shermozle
Last active July 16, 2018 03:47
Show Gist options
  • Save shermozle/7365434 to your computer and use it in GitHub Desktop.
Save shermozle/7365434 to your computer and use it in GitHub Desktop.
Prototype showing how to use Selenium Webdriver to test web analytics. It's very rough. You need a local install of Selenium. You can download the standalone server jar which has no dependencies beyond Java: https://code.google.com/p/selenium/downloads/list
// PROXY
var url = require('url'),
http = require('http'),
colors = require('colors');
http.createServer().listen(9000).on('request', function(request, response) {
try {
var options = url.parse(request.url);
options.headers = request.headers;
options.method = request.method;
options.agent = false;
var connector = http.request(options, function(serverResponse) {
response.writeHeader(serverResponse.statusCode, serverResponse.headers);
serverResponse.pipe(response, {end:true});
});
request.pipe(connector, {end:true});
if (isThisInteresting(request)) {
console.log((isThisInteresting(request).beaconName).green.bold + ': ' + decodeURIComponent(isThisInteresting(request).url));
}
} catch (error) {
console.log("ERR:" + error);
}
});
var webdriver = require('selenium-webdriver');
var proxy = require('selenium-webdriver/proxy');
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.firefox())
.setProxy(proxy.manual({
http: 'localhost:9000'
}))
.build();
driver.get('http://media.telstra.com.au/');
driver.quit();
var isThisInteresting = function (request) {
var parsedRequest = url.parse(request.url);
if (parsedRequest.pathname.match('/b/ss')) {
return({
beaconName: 'Omniture',
url: request.url
});
} else
if (parsedRequest.host.match('adobetag.com')) {
return({
beaconName: 'Adobe Tag Container',
url: request.url
});
} else
if (parsedRequest.host.match('secure-au.imrworldwide.com')) {
return({
beaconName: 'Nielsen',
url: request.url
});
} else
if (parsedRequest.host.match('google-analytics.com')) {
return({
beaconName: 'GA',
url: request.url
});
}
else {
return(false);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment