summaryrefslogtreecommitdiff
path: root/addons/web_analytics/static/src/js/web_analytics.js
diff options
context:
space:
mode:
authorvta vta@openerp.com <>2012-10-23 17:15:49 +0200
committervta vta@openerp.com <>2012-10-23 17:15:49 +0200
commit7d15ab44f439138b18a56a908ba9ca120c993b98 (patch)
tree971c6126955be01e5a7b4240864713fe5fe5078a /addons/web_analytics/static/src/js/web_analytics.js
parent4f16b7191059977cbd19f25c38e8a4029395ea2e (diff)
[FIX] Fixed naming, the account used in ga, and the controller.
bzr revid: vta@openerp.com-20121023151549-atepg5qan70xhmiq
Diffstat (limited to 'addons/web_analytics/static/src/js/web_analytics.js')
-rw-r--r--addons/web_analytics/static/src/js/web_analytics.js56
1 files changed, 56 insertions, 0 deletions
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