diff options
| author | vta vta@openerp.com <> | 2013-01-07 16:33:21 +0100 |
|---|---|---|
| committer | vta vta@openerp.com <> | 2013-01-07 16:33:21 +0100 |
| commit | 129295d5984da5f4764d9732f4b92858e7432a37 (patch) | |
| tree | bc93a3d307d8d946e1e8991654d6eb03c580e063 /addons/web_analytics/static/src | |
| parent | 185aac252a988cc32a41bbce3c97c2284ffc0673 (diff) | |
[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
Diffstat (limited to 'addons/web_analytics/static/src')
| -rw-r--r-- | addons/web_analytics/static/src/js/web_analytics.js | 87 |
1 files changed, 34 insertions, 53 deletions
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; - }; - }; |
