diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-09-30 15:56:23 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-09-30 15:56:23 -0400 |
| commit | 2bdf7e7646cf1b61dad95a36e9d05278bc1fd745 (patch) | |
| tree | 2cc7457f3f59c2f8b0b4ddbf8fae5b6d00dadd80 | |
| parent | cc584860a6d5378826d007b5eeeeb6f1477713fd (diff) | |
tracking functions
| -rw-r--r-- | public/assets/javascripts/ui/reader/Tracker.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/public/assets/javascripts/ui/reader/Tracker.js b/public/assets/javascripts/ui/reader/Tracker.js new file mode 100644 index 0000000..7c31ce7 --- /dev/null +++ b/public/assets/javascripts/ui/reader/Tracker.js @@ -0,0 +1,99 @@ +var Tracker = Fiber.extend(function(base){ + + var exports = { + init: function(opt){ + this.wall_id = null + this.scenery_id = null + this.clicks = 0 + + this.wallTimer = new Timer () + this.roomTimer = new Timer () + this.sceneryTimer = new Timer () + + this.events = [] + }, + + trackPageview: function(opt){ + this.events.push([ "view", this.wall_id, duration ]) + }, + + // + // how long they spend in front of each wall + + trackChangeWall: function(opt){ + var duration = this.wallTimer.currentTime() + if (this.wall_id && duration > 5000) { + this.events.push([ "wall", this.wall_id, duration ]) + } + this.wall_id = opt.wall.id + this.wallTimer.start() + }, + + // + // how long the user spends on each item they click + + pickScenery: function(opt){ + this.sceneryTimer.start() + this.scenery_id = opt.scenery.id + }, + + trackScenery: function(){ + var duration = this.sceneryTimer.currentTime() + if (this.scenery_id && duration > 5000) { + this.events.push([ "scenery", this.scenery_id, duration ]) + } + this.scenery_id = null + this.sceneryTimer.reset() + }, + + // + // how long they spend in the room + + trackChangeRoom: function(opt){ + var duration = this.roomTimer.currentTime() + if (this.room_id && duration > 5000) { + this.events.push([ "room", this.room_id, duration ]) + } + this.room_id = opt.room.id + this.roomTimer.start() + }, + + // + // how many clicks per room + + trackClick: function(opt){ + this.clicks += 1 + }, + + save: function () { + }, + + } + + return exports +}) + + +var Timer = Fiber.extend(function(base){ + var exports = { + + init: function(opt){ + this.time = 0 + }, + + reset: function(){ + this.time = 0 + }, + + start: function(){ + this.time = Date.now() + }, + + currentTime: function(){ + return this.time ? Date.now() - this.time : 0 + }, + + } +}) + + |
