From 1774e390ecc114033a23072f7a8b20e8ae00c3d2 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 2 Jan 2013 16:58:22 +0100 Subject: [IMP] Refactoring web_analytics, step 1 bzr revid: vta@openerp.com-20130102155822-6t78t8tfbnhtfmg1 --- .../web_analytics/static/src/js/web_analytics.js | 43 +++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'addons/web_analytics/static/src/js') 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 || ''; } -- cgit v1.2.3 From a1d18ccb7a338ce01cfe45108a5443aaee96ee6c Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 3 Jan 2013 10:18:21 +0100 Subject: [IMP] Refactoring web_analytics, step 2 bzr revid: vta@openerp.com-20130103091821-mo57o9oybzpyrzqm --- .../web_analytics/static/src/js/web_analytics.js | 257 +++++++++++---------- 1 file changed, 133 insertions(+), 124 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 1f1941b768b..a25c2169528 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -3,12 +3,13 @@ var _gaq = _gaq || []; // asynchronous stack used by google analytics openerp.web_analytics = function(instance) { - /** The Google Analytics Module inserts the Google Analytics JS Snippet - * at the top of the page, and sends to google an url each time the - * openerp url is changed. - * The pushes of the urls is made by triggering the 'state_pushed' event in the - * web_client.do_push_state() method which is responsible of changing the openerp current url - */ + /* + * The Google Analytics Module inserts the Google Analytics JS Snippet + * at the top of the page, and sends to google an url each time the + * openerp url is changed. + * The pushes of the urls is made by triggering the 'state_pushed' event in the + * web_client.do_push_state() method which is responsible of changing the openerp current url + */ // Google Analytics Code snippet (function() { @@ -21,142 +22,150 @@ openerp.web_analytics = function(instance) { })(); instance.web_analytics.Tracker = instance.web.Class.extend({ + /* + * This method initializes the tracker + */ 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); + instance.client.on('state_pushed', this, 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-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) { - _gaq.push(['_setCustomVar', 1, 'User Type', 'Admin User', 1]); - } else { - _gaq.push(['_setCustomVar', 1, 'User Type', 'Normal User', 1]); - } - }; - - 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 - _gaq.push(['_setCustomVar', 2, 'Object', state.model, 3]); - // Tack view usage - _gaq.push(['_setCustomVar', 3, 'View Type', state.view_type, 3]); - // Track the page - var url = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type}); - _gaq.push(['_trackPageview', url]); - } - }; - - var include_tracker = function() { - // include the tracker into views and managers - - // Track the events related with the creation and the modification of records - instance.web.FormView = instance.web.FormView.extend({ - init: function(parent, dataset, view_id, options) { - this._super.apply(this, arguments); - var self = this; - this.on('record_created', self, function(r) { - var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'}); - _gaq.push(['_trackEvent', this.model, 'on_button_create_save', url]); - }); - this.on('record_saved', self, function(r) { - var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'}); - _gaq.push(['_trackEvent', this.model, 'on_button_edit_save', url]); - }); - } - }); - - // 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); - }, - }); - - // Track button events - instance.web.View.include({ - do_execute_action: function(action_data, dataset, record_id, on_closed) { - console.log(action_data); - var category = this.model || dataset.model || ''; - var action; - if (action_data.name && _.isNaN(action_data.name-0)) { - action = action_data.name; - } else { - action = action_data.string || action_data.special || ''; - } - var label = instance.web_analytics.generateUrl({'model': category, 'view_type': this.view_type}); - _gaq.push(['_trackEvent', category, action, label]); - return this._super.apply(this, arguments); - }, - }); - - // Track error events - instance.web.CrashManager.include({ - show_error: function(error) { - var hash = window.location.hash; - var params = $.deparam(hash.substr(hash.indexOf('#')+1)); - var options = {}; - if (params.model && params.view_type) { - options = {'model': params.model, 'view_type': params.view_type}; + /* + * This method contains the initialization of all user-related custom variables + * stored in GA. Also other modules can override it to add new custom variables + */ + initialize_custom: function() { + // Track User Access Level, Custom Variable 4 in GA with visitor level scope + // Values: 'Admin User', 'Normal User', 'Portal User', 'Anonymous User' + if (instance.session.uid === 1) { + _gaq.push(['_setCustomVar', 4, 'User Type', 'Admin User', 1]); + // Make the difference between portal users and anonymous users + } else if (instance.session.username.indexOf('@') !== -1) { + if (instance.session.username.indexOf('anonymous') === -1) { + _gaq.push(['_setCustomVar', 4, 'User Type', 'Portal User', 1]); } else { - options = {'action': params.action}; + _gaq.push(['_setCustomVar', 4, 'User Type', 'Anonymous User', 1]); } - var label = instance.web_analytics.generateUrl(options); - if (error.code) { - _gaq.push(['_trackEvent', error.message, error.data.fault_code, label, ,true]); - } else { - _gaq.push(['_trackEvent', error.type, error.data.debug, label, ,true]); + } else if (instance.session.username.indexOf('anonymous') !== -1) { + _gaq.push(['_setCustomVar', 4, 'User Type', 'Anonymous User', 1]); + } else { + _gaq.push(['_setCustomVar', 4, 'User Type', 'Normal User', 1]); + } + }, + /* + * This method contains the initialization of the object and view type + * custom variables stored in GA. Setting here the CV will work if web_analytics + * module is auto-install, because the first view of a fresh DB is the modules + * kanban view (also in trial), otherwise the responsibility of the first + * initialization relies on instance.web.ActionManager#ir_actions_client + * method + */ + 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 + _gaq.push(['_setCustomVar', 2, 'Object', state.model, 3]); + // Tack view usage + _gaq.push(['_setCustomVar', 3, 'View Type', state.view_type, 3]); + // Track the page + var url = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type}); + _gaq.push(['_trackPageview', url]); + } + }, + /* + * This method includes the tracker into view and managers. It can be overriden + * by other modules in order to extend tracking functionalities + */ + include_tracker: function() { + // Track the events related with the creation and the modification of records, + // the view type is always form + instance.web.FormView = instance.web.FormView.extend({ + init: function(parent, dataset, view_id, options) { + this._super.apply(this, arguments); + var self = this; + this.on('record_created', self, function(r) { + var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'}); + _gaq.push(['_trackEvent', this.model, 'on_button_create_save', url]); + }); + this.on('record_saved', self, function(r) { + var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'}); + _gaq.push(['_trackEvent', this.model, 'on_button_edit_save', url]); + }); } - this._super.apply(this, arguments); - }, - }); - }; - + }); + + // Track client actions, also if not in a fresh DB it initializes the + // CV related to objects and view types + instance.web.ActionManager.include({ + ir_actions_client: function (action, options) { + if (action.res_model) { + _gaq.push(['_setCustomVar', 2, 'Object', action.res_model, 3]); + } else { + _gaq.push(['_setCustomVar', 2, 'Object', action.type, 3]); + } + _gaq.push(['_setCustomVar', 2, 'View Type', action.name, 3]); + var url = instance.web_analytics.generateUrl({'action': action.tag}); + _gaq.push(['_trackPageview', url]); + return this._super.apply(this, arguments); + }, + }); + + // Track button events + instance.web.View.include({ + do_execute_action: function(action_data, dataset, record_id, on_closed) { + console.log(action_data); + var category = this.model || dataset.model || ''; + var action; + if (action_data.name && _.isNaN(action_data.name-0)) { + action = action_data.name; + } else { + action = action_data.string || action_data.special || ''; + } + var label = instance.web_analytics.generateUrl({'model': category, 'view_type': this.view_type}); + _gaq.push(['_trackEvent', category, action, label]); + return this._super.apply(this, arguments); + }, + }); + + // Track error events + instance.web.CrashManager.include({ + show_error: function(error) { + var hash = window.location.hash; + var params = $.deparam(hash.substr(hash.indexOf('#')+1)); + var options = {}; + if (params.model && params.view_type) { + options = {'model': params.model, 'view_type': params.view_type}; + } else { + options = {'action': params.action}; + } + var label = instance.web_analytics.generateUrl(options); + if (error.code) { + _gaq.push(['_trackEvent', error.message, error.data.fault_code, label, ,true]); + } else { + _gaq.push(['_trackEvent', error.type, error.data.debug, label, ,true]); + } + this._super.apply(this, arguments); + }, + }); + }, + }); + // Set correctly the tracker in the current instance if (instance.client instanceof instance.web.WebClient) { // not for embedded clients - init_tracker(); - - // Set the account and domain to start tracking - instance.client.on('state_pushed', this, on_state_pushed); - - include_tracker(); + instance.webclient.tracker = new instance.web_analytics.Tracker(); } else if (!instance.client) { // client does not already exists, we are in monodb mode - instance.web.WebClient.include({ init: function() { - init_tracker(); - return this._super.apply(this, arguments); + var d = this._super.apply(this, arguments); + this.tracker = new instance.web_analytics.Tracker(); + return d; }, - start: function() { - var self = this; - return this._super.apply(this, arguments).done(function() { - self.on('state_pushed', self, on_state_pushed); - include_tracker(); - }); - } }); } -- cgit v1.2.3 From 8dbb1e46881789727962bc41e58cfceaf7158720 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 3 Jan 2013 11:12:32 +0100 Subject: [IMP] Refactoring web_analytics, final step bzr revid: vta@openerp.com-20130103101232-00tsmlnvi00wsgha --- .../web_analytics/static/src/js/web_analytics.js | 43 ++++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index a25c2169528..94c58bdf9ea 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -26,13 +26,15 @@ openerp.web_analytics = function(instance) { * This method initializes the tracker */ init: function() { + var self = this; _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, this.on_state_pushed); - this.include_tracker(); + this.initialize_custom().then(function() { + instance.client.on('state_pushed', self, self.on_state_pushed); + self.include_tracker(); + }); }, /* * This method contains the initialization of all user-related custom variables @@ -42,27 +44,31 @@ openerp.web_analytics = function(instance) { // Track User Access Level, Custom Variable 4 in GA with visitor level scope // Values: 'Admin User', 'Normal User', 'Portal User', 'Anonymous User' if (instance.session.uid === 1) { - _gaq.push(['_setCustomVar', 4, 'User Type', 'Admin User', 1]); + _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Admin User', 1]); // Make the difference between portal users and anonymous users } else if (instance.session.username.indexOf('@') !== -1) { if (instance.session.username.indexOf('anonymous') === -1) { - _gaq.push(['_setCustomVar', 4, 'User Type', 'Portal User', 1]); + _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Portal User', 1]); } else { - _gaq.push(['_setCustomVar', 4, 'User Type', 'Anonymous User', 1]); + _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Anonymous User', 1]); } } else if (instance.session.username.indexOf('anonymous') !== -1) { - _gaq.push(['_setCustomVar', 4, 'User Type', 'Anonymous User', 1]); + _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Anonymous User', 1]); } else { - _gaq.push(['_setCustomVar', 4, 'User Type', 'Normal User', 1]); + _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Normal User', 1]); } + return instance.session.rpc("/web/webclient/version_info", {}) + .done(function(res) { + _gaq.push(['_setCustomVar', 5, 'Version', res.server_version, 3]); + }); }, /* * This method contains the initialization of the object and view type * custom variables stored in GA. Setting here the CV will work if web_analytics - * module is auto-install, because the first view of a fresh DB is the modules - * kanban view (also in trial), otherwise the responsibility of the first - * initialization relies on instance.web.ActionManager#ir_actions_client - * method + * module is auto-install and not anonymous user, because the first view + * of a fresh DB is the modules kanban view (also in trial), otherwise the + * responsibility of the first initialization relies on + * instance.web.ActionManager#ir_actions_client method */ on_state_pushed: function(state) { // Track only pages corresponding to a 'normal' view of OpenERP, views @@ -99,16 +105,22 @@ openerp.web_analytics = function(instance) { } }); - // Track client actions, also if not in a fresh DB it initializes the - // CV related to objects and view types + // Track client actions, also if not in a fresh DB or anonymous user, + // it initializes the CV related to objects and view types instance.web.ActionManager.include({ ir_actions_client: function (action, options) { + // Try to set the correct model, else it will be 'ir.actions.client' if (action.res_model) { _gaq.push(['_setCustomVar', 2, 'Object', action.res_model, 3]); } else { _gaq.push(['_setCustomVar', 2, 'Object', action.type, 3]); } - _gaq.push(['_setCustomVar', 2, 'View Type', action.name, 3]); + // Try to set a view type as accurate as possible + if (action.name) { + _gaq.push(['_setCustomVar', 3, 'View Type', action.name, 3]); + } else { + _gaq.push(['_setCustomVar', 3, 'View Type', action.tag, 3]); + } var url = instance.web_analytics.generateUrl({'action': action.tag}); _gaq.push(['_trackPageview', url]); return this._super.apply(this, arguments); @@ -118,7 +130,6 @@ openerp.web_analytics = function(instance) { // Track button events instance.web.View.include({ do_execute_action: function(action_data, dataset, record_id, on_closed) { - console.log(action_data); var category = this.model || dataset.model || ''; var action; if (action_data.name && _.isNaN(action_data.name-0)) { -- cgit v1.2.3 From 408ce4a241e6d9a5033295cbe5049b653576dbd2 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 3 Jan 2013 14:25:19 +0100 Subject: [IMP] Add multi-domain tracking capabilites bzr revid: vta@openerp.com-20130103132519-qypobspl58v435xw --- addons/web_analytics/static/src/js/web_analytics.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 94c58bdf9ea..44cfcf65581 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -27,10 +27,17 @@ openerp.web_analytics = function(instance) { */ init: function() { var self = this; + + /* Comment this lines when going on production, only used for testing on localhost */ _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 + _gaq.push(['_setDomainName', 'none']); + /**/ + + /* Uncomment this lines when going on production + _gaq.push(['_setAccount', 'UA-7333765-1']); + _gaq.push(['_setDomainName', '.openerp.com']); // Allow multi-domain + */ + this.initialize_custom().then(function() { instance.client.on('state_pushed', self, self.on_state_pushed); self.include_tracker(); -- cgit v1.2.3 From 0b02663f9a9fcfce4b83f0b92e4386e6ed5c6ce6 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 3 Jan 2013 14:27:05 +0100 Subject: [IMP] Added comment line bzr revid: vta@openerp.com-20130103132705-evxyn3dyvjes7q6k --- addons/web_analytics/static/src/js/web_analytics.js | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 44cfcf65581..599b34c4af0 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -64,6 +64,7 @@ openerp.web_analytics = function(instance) { } else { _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Normal User', 1]); } + // Fetch OpenERP's version of the instance return instance.session.rpc("/web/webclient/version_info", {}) .done(function(res) { _gaq.push(['_setCustomVar', 5, 'Version', res.server_version, 3]); -- cgit v1.2.3 From 16d25f400e57e31ffa00774c740f878d50b2a27f Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 3 Jan 2013 15:05:10 +0100 Subject: [FIX] Fixed comment bzr revid: vta@openerp.com-20130103140510-eyjh56vhh7n8lqol --- addons/web_analytics/static/src/js/web_analytics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 599b34c4af0..c75eeb39e4a 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -4,7 +4,7 @@ var _gaq = _gaq || []; // asynchronous stack used by google analytics openerp.web_analytics = function(instance) { /* - * The Google Analytics Module inserts the Google Analytics JS Snippet + * The Web Analytics Module inserts the Google Analytics JS Snippet * at the top of the page, and sends to google an url each time the * openerp url is changed. * The pushes of the urls is made by triggering the 'state_pushed' event in the -- cgit v1.2.3 From 6389eaa52b3363fce19ef94f433b172ec3189148 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Fri, 4 Jan 2013 13:58:49 +0100 Subject: [IMP] Refactor initialize_custom bzr revid: vta@openerp.com-20130104125849-0p3wm2g1hpvlyory --- .../web_analytics/static/src/js/web_analytics.js | 57 ++++++++++++++-------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index c75eeb39e4a..806803c80a7 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -26,8 +26,6 @@ openerp.web_analytics = function(instance) { * This method initializes the tracker */ init: function() { - var self = this; - /* Comment this lines when going on production, only used for testing on localhost */ _gaq.push(['_setAccount', 'UA-35793871-1']); _gaq.push(['_setDomainName', 'none']); @@ -37,37 +35,47 @@ openerp.web_analytics = function(instance) { _gaq.push(['_setAccount', 'UA-7333765-1']); _gaq.push(['_setDomainName', '.openerp.com']); // Allow multi-domain */ - - this.initialize_custom().then(function() { - instance.client.on('state_pushed', self, self.on_state_pushed); - self.include_tracker(); - }); }, /* - * This method contains the initialization of all user-related custom variables - * stored in GA. Also other modules can override it to add new custom variables + * This method MUST be overriden by saas_demo and saas_trial in order to + * set the correct user type. By default, the user connected is local to the DB. */ - initialize_custom: function() { - // Track User Access Level, Custom Variable 4 in GA with visitor level scope - // Values: 'Admin User', 'Normal User', 'Portal User', 'Anonymous User' + _get_user_type: function() { + return 'Local User'; + }, + _set_user_access_level: function() { if (instance.session.uid === 1) { - _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Admin User', 1]); + return 'Admin User'; // Make the difference between portal users and anonymous users } else if (instance.session.username.indexOf('@') !== -1) { if (instance.session.username.indexOf('anonymous') === -1) { - _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Portal User', 1]); + return 'Portal User'; } else { - _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Anonymous User', 1]); + return 'Anonymous User'; } } else if (instance.session.username.indexOf('anonymous') !== -1) { - _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Anonymous User', 1]); + return 'Anonymous User'; } else { - _gaq.push(['_setCustomVar', 4, 'User Access Level', 'Normal User', 1]); + return 'Normal User'; } - // Fetch OpenERP's version of the instance + }, + /* + * This method contains the initialization of all user-related custom variables + * stored in GA. Also other modules can override it to add new custom variables + */ + initialize_custom: function() { + // Track User Access Level, Custom Variable 4 in GA with visitor level scope + // Values: 'Admin User', 'Normal User', 'Portal User', 'Anonymous User' + _gaq.push(['_setCustomVar', 4, 'User Access Level', this.user_access_level, 1]); + + // Track User Type Conversion, Custom Variable 3 in GA with session level scope + // Values: 'Visitor', 'Demo', 'Online Trial', 'Online Paying', 'Local User' + _gaq.push(['_setCustomVar', 1, 'User Type Conversion', this._get_user_type(), 2]); + return instance.session.rpc("/web/webclient/version_info", {}) .done(function(res) { _gaq.push(['_setCustomVar', 5, 'Version', res.server_version, 3]); + return; }); }, /* @@ -180,11 +188,22 @@ openerp.web_analytics = function(instance) { } else if (!instance.client) { // client does not already exists, we are in monodb mode instance.web.WebClient.include({ - init: function() { + start: function() { var d = this._super.apply(this, arguments); this.tracker = new instance.web_analytics.Tracker(); return d; }, + show_application: function() { + var self = this; + $.when(this.tracker._set_user_access_level()).then(function(r) { + self.tracker.user_access_level = r; + self.tracker.initialize_custom().then(function() { + instance.webclient.on('state_pushed', self, self.tracker.on_state_pushed); + self.tracker.include_tracker(); + }); + self._super(); + }); + }, }); } -- cgit v1.2.3 From 185aac252a988cc32a41bbce3c97c2284ffc0673 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Fri, 4 Jan 2013 14:04:25 +0100 Subject: [FIX] Add support for multidb mode bzr revid: vta@openerp.com-20130104130425-t5b1etm074ha4lmz --- addons/web_analytics/static/src/js/web_analytics.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 806803c80a7..1e02de4f051 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -185,6 +185,13 @@ openerp.web_analytics = function(instance) { // Set correctly the tracker in the current instance if (instance.client instanceof instance.web.WebClient) { // not for embedded clients instance.webclient.tracker = new instance.web_analytics.Tracker(); + $.when(instance.webclient.tracker._set_user_access_level()).then(function(r) { + instance.webclient.tracker.user_access_level = r; + instance.webclient.tracker.initialize_custom().then(function() { + instance.webclient.on('state_pushed', self, instance.webclient.tracker.on_state_pushed); + instance.webclient.tracker.include_tracker(); + }); + }); } else if (!instance.client) { // client does not already exists, we are in monodb mode instance.web.WebClient.include({ -- cgit v1.2.3 From 129295d5984da5f4764d9732f4b92858e7432a37 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Mon, 7 Jan 2013 16:33:21 +0100 Subject: [IMP] Refactoring setup on webclient, changed Object and View Type custom variables onto events (GA doesn't support multiple sets on page-level cv) bzr revid: vta@openerp.com-20130107153321-b1pimfpmfy4xg8pv --- .../web_analytics/static/src/js/web_analytics.js | 87 +++++++++------------- 1 file changed, 34 insertions(+), 53 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 1e02de4f051..2ef4b277868 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -80,23 +80,15 @@ openerp.web_analytics = function(instance) { }, /* * This method contains the initialization of the object and view type - * custom variables stored in GA. Setting here the CV will work if web_analytics - * module is auto-install and not anonymous user, because the first view - * of a fresh DB is the modules kanban view (also in trial), otherwise the - * responsibility of the first initialization relies on - * instance.web.ActionManager#ir_actions_client method + * as an event in GA. */ 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 - _gaq.push(['_setCustomVar', 2, 'Object', state.model, 3]); - // Tack view usage - _gaq.push(['_setCustomVar', 3, 'View Type', state.view_type, 3]); // Track the page - var url = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type}); - _gaq.push(['_trackPageview', url]); + var label = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type}); + _gaq.push(['_trackEvent', state.model, state.view_type, label]); } }, /* @@ -106,7 +98,7 @@ openerp.web_analytics = function(instance) { include_tracker: function() { // Track the events related with the creation and the modification of records, // the view type is always form - instance.web.FormView = instance.web.FormView.extend({ + instance.web.FormView.include({ init: function(parent, dataset, view_id, options) { this._super.apply(this, arguments); var self = this; @@ -121,24 +113,13 @@ openerp.web_analytics = function(instance) { } }); - // Track client actions, also if not in a fresh DB or anonymous user, - // it initializes the CV related to objects and view types + // Track client actions instance.web.ActionManager.include({ ir_actions_client: function (action, options) { - // Try to set the correct model, else it will be 'ir.actions.client' - if (action.res_model) { - _gaq.push(['_setCustomVar', 2, 'Object', action.res_model, 3]); - } else { - _gaq.push(['_setCustomVar', 2, 'Object', action.type, 3]); - } - // Try to set a view type as accurate as possible - if (action.name) { - _gaq.push(['_setCustomVar', 3, 'View Type', action.name, 3]); - } else { - _gaq.push(['_setCustomVar', 3, 'View Type', action.tag, 3]); - } - var url = instance.web_analytics.generateUrl({'action': action.tag}); - _gaq.push(['_trackPageview', url]); + var label = instance.web_analytics.generateUrl({'action': action.tag}); + var category = action.res_model || action.type; + var ga_action = action.name || action.tag; + _gaq.push(['_trackEvent', category, ga_action, label]); return this._super.apply(this, arguments); }, }); @@ -182,16 +163,33 @@ openerp.web_analytics = function(instance) { }, }); + // ---------------------------------------------------------------- + // utility functions + // ---------------------------------------------------------------- + + instance.web_analytics.generateUrl = function(options) { + var url = ''; + _.each(options, function(value, key) { + url += '/' + key + '=' + value; + }); + return url; + }; + + instance.web_analytics.setupTracker = function(wc) { + var t = wc.tracker; + return $.when(t._set_user_access_level()).then(function(r) { + t.user_access_level = r; + t.initialize_custom().then(function() { + wc.on('state_pushed', wc, t.on_state_pushed); + t.include_tracker(); + }); + }); + }; + // Set correctly the tracker in the current instance if (instance.client instanceof instance.web.WebClient) { // not for embedded clients instance.webclient.tracker = new instance.web_analytics.Tracker(); - $.when(instance.webclient.tracker._set_user_access_level()).then(function(r) { - instance.webclient.tracker.user_access_level = r; - instance.webclient.tracker.initialize_custom().then(function() { - instance.webclient.on('state_pushed', self, instance.webclient.tracker.on_state_pushed); - instance.webclient.tracker.include_tracker(); - }); - }); + instance.web_analytics.setupTracker(instance.webclient); } else if (!instance.client) { // client does not already exists, we are in monodb mode instance.web.WebClient.include({ @@ -202,28 +200,11 @@ openerp.web_analytics = function(instance) { }, show_application: function() { var self = this; - $.when(this.tracker._set_user_access_level()).then(function(r) { - self.tracker.user_access_level = r; - self.tracker.initialize_custom().then(function() { - instance.webclient.on('state_pushed', self, self.tracker.on_state_pushed); - self.tracker.include_tracker(); - }); + instance.web_analytics.setupTracker(self).then(function() { self._super(); }); }, }); } - // ---------------------------------------------------------------- - // utility functions - // ---------------------------------------------------------------- - - instance.web_analytics.generateUrl = function(options) { - var url = ''; - _.each(options, function(value, key) { - url += '/' + key + '=' + value; - }); - return url; - }; - }; -- cgit v1.2.3 From fd7680daa75d5c41024c2cedee11bc5ea7a1959e Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 8 Jan 2013 10:17:54 +0100 Subject: [IMP] Added _push_ecommerce function to web_analytics.Tracker. Minor naming fix bzr revid: vta@openerp.com-20130108091754-7zu8asu7hwx8bd1y --- .../web_analytics/static/src/js/web_analytics.js | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 2ef4b277868..ee06a6373ed 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -43,7 +43,7 @@ openerp.web_analytics = function(instance) { _get_user_type: function() { return 'Local User'; }, - _set_user_access_level: function() { + _get_user_access_level: function() { if (instance.session.uid === 1) { return 'Admin User'; // Make the difference between portal users and anonymous users @@ -161,6 +161,29 @@ openerp.web_analytics = function(instance) { }, }); }, + _push_ecommerce: function(trans_data, item_list) { + _gaq.push(['_addTrans', + trans_data.order_id, + trans_data.store_name, + trans_data.total, + trans_data.tax, + trans_data.shipping, + trans_data.city, + trans_data.state + trans_data.country, + ]); + _.each(item_list, function(item) { + _gaq.push(['_addItem', + item.order_id, + item.sku, + item.name, + item.category, + item.price, + item.quantity, + ]); + }); + _gaq.push(['_trackTrans']); + }, }); // ---------------------------------------------------------------- @@ -177,7 +200,7 @@ openerp.web_analytics = function(instance) { instance.web_analytics.setupTracker = function(wc) { var t = wc.tracker; - return $.when(t._set_user_access_level()).then(function(r) { + return $.when(t._get_user_access_level()).then(function(r) { t.user_access_level = r; t.initialize_custom().then(function() { wc.on('state_pushed', wc, t.on_state_pushed); -- cgit v1.2.3 From 2743be58628f3043e5217ddc114eb6fd57fad6be Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 8 Jan 2013 10:48:50 +0100 Subject: [IMP] Refactor event tracking bzr revid: vta@openerp.com-20130108094850-452xq5vbfnnoipz5 --- .../web_analytics/static/src/js/web_analytics.js | 85 ++++++++++++++++------ 1 file changed, 63 insertions(+), 22 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index ee06a6373ed..1f9185a5216 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -87,8 +87,12 @@ openerp.web_analytics = function(instance) { // related to client actions are tracked by the action manager if (state.model && state.view_type) { // Track the page - var label = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type}); - _gaq.push(['_trackEvent', state.model, state.view_type, label]); + var url = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type}); + this._push_event({ + 'category': state.model, + 'action': state.view_type, + 'label': url, + }); } }, /* @@ -96,6 +100,7 @@ openerp.web_analytics = function(instance) { * by other modules in order to extend tracking functionalities */ include_tracker: function() { + var t = this; // Track the events related with the creation and the modification of records, // the view type is always form instance.web.FormView.include({ @@ -103,12 +108,20 @@ openerp.web_analytics = function(instance) { this._super.apply(this, arguments); var self = this; this.on('record_created', self, function(r) { - var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'}); - _gaq.push(['_trackEvent', this.model, 'on_button_create_save', url]); + var url = instance.web_analytics.generateUrl({'model': r.model, 'view_type': 'form'}); + t._push_event({ + 'category': r.model, + 'action': 'form', + 'label': url, + }); }); this.on('record_saved', self, function(r) { - var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'}); - _gaq.push(['_trackEvent', this.model, 'on_button_edit_save', url]); + var url = instance.web_analytics.generateUrl({'model': r.model, 'view_type': 'form'}); + t._push_event({ + 'category': r.model, + 'action': 'form', + 'label': url, + }); }); } }); @@ -116,10 +129,13 @@ openerp.web_analytics = function(instance) { // Track client actions instance.web.ActionManager.include({ ir_actions_client: function (action, options) { - var label = instance.web_analytics.generateUrl({'action': action.tag}); + var url = instance.web_analytics.generateUrl({'action': action.tag}); var category = action.res_model || action.type; - var ga_action = action.name || action.tag; - _gaq.push(['_trackEvent', category, ga_action, label]); + t._push_event({ + 'category': action.res_model || action.type, + 'action': action.name || action.tag, + 'label': url, + }); return this._super.apply(this, arguments); }, }); @@ -134,8 +150,12 @@ openerp.web_analytics = function(instance) { } else { action = action_data.string || action_data.special || ''; } - var label = instance.web_analytics.generateUrl({'model': category, 'view_type': this.view_type}); - _gaq.push(['_trackEvent', category, action, label]); + var url = instance.web_analytics.generateUrl({'model': category, 'view_type': this.view_type}); + t._push_event({ + 'category': category, + 'action': action, + 'label': url, + }); return this._super.apply(this, arguments); }, }); @@ -151,26 +171,47 @@ openerp.web_analytics = function(instance) { } else { options = {'action': params.action}; } - var label = instance.web_analytics.generateUrl(options); + var url = instance.web_analytics.generateUrl(options); if (error.code) { - _gaq.push(['_trackEvent', error.message, error.data.fault_code, label, ,true]); + t._push_event({ + 'category': error.message, + 'action': error.data.fault_code, + 'label': url, + 'value': undefined, + 'noninteraction': true, + }); } else { - _gaq.push(['_trackEvent', error.type, error.data.debug, label, ,true]); + t._push_event({ + 'category': error.type, + 'action': error.data.debug, + 'label': url, + 'value': undefined, + 'noninteraction': true, + }); } this._super.apply(this, arguments); }, }); }, + _push_event: function(options) { + _gaq.push(['_trackEvent', + options.category, + options.action, + options.label, + options.value, + options.noninteraction + ]); + }, _push_ecommerce: function(trans_data, item_list) { _gaq.push(['_addTrans', - trans_data.order_id, - trans_data.store_name, - trans_data.total, - trans_data.tax, - trans_data.shipping, - trans_data.city, - trans_data.state - trans_data.country, + trans_data.order_id, + trans_data.store_name, + trans_data.total, + trans_data.tax, + trans_data.shipping, + trans_data.city, + trans_data.state + trans_data.country, ]); _.each(item_list, function(item) { _gaq.push(['_addItem', -- cgit v1.2.3 From 78a36ad7a40485dfa1a2527eb29f61bd85ba7e17 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 8 Jan 2013 11:32:00 +0100 Subject: [FIX] Remove unused key bzr revid: vta@openerp.com-20130108103200-qq94ad7clyootwtx --- addons/web_analytics/static/src/js/web_analytics.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 1f9185a5216..2b659d5e6a9 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -177,7 +177,6 @@ openerp.web_analytics = function(instance) { 'category': error.message, 'action': error.data.fault_code, 'label': url, - 'value': undefined, 'noninteraction': true, }); } else { @@ -185,7 +184,6 @@ openerp.web_analytics = function(instance) { 'category': error.type, 'action': error.data.debug, 'label': url, - 'value': undefined, 'noninteraction': true, }); } -- cgit v1.2.3 From e7d32f666e0540a4099d2ffa3960ab44d489639c Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 8 Jan 2013 11:38:13 +0100 Subject: [IMP] Added comments bzr revid: vta@openerp.com-20130108103813-opbmmavuxlfmuqaw --- addons/web_analytics/static/src/js/web_analytics.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 2b659d5e6a9..fedc13b6f23 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -43,6 +43,9 @@ openerp.web_analytics = function(instance) { _get_user_type: function() { return 'Local User'; }, + /* + * This method gets the user access level, to be used as CV in GA + */ _get_user_access_level: function() { if (instance.session.uid === 1) { return 'Admin User'; @@ -96,7 +99,7 @@ openerp.web_analytics = function(instance) { } }, /* - * This method includes the tracker into view and managers. It can be overriden + * This method includes the tracker into views and managers. It can be overriden * by other modules in order to extend tracking functionalities */ include_tracker: function() { @@ -191,6 +194,9 @@ openerp.web_analytics = function(instance) { }, }); }, + /* + * Method called in order to send _trackEvent to GA + */ _push_event: function(options) { _gaq.push(['_trackEvent', options.category, @@ -200,6 +206,9 @@ openerp.web_analytics = function(instance) { options.noninteraction ]); }, + /* + * Method called in order to send ecommerce transactions to GA + */ _push_ecommerce: function(trans_data, item_list) { _gaq.push(['_addTrans', trans_data.order_id, -- cgit v1.2.3 From cd1454e6b928b2bb9475b7c4ab64472d1a150cd6 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 8 Jan 2013 11:39:31 +0100 Subject: [FIX] Going into production bzr revid: vta@openerp.com-20130108103931-55s7n8xrwrkztrgy --- addons/web_analytics/static/src/js/web_analytics.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index fedc13b6f23..9960d3cfde0 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -26,15 +26,15 @@ openerp.web_analytics = function(instance) { * This method initializes the tracker */ init: function() { - /* Comment this lines when going on production, only used for testing on localhost */ + /* Comment this lines when going on production, only used for testing on localhost _gaq.push(['_setAccount', 'UA-35793871-1']); _gaq.push(['_setDomainName', 'none']); - /**/ + */ - /* Uncomment this lines when going on production + /* Uncomment this lines when going on production */ _gaq.push(['_setAccount', 'UA-7333765-1']); _gaq.push(['_setDomainName', '.openerp.com']); // Allow multi-domain - */ + /**/ }, /* * This method MUST be overriden by saas_demo and saas_trial in order to -- cgit v1.2.3 From 562b7bed64325d5d1e2111ff78c76dbd3552e6a5 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 8 Jan 2013 12:21:36 +0100 Subject: [FIX] Launch application even if the tracker crashes bzr revid: vta@openerp.com-20130108112136-xiqejgkxazy23djy --- addons/web_analytics/static/src/js/web_analytics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 9960d3cfde0..8d4c87d61e1 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -271,7 +271,7 @@ openerp.web_analytics = function(instance) { }, show_application: function() { var self = this; - instance.web_analytics.setupTracker(self).then(function() { + instance.web_analytics.setupTracker(self).always(function() { self._super(); }); }, -- cgit v1.2.3 From acfd3b3aa2381e254318f59b2c4948a685f4c4ee Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 9 Jan 2013 10:50:49 +0100 Subject: [FIX] Forgotten ',' and issue on calling _push_event bzr revid: vta@openerp.com-20130109095049-4gb392x20iius6pj --- .../web_analytics/static/src/js/web_analytics.js | 78 +++++++++++----------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 8d4c87d61e1..4777d14d384 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -23,7 +23,7 @@ openerp.web_analytics = function(instance) { instance.web_analytics.Tracker = instance.web.Class.extend({ /* - * This method initializes the tracker + * This method initializes the tracker */ init: function() { /* Comment this lines when going on production, only used for testing on localhost @@ -82,6 +82,44 @@ openerp.web_analytics = function(instance) { }); }, /* + * Method called in order to send _trackEvent to GA + */ + _push_event: function(options) { + _gaq.push(['_trackEvent', + options.category, + options.action, + options.label, + options.value, + options.noninteraction + ]); + }, + /* + * Method called in order to send ecommerce transactions to GA + */ + _push_ecommerce: function(trans_data, item_list) { + _gaq.push(['_addTrans', + trans_data.order_id, + trans_data.store_name, + trans_data.total, + trans_data.tax, + trans_data.shipping, + trans_data.city, + trans_data.state, + trans_data.country, + ]); + _.each(item_list, function(item) { + _gaq.push(['_addItem', + item.order_id, + item.sku, + item.name, + item.category, + item.price, + item.quantity, + ]); + }); + _gaq.push(['_trackTrans']); + }, + /* * This method contains the initialization of the object and view type * as an event in GA. */ @@ -194,44 +232,6 @@ openerp.web_analytics = function(instance) { }, }); }, - /* - * Method called in order to send _trackEvent to GA - */ - _push_event: function(options) { - _gaq.push(['_trackEvent', - options.category, - options.action, - options.label, - options.value, - options.noninteraction - ]); - }, - /* - * Method called in order to send ecommerce transactions to GA - */ - _push_ecommerce: function(trans_data, item_list) { - _gaq.push(['_addTrans', - trans_data.order_id, - trans_data.store_name, - trans_data.total, - trans_data.tax, - trans_data.shipping, - trans_data.city, - trans_data.state - trans_data.country, - ]); - _.each(item_list, function(item) { - _gaq.push(['_addItem', - item.order_id, - item.sku, - item.name, - item.category, - item.price, - item.quantity, - ]); - }); - _gaq.push(['_trackTrans']); - }, }); // ---------------------------------------------------------------- -- cgit v1.2.3 From afafaff8dacdc9d8d06e8cc7948443f23695587b Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 9 Jan 2013 11:24:29 +0100 Subject: [FIX] Pass the right object when binding to 'state_pushed' bzr revid: vta@openerp.com-20130109102429-2k33nl3nwg3p0cna --- addons/web_analytics/static/src/js/web_analytics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 4777d14d384..f702a0d1d5b 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -251,7 +251,7 @@ openerp.web_analytics = function(instance) { return $.when(t._get_user_access_level()).then(function(r) { t.user_access_level = r; t.initialize_custom().then(function() { - wc.on('state_pushed', wc, t.on_state_pushed); + wc.on('state_pushed', t, t.on_state_pushed); t.include_tracker(); }); }); -- cgit v1.2.3 From d9faa7c095718e405e0cf043090526a259d527b8 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 10 Jan 2013 09:47:00 +0100 Subject: [FIX] Handle correctly webclient's show_application execution in web_analytics bzr revid: vta@openerp.com-20130110084700-curkkezb5333edai --- addons/web_analytics/static/src/js/web_analytics.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'addons/web_analytics/static/src/js') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index f702a0d1d5b..75bcf29a575 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -78,6 +78,7 @@ openerp.web_analytics = function(instance) { return instance.session.rpc("/web/webclient/version_info", {}) .done(function(res) { _gaq.push(['_setCustomVar', 5, 'Version', res.server_version, 3]); + _gaq.push(['_trackPageview']); return; }); }, @@ -271,9 +272,10 @@ openerp.web_analytics = function(instance) { }, show_application: function() { var self = this; - instance.web_analytics.setupTracker(self).always(function() { - self._super(); + $.when(this.subscribe_deferred).then(function() { + instance.web_analytics.setupTracker(self); }); + this._super(); }, }); } -- cgit v1.2.3