[IMP] Refactor event tracking
bzr revid: vta@openerp.com-20130108094850-452xq5vbfnnoipz5
This commit is contained in:
parent
fd7680daa7
commit
2743be5862
|
@ -87,8 +87,12 @@ openerp.web_analytics = function(instance) {
|
||||||
// related to client actions are tracked by the action manager
|
// related to client actions are tracked by the action manager
|
||||||
if (state.model && state.view_type) {
|
if (state.model && state.view_type) {
|
||||||
// Track the page
|
// Track the page
|
||||||
var label = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type});
|
var url = instance.web_analytics.generateUrl({'model': state.model, 'view_type': state.view_type});
|
||||||
_gaq.push(['_trackEvent', state.model, state.view_type, label]);
|
this._push_event({
|
||||||
|
'category': state.model,
|
||||||
|
'action': state.view_type,
|
||||||
|
'label': url,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
|
@ -96,6 +100,7 @@ openerp.web_analytics = function(instance) {
|
||||||
* by other modules in order to extend tracking functionalities
|
* by other modules in order to extend tracking functionalities
|
||||||
*/
|
*/
|
||||||
include_tracker: function() {
|
include_tracker: function() {
|
||||||
|
var t = this;
|
||||||
// Track the events related with the creation and the modification of records,
|
// Track the events related with the creation and the modification of records,
|
||||||
// the view type is always form
|
// the view type is always form
|
||||||
instance.web.FormView.include({
|
instance.web.FormView.include({
|
||||||
|
@ -103,12 +108,20 @@ openerp.web_analytics = function(instance) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
var self = this;
|
var self = this;
|
||||||
this.on('record_created', self, function(r) {
|
this.on('record_created', self, function(r) {
|
||||||
var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'});
|
var url = instance.web_analytics.generateUrl({'model': r.model, 'view_type': 'form'});
|
||||||
_gaq.push(['_trackEvent', this.model, 'on_button_create_save', url]);
|
t._push_event({
|
||||||
|
'category': r.model,
|
||||||
|
'action': 'form',
|
||||||
|
'label': url,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
this.on('record_saved', self, function(r) {
|
this.on('record_saved', self, function(r) {
|
||||||
var url = instance.web_analytics.generateUrl({'model': this.model, 'view_type': 'form'});
|
var url = instance.web_analytics.generateUrl({'model': r.model, 'view_type': 'form'});
|
||||||
_gaq.push(['_trackEvent', this.model, 'on_button_edit_save', url]);
|
t._push_event({
|
||||||
|
'category': r.model,
|
||||||
|
'action': 'form',
|
||||||
|
'label': url,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -116,10 +129,13 @@ openerp.web_analytics = function(instance) {
|
||||||
// Track client actions
|
// Track client actions
|
||||||
instance.web.ActionManager.include({
|
instance.web.ActionManager.include({
|
||||||
ir_actions_client: function (action, options) {
|
ir_actions_client: function (action, options) {
|
||||||
var label = instance.web_analytics.generateUrl({'action': action.tag});
|
var url = instance.web_analytics.generateUrl({'action': action.tag});
|
||||||
var category = action.res_model || action.type;
|
var category = action.res_model || action.type;
|
||||||
var ga_action = action.name || action.tag;
|
t._push_event({
|
||||||
_gaq.push(['_trackEvent', category, ga_action, label]);
|
'category': action.res_model || action.type,
|
||||||
|
'action': action.name || action.tag,
|
||||||
|
'label': url,
|
||||||
|
});
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -134,8 +150,12 @@ openerp.web_analytics = function(instance) {
|
||||||
} else {
|
} else {
|
||||||
action = action_data.string || action_data.special || '';
|
action = action_data.string || action_data.special || '';
|
||||||
}
|
}
|
||||||
var label = instance.web_analytics.generateUrl({'model': category, 'view_type': this.view_type});
|
var url = instance.web_analytics.generateUrl({'model': category, 'view_type': this.view_type});
|
||||||
_gaq.push(['_trackEvent', category, action, label]);
|
t._push_event({
|
||||||
|
'category': category,
|
||||||
|
'action': action,
|
||||||
|
'label': url,
|
||||||
|
});
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -151,26 +171,47 @@ openerp.web_analytics = function(instance) {
|
||||||
} else {
|
} else {
|
||||||
options = {'action': params.action};
|
options = {'action': params.action};
|
||||||
}
|
}
|
||||||
var label = instance.web_analytics.generateUrl(options);
|
var url = instance.web_analytics.generateUrl(options);
|
||||||
if (error.code) {
|
if (error.code) {
|
||||||
_gaq.push(['_trackEvent', error.message, error.data.fault_code, label, ,true]);
|
t._push_event({
|
||||||
|
'category': error.message,
|
||||||
|
'action': error.data.fault_code,
|
||||||
|
'label': url,
|
||||||
|
'value': undefined,
|
||||||
|
'noninteraction': true,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
_gaq.push(['_trackEvent', error.type, error.data.debug, label, ,true]);
|
t._push_event({
|
||||||
|
'category': error.type,
|
||||||
|
'action': error.data.debug,
|
||||||
|
'label': url,
|
||||||
|
'value': undefined,
|
||||||
|
'noninteraction': true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
_push_event: function(options) {
|
||||||
|
_gaq.push(['_trackEvent',
|
||||||
|
options.category,
|
||||||
|
options.action,
|
||||||
|
options.label,
|
||||||
|
options.value,
|
||||||
|
options.noninteraction
|
||||||
|
]);
|
||||||
|
},
|
||||||
_push_ecommerce: function(trans_data, item_list) {
|
_push_ecommerce: function(trans_data, item_list) {
|
||||||
_gaq.push(['_addTrans',
|
_gaq.push(['_addTrans',
|
||||||
trans_data.order_id,
|
trans_data.order_id,
|
||||||
trans_data.store_name,
|
trans_data.store_name,
|
||||||
trans_data.total,
|
trans_data.total,
|
||||||
trans_data.tax,
|
trans_data.tax,
|
||||||
trans_data.shipping,
|
trans_data.shipping,
|
||||||
trans_data.city,
|
trans_data.city,
|
||||||
trans_data.state
|
trans_data.state
|
||||||
trans_data.country,
|
trans_data.country,
|
||||||
]);
|
]);
|
||||||
_.each(item_list, function(item) {
|
_.each(item_list, function(item) {
|
||||||
_gaq.push(['_addItem',
|
_gaq.push(['_addItem',
|
||||||
|
|
Loading…
Reference in New Issue