From 1774e390ecc114033a23072f7a8b20e8ae00c3d2 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 2 Jan 2013 16:58:22 +0100 Subject: [PATCH] [IMP] Refactoring web_analytics, step 1 bzr revid: vta@openerp.com-20130102155822-6t78t8tfbnhtfmg1 --- .../static/src/js/web_analytics.js | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 01c7cc2a7a3..1f1941b768b 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -20,37 +20,42 @@ openerp.web_analytics = function(instance) { s.parentNode.insertBefore(ga,s); })(); + instance.web_analytics.Tracker = instance.web.Class.extend({ + init: function() { + // initialize tracker + _gaq.push(['_setAccount', 'UA-35793871-1']); + // _gaq.push(['_setAccount', 'UA-7333765-1']); + //_gaq.push(['_setAccount', 'UA-36797757-1']); // Debug code + _gaq.push(['_setDomainName', 'none']); // Change for the real domain + this.initialize_custom(); + instance.client.on('state_pushed', this, on_state_pushed); + this.include_tracker(); + }, + initialize_custom: function() {}, + on_state_pushed: function() {}, + include_tracker: function() {}, + }); var init_tracker = function() { // initialize tracker - _gaq.push(['_setAccount', 'UA-7333765-1']); + _gaq.push(['_setAccount', 'UA-35793871-1']); + // _gaq.push(['_setAccount', 'UA-7333765-1']); //_gaq.push(['_setAccount', 'UA-36797757-1']); // Debug code _gaq.push(['_setDomainName', 'none']); // Change for the real domain // Track user types - if (instance.session.uid !== 1) { - if ((/\.demo.openerp.com/).test(instance.session.server)) { - _gaq.push(['_setCustomVar', 1, 'User Type', 'Demo User', 1]); - } else { - _gaq.push(['_setCustomVar', 1, 'User Type', 'Normal User', 1]); - } - } else { + if (instance.session.uid === 1) { _gaq.push(['_setCustomVar', 1, 'User Type', 'Admin User', 1]); + } else { + _gaq.push(['_setCustomVar', 1, 'User Type', 'Normal User', 1]); } - - // Track object usage - _gaq.push(['_setCustomVar', 2, 'Object', 'no_model', 3]); - // Tack view usage - _gaq.push(['_setCustomVar', 3, 'View Type', 'default', 3]); - - _gaq.push(['_trackPageview']); }; var on_state_pushed = function(state) { // Track only pages corresponding to a 'normal' view of OpenERP, views // related to client actions are tracked by the action manager - if (state.model && state.view_type) { - // Track object usage + if (state.model && state.view_type) { + // Track object usage _gaq.push(['_setCustomVar', 2, 'Object', state.model, 3]); // Tack view usage _gaq.push(['_setCustomVar', 3, 'View Type', state.view_type, 3]); @@ -82,6 +87,8 @@ openerp.web_analytics = function(instance) { // Track client actions instance.web.ActionManager.include({ ir_actions_client: function (action, options) { + console.log(action); + console.log(options); var url = instance.web_analytics.generateUrl({'action': action.tag}); _gaq.push(['_trackPageview', url]); return this._super.apply(this, arguments); @@ -95,7 +102,7 @@ openerp.web_analytics = function(instance) { var category = this.model || dataset.model || ''; var action; if (action_data.name && _.isNaN(action_data.name-0)) { - action = action_data.name; + action = action_data.name; } else { action = action_data.string || action_data.special || ''; }