Show campaign QR codes for email as well as postcard (#14)
Deploy Beta / unit-tests (push) Successful in 21s
Deploy Beta / docker (push) Successful in 29s
Deploy Beta / deploy-beta (push) Successful in 6m33s

## Summary
Closes #13.
- Draw the tracked-link QR for email campaigns as well as postcard (copy / download PNG).
- Keep the QR hidden for SMS.
- Fix `.utm-qr { display: flex }` overriding the HTML `hidden` attribute so SMS does not leak an empty canvas.

## Test plan
- [ ] Open campaign composer on Email — QR renders for the short `piha.li` URL
- [ ] Copy QR image / Download PNG work
- [ ] Switch to SMS — QR box is gone
- [ ] Switch to Postcard — QR still renders; postcard-designer hint still shows
- [ ] Email campaign report page also shows a filled QR

Reviewed-on: #14
This commit was merged in pull request #14.
This commit is contained in:
2026-09-01 11:51:57 -07:00
parent bc7c47a69c
commit a867a57750
4 changed files with 22 additions and 3 deletions
@@ -13,6 +13,7 @@
Auto-added to the email as a styled link. Updates as you type the campaign name.
<code>utm_medium=email</code> · <code>utm_campaign</code> matches the name.
Recipients tap a short <code>piha.li</code> link that redirects to this URL.
QR below encodes the same short link.
</p>
<p class="hint" data-utm-sms-hint hidden>
SMS is plain text — phones cannot show HTML links. A short <code>piha.li</code>
@@ -31,7 +32,10 @@
<div class="utm-qr-actions">
<button type="button" class="btn btn-ghost btn-sm" data-utm-copy-qr>Copy QR image</button>
<button type="button" class="btn btn-ghost btn-sm" data-utm-download-qr>Download PNG</button>
<p class="hint" style="margin-top:8px">
<p class="hint" style="margin-top:8px" data-utm-qr-email-hint hidden>
Copy or download the PNG for print, signatures, or other materials.
</p>
<p class="hint" style="margin-top:8px" data-utm-qr-postcard-hint hidden>
Paste or upload the PNG in
<a href="{% url 'messaging:postcard_designer' %}">Postcard design</a>.
</p>
+5
View File
@@ -1554,6 +1554,8 @@ class CampaignUtmLinkTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Tracked site link")
self.assertContains(response, "campaign-utm.js")
self.assertContains(response, "qrcode.min.js")
self.assertContains(response, "data-utm-qr")
self.assertContains(response, "utm_campaign")
self.assertContains(response, reverse("messaging:campaign_short_link"))
@@ -1573,6 +1575,9 @@ class CampaignUtmLinkTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertContains(response, "utm_campaign=spring-seller-tips")
self.assertContains(response, "utm_medium=email")
self.assertContains(response, "qrcode.min.js")
self.assertContains(response, "data-utm-qr")
self.assertContains(response, "QR below encodes the same short link")
def test_sms_replaces_existing_short_url(self):
from messaging.services import ensure_campaign_utm_in_text
+3
View File
@@ -718,6 +718,9 @@ body.portal {
flex-wrap: wrap;
margin-top: 12px;
}
.utm-qr[hidden] {
display: none !important;
}
.utm-qr canvas {
display: block;
border: 1px solid var(--monica-border);
+9 -2
View File
@@ -181,12 +181,19 @@
function paint(url, inject) {
var ch = medium();
var showQr = ch === "email" || ch === "postcard";
if (urlEl) urlEl.textContent = url;
if (qrWrap) qrWrap.hidden = ch !== "postcard";
if (qrWrap) qrWrap.hidden = !showQr;
if (smsHint) smsHint.hidden = ch !== "sms";
if (emailHint) emailHint.hidden = ch !== "email";
if (postcardHint) postcardHint.hidden = ch !== "postcard";
if (ch === "postcard" && canvas) {
panel.querySelectorAll("[data-utm-qr-email-hint]").forEach(function (el) {
el.hidden = ch !== "email";
});
panel.querySelectorAll("[data-utm-qr-postcard-hint]").forEach(function (el) {
el.hidden = ch !== "postcard";
});
if (showQr && canvas) {
renderQr(canvas, url).catch(function () {});
}
if (inject && typeof opts.onUrlChange === "function") {