(tracking) add UTM parameters to shared document links

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 <chaibax@gmail.com>
This commit is contained in:
Chaïb Martinez
2026-02-18 15:40:16 +01:00
committed by Anthony LC
parent fa0c3847e4
commit c0994d7d1f
4 changed files with 25 additions and 7 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -1021,7 +1021,10 @@ def test_models_documents__email_invitation__success():
f"Test Sender (sender@example.com) invited you with the role &quot;editor&quot; "
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&amp;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&amp;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&amp;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 &quot;editor&quot; "
"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&amp;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 &quot;propriétaire&quot; "
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&amp;utm_campaign={document.id}"
in email_content
)
@mock.patch(

View File

@@ -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'),
);