Template
Add campaign UTM links and piha.li shortener (#4)
## Summary - Port Monica campaign UTM + piha.li minting into always-on `core` (`shortener.py`, `campaign_utm.py`) so `email_sms` and `directmail` stay optional and never import each other. - `utm_source` is a slug of `SITE_NAME` (override with `UTM_SOURCE`). Email gets an HTML `data-campaign-utm` link; SMS gets a plain URL; postcard QR only — no body inject. - Live composer mints through login+CSRF `POST /portal/campaigns/short-link/` (registered only when an outreach app is installed). Empty `SHORTENER_*` falls back to the long UTM URL. Reference: [monica_site PR #10](ai_ml_operations/monica_site#10) Closes #3 ## Test plan - [x] `cd site && uv run python manage.py test` (125 tests) - [ ] Email composer: type a name, confirm HTML link + `utm_campaign` updates, save draft - [ ] SMS composer: plain `piha.li` (or long UTM if shortener unset) in the body - [ ] Postcard composer: QR copies the tracked URL; campaign body has no `utm_source` - [ ] Campaign report pages show the same panel - [ ] With `FEATURE_EMAIL_SMS` and `FEATURE_DIRECT_MAIL` off, no extra nav and no `/portal/campaigns/short-link/` route Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
@@ -17,10 +17,12 @@ from django.views.decorators.http import require_GET, require_http_methods, requ
|
||||
|
||||
from contacts.consent import opted_in_contacts, record_sms_stop
|
||||
from contacts.models import Channel
|
||||
from core.campaign_utm import ensure_campaign_utm_link, utm_panel_context
|
||||
from core.models import StoredFile
|
||||
from core.scheduling import parse_scheduled_for
|
||||
from email_sms.models import Campaign, Message, ProviderEvent
|
||||
from email_sms.services import (
|
||||
channel_for_audience,
|
||||
create_campaign_draft,
|
||||
enqueue_campaign_send,
|
||||
message_is_removable,
|
||||
@@ -291,6 +293,16 @@ def campaign_list(request):
|
||||
form_errors.append("Campaign name is required.")
|
||||
if audience not in Campaign.Audience.values:
|
||||
form_errors.append("Choose a recipient list.")
|
||||
else:
|
||||
channel = channel_for_audience(audience)
|
||||
if channel in (Channel.EMAIL, Channel.SMS):
|
||||
body = ensure_campaign_utm_link(
|
||||
body,
|
||||
name=name or "campaign",
|
||||
medium=channel,
|
||||
html=(channel == Channel.EMAIL),
|
||||
)
|
||||
form_data["body"] = body
|
||||
if not body:
|
||||
form_errors.append("Body is required.")
|
||||
if audience == Campaign.Audience.EMAIL_OPT_IN and not subject:
|
||||
@@ -330,6 +342,7 @@ def campaign_list(request):
|
||||
"form_data": form_data,
|
||||
"form_errors": form_errors,
|
||||
"image_upload_url": reverse("email_sms:campaign_image_upload"),
|
||||
**utm_panel_context(live=True),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -353,6 +366,7 @@ def campaign_detail(request, pk):
|
||||
"recent_events": ctx["recent_events"],
|
||||
"events_title": ctx["events_title"],
|
||||
"events_empty": ctx["events_empty"],
|
||||
**utm_panel_context(campaign=campaign, live=False),
|
||||
"can_send": campaign.status
|
||||
in {
|
||||
Campaign.Status.DRAFT,
|
||||
|
||||
Reference in New Issue
Block a user