From 7d15ab44f439138b18a56a908ba9ca120c993b98 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 23 Oct 2012 17:15:49 +0200 Subject: [FIX] Fixed naming, the account used in ga, and the controller. bzr revid: vta@openerp.com-20121023151549-atepg5qan70xhmiq --- addons/web_analytics/__init__.py | 0 addons/web_analytics/__openerp__.py | 40 +++++++++++++++ addons/web_analytics/controllers/__init__.py | 3 ++ addons/web_analytics/controllers/main.py | 34 +++++++++++++ addons/web_analytics/static/src/img/icon.png | Bin 0 -> 11486 bytes .../web_analytics/static/src/js/web_analytics.js | 56 +++++++++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 addons/web_analytics/__init__.py create mode 100644 addons/web_analytics/__openerp__.py create mode 100644 addons/web_analytics/controllers/__init__.py create mode 100644 addons/web_analytics/controllers/main.py create mode 100644 addons/web_analytics/static/src/img/icon.png create mode 100644 addons/web_analytics/static/src/js/web_analytics.js (limited to 'addons/web_analytics') diff --git a/addons/web_analytics/__init__.py b/addons/web_analytics/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/addons/web_analytics/__openerp__.py b/addons/web_analytics/__openerp__.py new file mode 100644 index 00000000000..2fa95c7398b --- /dev/null +++ b/addons/web_analytics/__openerp__.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2012 OpenERP s.a. (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Google Analytics', + 'version': '1.0', + 'category': 'Tools', + 'complexity': "easy", + 'description': """ +Google Analytics. +============================== + +Collects web application usage with Google Analytics. + """, + 'author': 'OpenERP SA', + 'website': 'http://openerp.com', + 'depends': ['web'], + 'data': [], + 'installable': True, + 'active': False, + 'js': ['static/src/js/web_analytics.js'], +} + diff --git a/addons/web_analytics/controllers/__init__.py b/addons/web_analytics/controllers/__init__.py new file mode 100644 index 00000000000..9f828025b8e --- /dev/null +++ b/addons/web_analytics/controllers/__init__.py @@ -0,0 +1,3 @@ +import main + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/web_analytics/controllers/main.py b/addons/web_analytics/controllers/main.py new file mode 100644 index 00000000000..82c42efecb0 --- /dev/null +++ b/addons/web_analytics/controllers/main.py @@ -0,0 +1,34 @@ +import json +import textwrap + +import simplejson +import werkzeug.wrappers + +import web.common.http as openerpweb +import web.controllers.main + +class web_analytics(openerpweb.Controller): + + # This controllers redirects virtual urls of the form /web_analytics/MODEL/VIEW + # as provided to google by the analytics modules to a real url that openerp can + # understand of the form /#model=MODEL&view_type=VIEW + # So that the user can click openerp urls inside google analytics. + + _cp_path = "/web_analytics" + + @openerpweb.httprequest + def redirect(self, req): + url = req.httprequest.base_url + suburl = url.split('/') + suburl = suburl[suburl.index('redirect')+1:] + + rurl = "/#" + if len(suburl) >=1 and suburl[0]: + rurl += "model="+str(suburl[0]) + if len(suburl) >=2 and suburl[1]: + rurl += "&view_type="+str(suburl[1]) + + redirect = werkzeug.utils.redirect(rurl, 303) + + return redirect + diff --git a/addons/web_analytics/static/src/img/icon.png b/addons/web_analytics/static/src/img/icon.png new file mode 100644 index 00000000000..320c1f3ec34 Binary files /dev/null and b/addons/web_analytics/static/src/img/icon.png differ diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js new file mode 100644 index 00000000000..800e41b5a64 --- /dev/null +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -0,0 +1,56 @@ + +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 a virtual url each time the + * openerp url is changed. Google needs a virtual url because it cannot + * handle sharps in the url. At this time the virtual url only handles the + * model and view parameters and is of the form /web_analytics/redirect/MODEL/VIEW + * + * The pushes of the virtual urls is made by adding a callback to the + * web_client.do_push_state() method which is responsible of changing the openerp current url + */ + + if (instance.webclient) { + // _gaq.push(['_setAccount', 'UA-25293939-2']); // fva@openerp.com localhost + // _gaq.push(['_setAccount', 'UA-28648768-1']); // fva@openerp.com runbot + // _gaq.push(['_setAccount', 'UA-28648768-1']); // fva@openerp.com + // _gaq.push(['_setAccount', 'UA-7333765-1']); // fp@openerp.com + // _gaq.push(['_setAccount', 'UA-7333765-1']); // fp@openerp.com + // _gaq.push(['_setDomainName', '.openerp.com']); + + _gaq.push(['_setAccount', 'UA-35793871-1']); // vta@openerp.com localhost + _gaq.push(['setDomainName', 'none']); + _gaq.push(['_trackPageview']); + + // var connection = instance.session.connection; + _gaq.push(['_setCustomVar', 1, 'Normal User', String(instance.session.uid === 1), 1]); + _gaq.push(['_setCustomVar', 2, 'Admin User', String(instance.session.uid === 1), 1]); + + // Google Analytics Code snippet + (function() { + var ga = document.createElement('script'); + ga.type = 'text/javascript'; + ga.async = true + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; + s.parentNode.insertBefore(ga,s); + })(); + + var self = this; + instance.webclient.on('state_pushed', self, function(state) { + var model_whitelist = {'sale.order':'', 'purchase.order':'', 'crm.lead':''}; + var view_type_blacklist = {'default':''}; + var model = state["model"] || "no_model"; + var view_type = state["view_type"] || "default"; + if ((model in model_whitelist) && !(view_type in view_type_blacklist)) { + var vurl = "web_analytics/redirect/"+ model + "/" + view_type + console.log(vurl); + _gaq.push(['_trackPageview',vurl]); + } + }); + } + +}; \ No newline at end of file -- cgit v1.2.3 From 21b916349a89bb9274667f135f1f9d79908c4057 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 24 Oct 2012 17:45:39 +0200 Subject: [IMP] Improved working with events. bzr revid: vta@openerp.com-20121024154539-n2hvx8m9bbicvrur --- .../web_analytics/static/src/js/web_analytics.js | 50 ++++++++++++++++------ 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'addons/web_analytics') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index 800e41b5a64..e9f83780a2d 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -22,12 +22,23 @@ openerp.web_analytics = function(instance) { // _gaq.push(['_setDomainName', '.openerp.com']); _gaq.push(['_setAccount', 'UA-35793871-1']); // vta@openerp.com localhost - _gaq.push(['setDomainName', 'none']); + _gaq.push(['_setDomainName', 'none']); _gaq.push(['_trackPageview']); + _gaq.push(['_deleteCustomVar', 1]); + _gaq.push(['_deleteCustomVar', 2]); + _gaq.push(['_deleteCustomVar', 3]); + _gaq.push(['_deleteCustomVar', 4]); + _gaq.push(['_deleteCustomVar', 5]); - // var connection = instance.session.connection; - _gaq.push(['_setCustomVar', 1, 'Normal User', String(instance.session.uid === 1), 1]); - _gaq.push(['_setCustomVar', 2, 'Admin User', String(instance.session.uid === 1), 1]); + 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 { + _gaq.push(['_setCustomVar', 1, 'User Type', 'Admin User', 1]); + } // Google Analytics Code snippet (function() { @@ -41,16 +52,31 @@ openerp.web_analytics = function(instance) { var self = this; instance.webclient.on('state_pushed', self, function(state) { - var model_whitelist = {'sale.order':'', 'purchase.order':'', 'crm.lead':''}; - var view_type_blacklist = {'default':''}; - var model = state["model"] || "no_model"; + var url = '/' + window.location.hash; + _gaq.push(['_trackPageview', url]); + var model = state["model"] || "no_model"; var view_type = state["view_type"] || "default"; - if ((model in model_whitelist) && !(view_type in view_type_blacklist)) { - var vurl = "web_analytics/redirect/"+ model + "/" + view_type - console.log(vurl); - _gaq.push(['_trackPageview',vurl]); - } + _gaq.push(['_setCustomVar', 2, 'Object', model, 3]); + _gaq.push(['_setCustomVar', 3, 'View Type', view_type, 3]); }); } + instance.web.FormView = instance.web.FormView.extend({ + save: function(prepend_on_create) { + if (!this.datarecord.id) { + _gaq.push(['_trackEvent', this.model, 'on_button_save', 'Save']); + } else { + _gaq.push(['_trackEvent', this.model, 'on_button_edit', 'Save']); + } + return this._super.apply(this, arguments); + } + }); + + instance.web.form.WidgetButton = instance.web.form.WidgetButton.extend({ + on_confirmed: function() { + _gaq.push(['_trackEvent', this.view.model, this.node.attrs.name, this.node.attrs.string]); + return this._super.apply(this, arguments); + }, + }); + }; \ No newline at end of file -- cgit v1.2.3 From 9e758119b16eccd783030d13ea7300f29db54e6f Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Fri, 26 Oct 2012 16:02:39 +0200 Subject: [IMP] Improved tracking code. bzr revid: vta@openerp.com-20121026140239-22pb87v79y015uy0 --- addons/web_analytics/__openerp__.py | 2 +- .../web_analytics/static/src/js/web_analytics.js | 138 ++++++++++++++------- 2 files changed, 96 insertions(+), 44 deletions(-) (limited to 'addons/web_analytics') diff --git a/addons/web_analytics/__openerp__.py b/addons/web_analytics/__openerp__.py index 2fa95c7398b..66ec959ac7b 100644 --- a/addons/web_analytics/__openerp__.py +++ b/addons/web_analytics/__openerp__.py @@ -31,7 +31,7 @@ Collects web application usage with Google Analytics. """, 'author': 'OpenERP SA', 'website': 'http://openerp.com', - 'depends': ['web'], + 'depends': ['web', 'auth_signup'], 'data': [], 'installable': True, 'active': False, diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index e9f83780a2d..e76488e4b45 100644 --- a/addons/web_analytics/static/src/js/web_analytics.js +++ b/addons/web_analytics/static/src/js/web_analytics.js @@ -4,32 +4,29 @@ 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 a virtual url each time the - * openerp url is changed. Google needs a virtual url because it cannot - * handle sharps in the url. At this time the virtual url only handles the - * model and view parameters and is of the form /web_analytics/redirect/MODEL/VIEW - * - * The pushes of the virtual urls is made by adding a callback to the + * 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() { + var ga = document.createElement('script'); + ga.type = 'text/javascript'; + ga.async = true + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; + s.parentNode.insertBefore(ga,s); + })(); + if (instance.webclient) { - // _gaq.push(['_setAccount', 'UA-25293939-2']); // fva@openerp.com localhost - // _gaq.push(['_setAccount', 'UA-28648768-1']); // fva@openerp.com runbot - // _gaq.push(['_setAccount', 'UA-28648768-1']); // fva@openerp.com - // _gaq.push(['_setAccount', 'UA-7333765-1']); // fp@openerp.com - // _gaq.push(['_setAccount', 'UA-7333765-1']); // fp@openerp.com - // _gaq.push(['_setDomainName', '.openerp.com']); + // Set the account and domain to start tracking _gaq.push(['_setAccount', 'UA-35793871-1']); // vta@openerp.com localhost - _gaq.push(['_setDomainName', 'none']); - _gaq.push(['_trackPageview']); - _gaq.push(['_deleteCustomVar', 1]); - _gaq.push(['_deleteCustomVar', 2]); - _gaq.push(['_deleteCustomVar', 3]); - _gaq.push(['_deleteCustomVar', 4]); - _gaq.push(['_deleteCustomVar', 5]); + _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]); @@ -40,43 +37,98 @@ openerp.web_analytics = function(instance) { _gaq.push(['_setCustomVar', 1, 'User Type', 'Admin User', 1]); } - // Google Analytics Code snippet - (function() { - var ga = document.createElement('script'); - ga.type = 'text/javascript'; - ga.async = true - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; - s.parentNode.insertBefore(ga,s); - })(); + // 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 self = this; instance.webclient.on('state_pushed', self, function(state) { - var url = '/' + window.location.hash; - _gaq.push(['_trackPageview', url]); - var model = state["model"] || "no_model"; - var view_type = state["view_type"] || "default"; - _gaq.push(['_setCustomVar', 2, 'Object', model, 3]); - _gaq.push(['_setCustomVar', 3, 'View Type', view_type, 3]); + // 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.parseUrl({'model': state.model, 'view_type': state.view_type}); + _gaq.push(['_trackPageview', url]); + } }); } + // Track the events related with the creation and the modification of records instance.web.FormView = instance.web.FormView.extend({ - save: function(prepend_on_create) { - if (!this.datarecord.id) { - _gaq.push(['_trackEvent', this.model, 'on_button_save', 'Save']); + 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.parseUrl({'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.parseUrl({'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) { + var url = instance.web_analytics.parseUrl({'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 { - _gaq.push(['_trackEvent', this.model, 'on_button_edit', 'Save']); + action = action_data.string || action_data.special || ''; } + var label = instance.web_analytics.parseUrl({'model': category, 'view_type': this.view_type}); + _gaq.push(['_trackEvent', category, action, label]); return this._super.apply(this, arguments); - } + }, }); - instance.web.form.WidgetButton = instance.web.form.WidgetButton.extend({ - on_confirmed: function() { - _gaq.push(['_trackEvent', this.view.model, this.node.attrs.name, this.node.attrs.string]); - return this._super.apply(this, arguments); + // Track error events + instance.web.CrashManager = instance.web.CrashManager.extend({ + 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.parseUrl(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); }, }); + instance.web_analytics.parseUrl = function(options) { + var url = ''; + _.each(options, function(value, key) { + url += '/' + key + '=' + value; + }); + return url; + }; + }; \ No newline at end of file -- cgit v1.2.3 From f6885da5af11bef8926cb05bbac10b05fe12288c Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 8 Nov 2012 13:23:43 +0100 Subject: [REM] Remove unused files. bzr revid: vta@openerp.com-20121108122343-7lfzcntwugdc1qxw --- addons/web_analytics/controllers/__init__.py | 3 --- addons/web_analytics/controllers/main.py | 34 ---------------------------- 2 files changed, 37 deletions(-) delete mode 100644 addons/web_analytics/controllers/__init__.py delete mode 100644 addons/web_analytics/controllers/main.py (limited to 'addons/web_analytics') diff --git a/addons/web_analytics/controllers/__init__.py b/addons/web_analytics/controllers/__init__.py deleted file mode 100644 index 9f828025b8e..00000000000 --- a/addons/web_analytics/controllers/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -import main - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/web_analytics/controllers/main.py b/addons/web_analytics/controllers/main.py deleted file mode 100644 index 82c42efecb0..00000000000 --- a/addons/web_analytics/controllers/main.py +++ /dev/null @@ -1,34 +0,0 @@ -import json -import textwrap - -import simplejson -import werkzeug.wrappers - -import web.common.http as openerpweb -import web.controllers.main - -class web_analytics(openerpweb.Controller): - - # This controllers redirects virtual urls of the form /web_analytics/MODEL/VIEW - # as provided to google by the analytics modules to a real url that openerp can - # understand of the form /#model=MODEL&view_type=VIEW - # So that the user can click openerp urls inside google analytics. - - _cp_path = "/web_analytics" - - @openerpweb.httprequest - def redirect(self, req): - url = req.httprequest.base_url - suburl = url.split('/') - suburl = suburl[suburl.index('redirect')+1:] - - rurl = "/#" - if len(suburl) >=1 and suburl[0]: - rurl += "model="+str(suburl[0]) - if len(suburl) >=2 and suburl[1]: - rurl += "&view_type="+str(suburl[1]) - - redirect = werkzeug.utils.redirect(rurl, 303) - - return redirect - -- cgit v1.2.3 From 0f1c30142b35795d2cfdf6bbae9f6cffde99116b Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Thu, 8 Nov 2012 13:24:45 +0100 Subject: [FIX] Changed the account. bzr revid: vta@openerp.com-20121108122445-i2hb6428b9gxhrqu --- addons/web_analytics/static/src/js/web_analytics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_analytics') diff --git a/addons/web_analytics/static/src/js/web_analytics.js b/addons/web_analytics/static/src/js/web_analytics.js index e76488e4b45..0de8e9e087b 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) { if (instance.webclient) { // Set the account and domain to start tracking - _gaq.push(['_setAccount', 'UA-35793871-1']); // vta@openerp.com localhost + _gaq.push(['_setAccount', 'UA-7333765-1']); // vta@openerp.com localhost _gaq.push(['_setDomainName', 'none']); // Change for the real domain // Track user types -- cgit v1.2.3