From c0994d7d1fc1f789658f9ac95dd55eb73e1c2312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cha=C3=AFb=20Martinez?= Date: Wed, 18 Feb 2026 15:40:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(tracking)=20add=20UTM=20parameters=20?= =?UTF-8?q?to=20shared=20document=20links?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add utm_source=docssharelink and utm_campaign={docId} query parameters to shared document links (copy link and invitation emails). Signed-off-by: Chaïb Martinez --- CHANGELOG.md | 1 + src/backend/core/models.py | 2 +- .../core/tests/test_models_documents.py | 27 +++++++++++++++---- .../doc-management/hooks/useCopyDocLink.tsx | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e371d78..6bf16037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to ### Added +- ✨(tracking) add UTM parameters to shared document links - ✨(frontend) Can print a doc #1832 - ✨(backend) manage reconciliation requests for user accounts #1878 - 👷(CI) add GHCR workflow for forked repo testing #1851 diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 7b3a2dc2..5aaaa4a9 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -1260,7 +1260,7 @@ class Document(MP_Node, BaseModel): "brandname": settings.EMAIL_BRAND_NAME, "document": self, "domain": domain, - "link": f"{domain}/docs/{self.id}/", + "link": f"{domain}/docs/{self.id}/?utm_source=docssharelink&utm_campaign={self.id}", "link_label": self.title or str(_("Untitled Document")), "button_label": _("Open"), "logo_img": settings.EMAIL_LOGO_IMG, diff --git a/src/backend/core/tests/test_models_documents.py b/src/backend/core/tests/test_models_documents.py index e5432cdd..0b3ea58a 100644 --- a/src/backend/core/tests/test_models_documents.py +++ b/src/backend/core/tests/test_models_documents.py @@ -1021,7 +1021,10 @@ def test_models_documents__email_invitation__success(): f"Test Sender (sender@example.com) invited you with the role "editor" " f"on the following document: {document.title}" in email_content ) - assert f"docs/{document.id}/" in email_content + assert ( + f"docs/{document.id}/?utm_source=docssharelink&utm_campaign={document.id}" + in email_content + ) @pytest.mark.parametrize( @@ -1051,10 +1054,18 @@ def test_models_documents__email_invitation__url_app_param(email_url_app): # Determine expected domain if email_url_app: - assert f"https://test-example.com/docs/{document.id}/" in email_content + expected_url = ( + f"https://test-example.com/docs/{document.id}/" + f"?utm_source=docssharelink&utm_campaign={document.id}" + ) + assert expected_url in email_content else: # Default Site domain is example.com - assert f"example.com/docs/{document.id}/" in email_content + expected_url = ( + f"example.com/docs/{document.id}/" + f"?utm_source=docssharelink&utm_campaign={document.id}" + ) + assert expected_url in email_content def test_models_documents__email_invitation__success_empty_title(): @@ -1085,7 +1096,10 @@ def test_models_documents__email_invitation__success_empty_title(): "Test Sender (sender@example.com) invited you with the role "editor" " "on the following document: Untitled Document" in email_content ) - assert f"docs/{document.id}/" in email_content + assert ( + f"docs/{document.id}/?utm_source=docssharelink&utm_campaign={document.id}" + in email_content + ) def test_models_documents__email_invitation__success_fr(): @@ -1120,7 +1134,10 @@ def test_models_documents__email_invitation__success_fr(): f"Test Sender2 (sender2@example.com) vous a invité avec le rôle "propriétaire" " f"sur le document suivant : {document.title}" in email_content ) - assert f"docs/{document.id}/" in email_content + assert ( + f"docs/{document.id}/?utm_source=docssharelink&utm_campaign={document.id}" + in email_content + ) @mock.patch( diff --git a/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCopyDocLink.tsx b/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCopyDocLink.tsx index a202a364..4d54c55c 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCopyDocLink.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCopyDocLink.tsx @@ -11,7 +11,7 @@ export const useCopyDocLink = (docId: Doc['id']) => { return useCallback(() => { copyToClipboard( - `${window.location.origin}/docs/${docId}/`, + `${window.location.origin}/docs/${docId}/?utm_source=docssharelink&utm_campaign=${docId}`, t('Link Copied !'), t('Failed to copy link'), );