Files
odoo_source/addons/utm/models/ir_http.py
T
Jeremy Kersten a89af09120 [FIX] http_routing, utm, website: set expiration date on some cookies
The 'frontend_lang' cookie is used to 'cache' the user's preferred lang.
We want to make sure that this language preference is preserved for a
longer period of time than just the life of the browser. This means that
even if you quit your browser and come back into the year, your
preferred language will be used, until you choose to remove your cookies.

The 'utm_*' cookies are used to 'track' where you are coming from on the
instance. The purpose of these cookies is to know the tracking value
to improve the overall user experience or compute the profitability of
some campaigns. Now we keep these cookies for 1 month.

closes odoo/odoo#122573

X-original-commit: 058e0abcf621796bf23d8dcaaf3b2297f632b5fd
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Jérémy Kersten <jke@odoo.com>
2023-05-30 13:03:25 +02:00

27 lines
980 B
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.http import request, Response
class IrHttp(models.AbstractModel):
_inherit = 'ir.http'
@classmethod
def get_utm_domain_cookies(cls):
return request.httprequest.host
@classmethod
def _set_utm(cls, response):
# Make sure response is an odoo Response.
response = Response.load(response)
domain = cls.get_utm_domain_cookies()
for url_parameter, __, cookie_name in request.env['utm.mixin'].tracking_fields():
if url_parameter in request.params and request.httprequest.cookies.get(cookie_name) != request.params[url_parameter]:
response.set_cookie(cookie_name, request.params[url_parameter], max_age=31 * 24 * 3600, domain=domain, cookie_type='optional')
@classmethod
def _post_dispatch(cls, response):
cls._set_utm(response)
super()._post_dispatch(response)