[IMP] Improved tracking code.
bzr revid: vta@openerp.com-20121026140239-22pb87v79y015uy0
This commit is contained in:
parent
21b916349a
commit
9e758119b1
|
@ -31,7 +31,7 @@ Collects web application usage with Google Analytics.
|
||||||
""",
|
""",
|
||||||
'author': 'OpenERP SA',
|
'author': 'OpenERP SA',
|
||||||
'website': 'http://openerp.com',
|
'website': 'http://openerp.com',
|
||||||
'depends': ['web'],
|
'depends': ['web', 'auth_signup'],
|
||||||
'data': [],
|
'data': [],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'active': False,
|
'active': False,
|
||||||
|
|
|
@ -4,32 +4,29 @@ var _gaq = _gaq || []; // asynchronous stack used by google analytics
|
||||||
openerp.web_analytics = function(instance) {
|
openerp.web_analytics = function(instance) {
|
||||||
|
|
||||||
/** The Google Analytics Module inserts the Google Analytics JS Snippet
|
/** 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
|
* at the top of the page, and sends to google an url each time the
|
||||||
* openerp url is changed. Google needs a virtual url because it cannot
|
* openerp url is changed.
|
||||||
* handle sharps in the url. At this time the virtual url only handles the
|
* The pushes of the urls is made by triggering the 'state_pushed' event in 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
|
* 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) {
|
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(['_setAccount', 'UA-35793871-1']); // vta@openerp.com localhost
|
||||||
_gaq.push(['_setDomainName', 'none']);
|
_gaq.push(['_setDomainName', 'none']); // Change for the real domain
|
||||||
_gaq.push(['_trackPageview']);
|
|
||||||
_gaq.push(['_deleteCustomVar', 1]);
|
|
||||||
_gaq.push(['_deleteCustomVar', 2]);
|
|
||||||
_gaq.push(['_deleteCustomVar', 3]);
|
|
||||||
_gaq.push(['_deleteCustomVar', 4]);
|
|
||||||
_gaq.push(['_deleteCustomVar', 5]);
|
|
||||||
|
|
||||||
|
// Track user types
|
||||||
if (instance.session.uid !== 1) {
|
if (instance.session.uid !== 1) {
|
||||||
if ((/\.demo.openerp.com/).test(instance.session.server)) {
|
if ((/\.demo.openerp.com/).test(instance.session.server)) {
|
||||||
_gaq.push(['_setCustomVar', 1, 'User Type', 'Demo User', 1]);
|
_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]);
|
_gaq.push(['_setCustomVar', 1, 'User Type', 'Admin User', 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Google Analytics Code snippet
|
// Track object usage
|
||||||
(function() {
|
_gaq.push(['_setCustomVar', 2, 'Object', 'no_model', 3]);
|
||||||
var ga = document.createElement('script');
|
// Tack view usage
|
||||||
ga.type = 'text/javascript';
|
_gaq.push(['_setCustomVar', 3, 'View Type', 'default', 3]);
|
||||||
ga.async = true
|
|
||||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
_gaq.push(['_trackPageview']);
|
||||||
var s = document.getElementsByTagName('script')[0];
|
|
||||||
s.parentNode.insertBefore(ga,s);
|
|
||||||
})();
|
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
instance.webclient.on('state_pushed', self, function(state) {
|
instance.webclient.on('state_pushed', self, function(state) {
|
||||||
var url = '/' + window.location.hash;
|
// Track only pages corresponding to a 'normal' view of OpenERP, views
|
||||||
_gaq.push(['_trackPageview', url]);
|
// related to client actions are tracked by the action manager
|
||||||
var model = state["model"] || "no_model";
|
if (state.model && state.view_type) {
|
||||||
var view_type = state["view_type"] || "default";
|
// Track object usage
|
||||||
_gaq.push(['_setCustomVar', 2, 'Object', model, 3]);
|
_gaq.push(['_setCustomVar', 2, 'Object', state.model, 3]);
|
||||||
_gaq.push(['_setCustomVar', 3, 'View Type', view_type, 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({
|
instance.web.FormView = instance.web.FormView.extend({
|
||||||
save: function(prepend_on_create) {
|
init: function(parent, dataset, view_id, options) {
|
||||||
if (!this.datarecord.id) {
|
this._super.apply(this, arguments);
|
||||||
_gaq.push(['_trackEvent', this.model, 'on_button_save', 'Save']);
|
var self = this;
|
||||||
} else {
|
this.on('record_created', self, function(r) {
|
||||||
_gaq.push(['_trackEvent', this.model, 'on_button_edit', 'Save']);
|
var url = instance.web_analytics.parseUrl({'model': this.model, 'view_type': 'form'});
|
||||||
}
|
_gaq.push(['_trackEvent', this.model, 'on_button_create_save', url]);
|
||||||
return this._super.apply(this, arguments);
|
});
|
||||||
|
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]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.form.WidgetButton = instance.web.form.WidgetButton.extend({
|
// Track client actions
|
||||||
on_confirmed: function() {
|
instance.web.ActionManager.include({
|
||||||
_gaq.push(['_trackEvent', this.view.model, this.node.attrs.name, this.node.attrs.string]);
|
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);
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue