Skip to content

Instantly share code, notes, and snippets.

@debrouwere
Created May 29, 2013 16:26
Show Gist options
  • Save debrouwere/5671631 to your computer and use it in GitHub Desktop.
Save debrouwere/5671631 to your computer and use it in GitHub Desktop.
page = require('webpage').create()
page.onConsoleMessage = (msg) ->
console.log 'CONSOLE:' + msg
page.onResourceRequested = (params, request) ->
isJavaScript = params['url'].slice(-3) is '.js'
isJQuery = (params['url'].indexOf 'jquery') isnt -1
if isJavaScript and not isJQuery
request.abort()
console.log 'aborted req for', params['url']
bin = ([top, left, url]) ->
top = Math.floor top / 100
left = Math.floor left / 100
[top, left, url]
page.viewportSize = {width: 1000, height: 1000}
page.open 'http://www.guardian.co.uk', ->
console.log 'opened page'
links = page.evaluate ->
$ = window.jQuery
$.makeArray $('div#inner-wrapper a').map ->
href = $(this).attr 'href'
{top, left} = $(this).offset()
[[top, left, href]]
###
You couldn't really use this to create heatmaps because links can be
(and often are) present in multiple parts of the page, and so it's
impossible to know what links are getting the clicks that are resulting
in pageviews without actual click tracking.
You might be able to get by if you exclude all links that are present
more than once on the page. (Though this is tricky for pixies.)
Regardless, we can definitely use this to try and find correlations
between promotions and pageviews. We'd simply
###
binnedLinks = links.map bin
positions = binnedLinks.map (link) -> link[0]
height = Math.max positions...
console.log "canvas: 10 x #{height} in blocks of 100x100 pixels"
console.log JSON.stringify binnedLinks
phantom.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment