The
utm.mixin class can be used to track online marketing/communication campaigns through arguments in links to specified resources. The mixin adds 3 fields to your model:campaign_id:Many2onefield to autm.campaignobject (i.e. Christmas_Special, Fall_Collection, etc.)source_id:Many2onefield to autm.sourceobject (i.e. Search Engine, mailing list, etc.)medium_id:Many2onefield to autm.mediumobject (i.e. Snail Mail, e-Mail, social network update, etc.)
These models have a single field
name (i.e. they are simply there to distinguish campaigns but don’t have any specific behaviour).
Once a customer visits your website with these parameters set in the url (i.e. http://www.odoo.com/?campaign_id=mixin_talk&source_id=www.odoo.com&medium_id=website), three cookies are set in the visitor’s website for these parameters. Once a object that inherits the utm.mixin is created from the website (i.e. lead form, job application, etc.), the utm.mixin code kicks in and fetches the values from the cookies to set them in the new record. Once this is done, you can then use the campaign/source/medium fields as any other field when defining reports and views (group by, etc.).
To extend this behaviour, simply add a relational field to a simple model (the model should support the quick create (i.e. call to
create() with a single name value) and extend the function tracking_fields():class UtmMyTrack(models.Model): _name = 'my_module.my_track' _description = 'My Tracking Object' name = fields.Char(string='Name', required=True) class MyModel(models.Models): _name = 'my_module.my_model' _inherit = ['utm.mixin'] _description = 'My Tracked Object' my_field = fields.Many2one('my_module.my_track', 'My Field') @api.model def tracking_fields(self): result = super(MyModel, self).tracking_fields() result.append([ # ("URL_PARAMETER", "FIELD_NAME_MIXIN", "NAME_IN_COOKIES") ('my_field', 'my_field', 'odoo_utm_my_field') ]) return result
This will tell the system to create a cookie named odoo_utm_my_field with the value found in the url parameter
my_field; once a new record of this model is created by a call from a website form, the generic override of the create() method of utm.mixin will fetch the default values for this field from the cookie (and the my_module.my_trackrecord will be creatwed on the fly if it does not exist yet).
You can find concrete examples of integration in the following models:
crm.leadin the CRM (crm) Applicationhr.applicantin the Recruitment Process (hr_recruitment) Applicationhelpdesk.ticketin the Helpdesk (helpdesk - Odoo Enterprise only) Application
No comments:
Post a Comment