diff --git a/addons/saas_analytics/__init__.py b/addons/saas_analytics/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/addons/saas_analytics/__openerp__.py b/addons/saas_analytics/__openerp__.py new file mode 100644 index 00000000000..d8ee68a2d9d --- /dev/null +++ b/addons/saas_analytics/__openerp__.py @@ -0,0 +1,41 @@ +# -*- 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'], + 'icon': '/web_analytics/static/src/img/icon128.png', + 'data': [], + 'installable': True, + 'active': False, + 'js': ['static/src/js/web_analytics.js'], +} + diff --git a/addons/saas_analytics/controllers/__init__.py b/addons/saas_analytics/controllers/__init__.py new file mode 100644 index 00000000000..9f828025b8e --- /dev/null +++ b/addons/saas_analytics/controllers/__init__.py @@ -0,0 +1,3 @@ +import main + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/saas_analytics/controllers/main.py b/addons/saas_analytics/controllers/main.py new file mode 100644 index 00000000000..81ca3417255 --- /dev/null +++ b/addons/saas_analytics/controllers/main.py @@ -0,0 +1,32 @@ +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 /web/webclient/home/#model=MODEL&view_type=VIEW + # So that the user can click openerp urls inside google analytics. + + @openerpweb.httprequest + def redirect(self,req): + url = req.httprequest.base_url + suburl = url.split('/') + suburl = suburl[suburl.index('redirect')+1:] + + rurl = "/web/webclient/home/#" + 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/saas_analytics/static/src/img/icon128.png b/addons/saas_analytics/static/src/img/icon128.png new file mode 100644 index 00000000000..320c1f3ec34 Binary files /dev/null and b/addons/saas_analytics/static/src/img/icon128.png differ diff --git a/addons/saas_analytics/static/src/js/web_analytics.js b/addons/saas_analytics/static/src/js/web_analytics.js new file mode 100644 index 00000000000..5ef824ec260 --- /dev/null +++ b/addons/saas_analytics/static/src/js/web_analytics.js @@ -0,0 +1,50 @@ + +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(['_trackPageview']); + + var connection = this.sessions.session0.connection; + _gaq.push(['_setCustomVar',1,'Paying User',String(connection.openerp_entreprise),1]); + _gaq.push(['_setCustomVar',2,'Admin User',String(connection.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); + }) (); + + instance.webclient.do_push_state.add(function(state) { + var model = state["model"] || "no_model"; + var view_type = state["view_type"] || "default"; + var vurl = "web_analytics/redirect/"+ model + "/" + view_type + console.log(vurl); + _gaq.push(['_trackPageview',vurl]); + }); + } +}; +