[ADD] Added basic skel.

bzr revid: vta@openerp.com-20121023101509-5hyjjanz89pj1qbh
This commit is contained in:
vta vta@openerp.com
2012-10-23 12:15:09 +02:00
parent a53941b165
commit 4f16b71910
6 changed files with 126 additions and 0 deletions
View File
+41
View File
@@ -0,0 +1,41 @@
# -*- 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'],
'icon': '/web_analytics/static/src/img/icon128.png',
'data': [],
'installable': True,
'active': False,
'js': ['static/src/js/web_analytics.js'],
}
@@ -0,0 +1,3 @@
import main
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+32
View File
@@ -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
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

@@ -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]);
});
}
};