Skip to content

T3150 utm refactor#327

Merged
NoeBerdoz merged 2 commits into
14.0from
T3150-utm-refactor
Apr 28, 2026
Merged

T3150 utm refactor#327
NoeBerdoz merged 2 commits into
14.0from
T3150-utm-refactor

Conversation

@NoeBerdoz
Copy link
Copy Markdown
Contributor

@NoeBerdoz NoeBerdoz commented Apr 28, 2026

T3150: Refactor UTM Tracking (and fix WordPress sponsorships)

LINKED TO PR: CompassionCH/compassion-switzerland#1753

Follow-up to T3090 (PR compassion-website #321 and compassion-switzerland #1751.

The Issue

The initial UTM tracking implementation introduced a critical bug:

  • Broken Route: Changing the route converter from <model> to <int> broke our all QR printed slug based link.
  • Reinventing the Wheel: The previous code manually extracted and wrote UTM parameters into the session and records, bypassing Odoo's built-in utm.mixin functionality which already handles all of this natively via cookies.

The Solution (Refactored & Simplified)

This PR removes the redundant code and leans on Odoo's UTM utility.

  • Restored the <model("compassion.child"):child> route: This fixes the WordPress related links. It also ensures backward compatibility, meaning slug-based links and integer-based links will work.
  • Native Odoo UTM Tracking: Removed the custom UTM extraction logic. Added explicit utm.mixin inheritance to recurring.contract. Now, Odoo automatically intercepts UTMs from the URL, stores them in cookies, and maps them to the contract upon creation.
  • Fixed Login Redirection: UTMs and query parameters are no longer lost during the /web/login round-trip.
  • Safe QR Code Generation: (In compassion-switzerland) Refactored the QR URL builder to use urllib.parse.urlencode for safer parameter construction.

Here is how it works:
image

The code has been tested locally on the different possibilities.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors UTM tracking by integrating Odoo's utm.mixin and simplifies the sponsorship controller by removing manual UTM extraction and adopting model converters. However, feedback highlights that utm.mixin in Odoo 14 does not automatically populate fields on creation, which could lead to tracking data loss since the manual extraction logic was removed. Additionally, using request.httprequest.full_path for login redirects is flagged as a risk during AJAX updates, as it could redirect users to a JSON endpoint; a more stable redirect path construction is recommended.

Comment thread my_compassion/models/contracts.py
Comment thread my_compassion/controllers/my2_sponsorships.py
@NoeBerdoz NoeBerdoz merged commit ec66671 into 14.0 Apr 28, 2026
1 check passed
@NoeBerdoz NoeBerdoz deleted the T3150-utm-refactor branch April 28, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant