Skip to content

Instantly share code, notes, and snippets.

@duncanmorris
Created April 10, 2015 11:42
Show Gist options
  • Save duncanmorris/69ab9a71b48a2c2897f2 to your computer and use it in GitHub Desktop.
Save duncanmorris/69ab9a71b48a2c2897f2 to your computer and use it in GitHub Desktop.
Using PhantomJS to monitor Google Analytics - example 2
var page = require('webpage').create();
var url = 'http://crawlbin.com/response_301/';
console.log('Loading: ' + url);
page.onResourceRequested = function (res) {
console.log('Requesting: ' + res.url);
};
page.open(url, function (status) {
//Page is loaded!
if (url != page.url){
console.log('Redirected: ' + page.url)
}
phantom.exit();
});
@duncanmorris
Copy link
Author

Usage: phantomjs example2.js

Output:
Loading: http://crawlbin.com/response_301/
Requesting: http://crawlbin.com/response_301/
Requesting: http://crawlbin.com/
Requesting: https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css
Requesting: http://crawlbin.com/static/crawlbin.css
Requesting: http://crawlbin.com/static/favicon.ico
Redirected: http://crawlbin.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment