diff options
| author | vta vta@openerp.com <> | 2013-01-04 13:58:49 +0100 |
|---|---|---|
| committer | vta vta@openerp.com <> | 2013-01-04 13:58:49 +0100 |
| commit | 6389eaa52b3363fce19ef94f433b172ec3189148 (patch) | |
| tree | f9ab99044800bcea459acdc76210c7bb63934e07 /addons/web_analytics/static/src | |
| parent | 64ff6a065d7f776c79433461db29709e4c230925 (diff) | |
[IMP] Refactor initialize_custom
bzr revid: vta@openerp.com-20130104125849-0p3wm2g1hpvlyory
Diffstat (limited to 'addons/web_analytics/static/src')
| -rw-r--r-- | addons/web_analytics/static/src/js/web_analytics.js | 57 |
1 files changed, 38 insertions, 19 deletions
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(); + }); + }, }); } |
