I wanted to be able to see how many people were scrolling down my sales letters, and presumably reading the text, so I came up with a cool use of javascript.
I found a piece of javascript code that tracks the mouse movement. When it gets above a certain value on the y-axis, I submit a page in a hidden frame, and insert a database record to log that this person had scrolled down the page.
Here's the code for the hidden frame, inserted just above the closing </body> tag.
<iframe name="LogFrame" src="" width="0" height= "0"></iframe>
Here's the javascript code that tracks the mouse:
// THIS PIECE OF CODE TRACKS THE MOUSE, AND FIRES CODE TO DETERMINE WHETHER THE USER HAS SCROLLED DOWN THE PAGE OR NOT
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
//Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0
var LogIt = 0
// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
if (LogIt == 0 && tempY > 1500)
{ //this is where the frame is submitted with the page that will insert the record into the DB
window.LogFrame.location.href = "ebook/LogScrollDown.aspx";
LogIt = 1
}
return true
}
This method of scroll-tracking is far from perfect. If the person is using a non-supported browser, or if cookies are turned off, it won't work. If the person uses only their down arrows to scroll and never move the mouse, it won't work either. But, it will work for around 95% of people, and that won't change from sales letter mod-to-mod, so it's a good test.
This technique has been very informative for me so far...
--
>> There are only 10 kinds of people in the world - those that know binary and those that don't.
Labels: online marketing, programming