Top Banner
PhantomJS and Analytics MeasureCamp London 19 Sep 2015
22

Using PhantomJS to QA your analytics implementation

Apr 16, 2017

Download

Technology

Alban Gérôme
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Using PhantomJS to QA your analytics implementation

PhantomJS and Analytics

MeasureCamp London

19 Sep 2015

Page 2: Using PhantomJS to QA your analytics implementation

Spiders and robots

Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript.

Page 3: Using PhantomJS to QA your analytics implementation

Spiders and robots

Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript.

Now they can:

Page 4: Using PhantomJS to QA your analytics implementation

Spiders and robots

Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript.

Now they can:• Access the DOM

Page 5: Using PhantomJS to QA your analytics implementation

Spiders and robots

Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript.

Now they can:• Access the DOM• Interpret Javascript

Page 6: Using PhantomJS to QA your analytics implementation

Spiders and robots

Until a few years ago spiders and bots could only read the HTML. They could not execute Javascript.

Now they can:• Access the DOM• Interpret Javascript• Fill login forms

Page 7: Using PhantomJS to QA your analytics implementation

Just like you and me

Page 8: Using PhantomJS to QA your analytics implementation

Headless testing

Increasingly testing requires writing code

• Test Driven Development• Extreme Programming

An automated test goes through the pages, executes the relevant tests and produces a bug report

Page 9: Using PhantomJS to QA your analytics implementation

Introducing

Page 10: Using PhantomJS to QA your analytics implementation

Introducing

A scriptable WebKit chrome-less browser

Page 11: Using PhantomJS to QA your analytics implementation

Simulate user behaviour and more

PhantomJS can respond to different stages of the page load

• Page initialised• Page load start• Page load finished• Page closed• Page not found

Page 12: Using PhantomJS to QA your analytics implementation

Simulate user behaviour and more

PhantomJS can respond to HTTP requests

• Resource requested• Resource received• Resource error• HTTP status text and codes

Page 13: Using PhantomJS to QA your analytics implementation

Simulate user behaviour and more

PhantomJS can respond to alerts and messages

• Javascript alert sent• Javascript console sent• Javascript prompt

Page 14: Using PhantomJS to QA your analytics implementation

Simulate user behaviour and more

PhantomJS can also

• Scan and manipulate the DOM• Catch Javascript errors in the page analysed

Page 15: Using PhantomJS to QA your analytics implementation

Simulate user behaviour and more

PhantomJS can also

• Scan and manipulate the DOM• Catch Javascript errors in the page analysed

• It can do screenshots

Page 16: Using PhantomJS to QA your analytics implementation

With PhantomJS you can write a spider to audit your analytics

implementation

Page 17: Using PhantomJS to QA your analytics implementation

Continuously

Page 18: Using PhantomJS to QA your analytics implementation

http://www.phantomjs.org

PhantomJS 2 available!

Page 19: Using PhantomJS to QA your analytics implementation

// Set the start URLvar page = require("webpage").create();var url = "http://www.adobe.com";//var url = "http://www.webtrends.com";var links;

page.viewPortSize={ width: 1280, height: 800};page.clipRect={ top:0, left:0, width:1280, height:800}phantom.onError=function(){};page.onError=function(){};page.onLoadStarted=function(){};page.onResourceReceived=function(responseData){};

Source code

Page 20: Using PhantomJS to QA your analytics implementation

page.onResourceRequested=function(requestData,networkRequest){ if(requestData.url.match(/\/b\/ss\//)) console.log(requestData.url);//Adobe Analytics if(requestData.url.match(/dcs\.gif/)) console.log(requestData.url);//Webtrends};page.onLoadFinished=function(status){ if(status=="success"){ var links = page.evaluate(function(){ var a=document.createElement("a"); return [].map.call(document.querySelectorAll("a[href]"), function(link){ a.href=link.getAttribute("href"); return a.href; }); }); console.log(links.join("\n")); }else{ //log error }; //check next page};

Source code

Page 21: Using PhantomJS to QA your analytics implementation

page.open(url,function (status){ if(status=="success"){ }else{ //log error }; phantom.exit();});

Source code

Page 22: Using PhantomJS to QA your analytics implementation

Alban Gérômeemail: [email protected]: @albangerome

All pictures from this deck taken by myself in Barcelona