ref: master
plugins/analytics/public/javascripts/analytics.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
analytics = { t: function (key, options) { return I18n.t(key, $.extend(options, {scope: 'analytics_plugin'})) }, requestId: '', timeOnPage: { updateInterval: 0, baseUrl: '', report: function() { $.ajax(analytics.timeOnPage.baseUrl+'/report', { type: 'POST', data: {id: analytics.requestId}, success: function(data) { analytics.timeOnPage.poll() }, }) }, poll: function() { if (analytics.timeOnPage.updateInterval) setTimeout(analytics.timeOnPage.report, analytics.timeOnPage.updateInterval) }, }, init: function() { analytics.timeOnPage.poll() }, pageLoad: function() { $.ajax(analytics.timeOnPage.baseUrl+'/page_load', { type: 'POST', data: {id: analytics.requestId, title: document.title, time: Math.floor(Date.now()/1000)}, success: function(data) { }, }); } }; $(document).ready(analytics.pageLoad) |