Skip to content

Instantly share code, notes, and snippets.

@duncanmorris
Last active August 29, 2015 14:18
Show Gist options
  • Save duncanmorris/79230048faf054a486bd to your computer and use it in GitHub Desktop.
Save duncanmorris/79230048faf054a486bd to your computer and use it in GitHub Desktop.
Using PhantomJS to monitor Google Analytics - example 3
var page = require('webpage').create();
var url = 'https://www.distilled.net/';
console.log('Loading: ' + url);
var resources_to_log = [
new RegExp('^http(s)?://(www|ssl)\.google-analytics\.com.*'),
new RegExp('^http(s)?://stats\.g\.doubleclick\.net.*')
];
page.onResourceRequested = function (res) {
var length = resources_to_log.length;
while(length--) {
if (resources_to_log[length].test(res.url)){
console.log('Requesting: ' + res.url);
}
}
};
page.open(url, function (status) {
//Page is loaded!
if (url != page.url){
console.log('Redirected: ' + page.url)
}
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment