summaryrefslogtreecommitdiff
path: root/addons/web_analytics
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2012-11-09 14:36:23 +0100
committerOlivier Dony <odo@openerp.com>2012-11-09 14:36:23 +0100
commitd47d5f202d8da18fac46dee9a9be6613d1ef8e2f (patch)
tree703be521b4ca935d0e4375fc3e88b34558b282a3 /addons/web_analytics
parentc9d5148991db5beccedc802ce56efb3689dd1527 (diff)
parentc5961309c424173953a67d873c79135a97856759 (diff)
[MERGE] Sync with trunk
bzr revid: odo@openerp.com-20121109133623-pvgt4b9koun74ib3
Diffstat (limited to 'addons/web_analytics')
-rw-r--r--addons/web_analytics/__init__.py0
-rw-r--r--addons/web_analytics/__openerp__.py40
-rw-r--r--addons/web_analytics/static/src/img/icon.pngbin0 -> 11486 bytes
-rw-r--r--addons/web_analytics/static/src/js/web_analytics.js134
4 files changed, 174 insertions, 0 deletions
diff --git a/addons/web_analytics/__init__.py b/addons/web_analytics/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/addons/web_analytics/__init__.py
diff --git a/addons/web_analytics/__openerp__.py b/addons/web_analytics/__openerp__.py
new file mode 100644
index 00000000000..66ec959ac7b
--- /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. (<http://openerp.com>).
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{
+ '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', 'auth_signup'],
+ 'data': [],
+ 'installable': True,
+ 'active': False,
+ 'js': ['static/src/js/web_analytics.js'],
+}
+
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
--- /dev/null
+++ b/addons/web_analytics/static/src/img/icon.png
Binary files 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..0de8e9e087b
--- /dev/null
+++ b/addons/web_analytics/static/src/js/web_analytics.js
@@ -0,0 +1,134 @@
+
+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
+ */
+
+ // 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) {
+
+ // Set the account and domain to start tracking
+ _gaq.push(['_setAccount', 'UA-7333765-1']); // vta@openerp.com localhost
+ _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 {
+ _gaq.push(['_setCustomVar', 1, 'User Type', 'Admin 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 self = this;
+ instance.webclient.on('state_pushed', self, 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.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({
+ 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 {
+ 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);
+ },
+ });
+
+ // 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