Communication

Campaigns

Lists people sign up to, also without an account, and campaigns to their subscribers and to users by email, SMS and push, with link and open tracking and one-click unsubscribe.

Campaigns gives your app lists that people sign up to with an email address, a phone number or both: the readers of your news, the volunteers of an event, the members of a club. They do not need an account. A new subscriber confirms from a link in an email or SMS (double opt-in), and the subscription stores the proof of their consent. Every message carries a signed link to unsubscribe again. Signed-in users manage their subscriptions on their account page, and staff manage the lists in the admin area. A list can also be offered on the registration form, or take every new account on its own.

Staff send campaigns: to the subscribers of one or more lists (email and SMS), or to users picked by role, team, operation or by name (email, SMS and push). Campaigns go out in batches from a scheduled task, now or at a set time. Links in them are counted per recipient through Short Links, opens optionally, and every email carries one-click unsubscribe headers.

The package is @frigear-nu/campaigns. Every message goes through Notify, on the email, SMS and push drivers your app sets. Campaigns ships no SMS provider of its own.

What you get

  • Signup: the global <ListSignup list="…"> component, also usable as ::list-signup{list="…"} in Nuxt Content, and a plain HTML form for other sites, shown on each list's staff page.
  • Registration form: the lists offered at sign-up as unticked boxes, in Auth's auth.register widget area (with Widget). See Lists and accounts.
  • Public pages:
    • /subscriptions/confirm, where the link in the confirmation message leads. It confirms on a button, never when the page opens, so link scanners and mail previews confirm nothing. After a plain HTML form signup it says "check your inbox".
    • /subscriptions/unsubscribe, where the unsubscribe link leads. It also acts on a button only.
  • Account page: /account/subscriptions, the signed-in user's subscriptions, with an item in the account menu when Menu is installed.
  • Admin area (needs Admin):
    • /admin/campaigns, the campaigns, and /admin/campaigns/:id, one campaign. See Staff screens.
    • /admin/campaigns/lists, the lists with their subscriber counts.
    • /admin/campaigns/lists/:id, one list: its settings (with the sign-up mode and, with Forms, the form that signs people up), its subscribers, "Add all current accounts" on a list that adds new accounts, and the signup code to copy.
    • A "Campaigns" item in the Manage group of the admin sidebar, when Menu is installed. Tabs under the heading switch between campaigns and lists.
  • Email templates campaigns-confirm and campaigns-message, when Email Templates is installed.
  • Notification topic campaigns.message on the account's notifications page (with Preferences): email and push on, SMS off until the user turns it on.
  • Tasks campaigns:deliver (every minute) and campaigns:retention (nightly), also on Cloudflare cron triggers.
  • Campaign API for staff: drafts, a preview of who they reach, send, schedule, cancel, stats and deliveries.
  • Managed campaigns: other modules (an event, an operation, a team) own messages to their people, timed from their dates or sent when something happens, from a Messages tab on their page (see Managed campaigns).
ServerClientMobile
Installed for you: Auth, Users, Notify, Short Links, UI and Module Kit. You add:NuxtHub with a database and KV (the signup's rate limit). Optional:
  • Admin and Menu: the staff pages and the menu items.
  • Email Templates: the confirmation email from its template.
  • Forms: the captcha of the signup, and signing people up from a form's submissions.
  • Widget: the lists offered on the registration form.
  • Preferences: users' choices for campaigns.message, and turning it off from a message's unsubscribe link.
  • SMS: the number a campaign's texts go out from (see From number).

Quick setup

Install Campaigns

pnpm add @frigear-nu/campaigns

Add it to nuxt.config.ts

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxthub/core', '@frigear-nu/users', '@frigear-nu/admin', '@frigear-nu/campaigns'],
  hub: { db: 'sqlite', kv: true },
})

Unsubscribe links are signed with a key derived from Nuxt's appSecret. Set it in production, as your sessions need it too:

.env
NUXT_APP_SECRET=a-long-random-string-of-at-least-32-characters

Generate and commit a migration

Campaigns adds seven tables (and Short Links two). Generate a migration and commit it.

npx nuxt db generate

Create a list and put its signup on a page

Open /admin/campaigns/lists as an admin and create a list. Then add its signup to a page:

app/pages/news.vue
<template>
  <ListSignup list="news" />
</template>
What you should see: a signup sends a confirmation email. Its link opens /subscriptions/confirm, and after the click the subscriber shows up as subscribed on the list's staff page.

Options

Options go under the campaigns key.

OptionTypeDefaultPurpose
rateLimitnumber10Signups per IP address and list in the window. 0 turns the limit off.
rateLimitWindowSecondsnumber600The window of the rate limit.
confirmTtlHoursnumber72How long a confirmation link works.
resendAfterSecondsnumber300A new signup for an address that is still waiting to confirm sends the confirmation again only after this pause.
corsOriginsstring[][]Other sites allowed to post to the subscribe route from the browser. A plain HTML form needs none. Env NUXT_CAMPAIGNS_CORS_ORIGINS (a JSON array).
captchafalse | 'turnstile' | 'recaptcha' | 'hcaptcha'falseA captcha the subscribe route checks. It needs Forms, whose site and secret keys it uses.
signingKeystringfrom appSecretThe key unsubscribe links, delivery tokens and IP hashes are signed with. Env NUXT_CAMPAIGNS_SIGNING_KEY. Without it and without appSecret, signups answer 501 not_configured.
batchSizenumber200Messages the deliver task sends per run. Env NUXT_CAMPAIGNS_BATCH_SIZE.
deliverCronstring | false* * * * *When campaigns:deliver runs. false registers the task without a schedule (run it yourself).
retentionDaysnumber | false180Days the per-recipient rows of a finished campaign are kept; its counts stay. false keeps them and schedules no retention task. Env NUXT_CAMPAIGNS_RETENTION_DAYS.
settings.pages.confirmstring | boolean/subscriptions/confirmThe confirm page. If you turn it off, serve your own page at the same path: confirmation links point there.
settings.pages.unsubscribestring | boolean/subscriptions/unsubscribeThe unsubscribe page.
settings.pages.accountstring | boolean/account/subscriptionsThe signed-in user's subscriptions.
settings.pages.adminListsstring | boolean/admin/campaigns/listsThe staff page of the lists (with Admin).
settings.pages.adminListstring | boolean/admin/campaigns/lists/:idOne list's staff page. It must contain :id.
settings.pages.adminCampaignsstring | boolean/admin/campaignsThe staff list of campaigns (with Admin).
settings.pages.adminCampaignstring | boolean/admin/campaigns/:idOne campaign's staff page. It must contain :id.

Permissions

Campaigns registers these permissions with Authorization.

NameWho holds itWhat it covers
campaigns:manageadminLists and their subscribers without addresses; campaign drafts, previews and stats.
campaigns:sendadminSending, scheduling and cancelling campaigns.
campaigns:send-importantadminCreating and sending an important message, which reaches users on channels they turned off.
campaigns:piiadmin (sensitive)Subscribers' email addresses and phone numbers, searching by them, and a campaign's deliveries. Never covered by campaigns:*.
campaigns:subscriptionsEvery signed-in user (implicit)The user's own subscriptions. Also a token scope, through the subscriptions scope.

The signup, confirm, unsubscribe and open-pixel routes are anonymous. The rate limit, the optional captcha and the tokens in the messages guard them.

How signing up works

  • One answer for every address. The subscribe route answers { confirm } whether the address was known or not, subscribed or not, so it never tells anyone who is on a list. A subscriber who signs up again gets no email.
  • Contacts. A contact is one email address and/or one phone number, unique each. An anonymous signup never changes an existing contact. When a signed-in user's email address is verified, the contact with that address is linked to them.
  • Double opt-in. With the list's "Ask new subscribers to confirm" on (the default), a new subscription is pending until the link in the confirmation email or SMS is followed and confirmed. Without it, it is active at once. A signed-in user who turns on a list from the account page with a verified address is active at once.
  • Consent proof. Each subscription stores where the consent came from (form, api, admin, forms or account), the version of the consent text the person agreed to, when they asked, when they confirmed and a keyed hash of their IP address. Changing a list's consent text starts a new version.
  • Unsubscribe links are <subscription id>.<signature>, an HMAC-SHA-256 under the signing key. Nothing is stored per link, so every message to a subscriber can carry one. Unsubscribing clears a confirmation that is still waiting.
  • The account page turns the email channel on or off. An SMS subscription can be turned off there; signing up for SMS goes through the signup, which confirms the phone number.
  • A honeypot. The signup sends a hidden website field. When it is filled in, the route answers as usual and stores nothing.

Lists and accounts

Each list has a sign-up mode, "New accounts" on its staff page (signupMode):

ModeWhat happens when someone creates an account
Off (off, the default)Nothing.
Offer at sign-up (offer)A public list shows on the registration form as an unticked box with its consent text. Only people who tick it are added.
Add new accounts automatically (auto)Every new account is added without being asked. Only for lists that are not marketing, such as practical updates for members: staff answer for having a reason to send them.
  • How. Auth fires auth:user:created for every new account (registration form, sign-in link, OAuth, frigear.nu, passkey, or staff creating it). Campaigns then adds the account's email address to every auto list, and to the offer lists ticked on the registration form. The form's widget sends the ticked ids as extras.campaigns.listIds; ids of lists that are not offered are ignored, and a failure never stops the sign-up.
  • Consent. The subscription's source is account, with the list's current consent version. With the list's double opt-in and an address that is not verified yet, the subscription waits for the confirmation email like any signup; otherwise it is active at once.
  • Email only. Accounts are added on the email channel, with the address they signed up with.
  • Unsubscribing works the same as for anyone, and someone who unsubscribed from a list is never added to it again.
  • Add all current accounts. An auto list's staff page adds every existing account that is not on the list yet, after a confirm with how many that is. Nobody who unsubscribed before is added back, and on a list with double opt-in only accounts with a verified address are added: nobody gets a confirmation email from it. The subscriptions are active, with the source admin.

Signups from a form

With Forms installed, a list's staff page can pick a form and which of its fields hold the consent checkbox, the email address, the phone number and the name. A submission of that form with the consent ticked signs the person up the way the signup does: consent source forms, the confirmation email or SMS when the list asks for it, and nothing said about whether the address was known. Without a ticked consent, or without a valid email address or international phone number, a submission signs nobody up.

Campaigns

A campaign goes to lists (kind: 'lists') or to people (kind: 'people'). Staff write it as a draft, check who it reaches with the preview, then send it now or schedule it.

To lists (lists)To people (people)
AudiencelistIds: the active subscribers of these lists, each contact once per channelgrants and/or userIds: the members of each grant (role, team, operation) and these users, each once
Channelsemail, smsemail, sms, push
Who decidesThe subscription: only active ones get it, checked again right before each sendThe user's choices for campaigns.message; an important campaign ignores them
UnsubscribeFrom every list of the campaign, on that channelTurns the channel off for campaigns.message
  • Content is per channel and per language: email: { subject, body }, sms: { body, from }, push: { title, body, url }. from is only used with SMS. The email body is markdown (bold, italics, links, paragraphs), rendered and escaped on the server. Each recipient gets their own language (the contact's or user's), then the campaign's locale, then English.
  • The audience of a campaign to people is resolved when it is sent or scheduled (a managed one's when it starts). public and signed-in grants are refused, and an audience that names nobody is 400 audience_not_resolved. The lists of a campaign to lists are read when it goes out; sending one now to lists nobody is on is 400 audience_not_resolved too.
  • Delivery. Sending makes the campaign scheduled; the campaigns:deliver task starts it (sending), adds one delivery row per recipient and channel in pages (resumable), and sends batchSize of them per run. A run claims rows with an update guarded by their status, so two runs never send the same row. A claim older than ten minutes is tried again, up to three times. "Send now" also starts one run right after the answer. When every row is done the campaign is sent and its counts are kept on it. Addresses are never copied into the rows: they are read when each message goes out.
  • Links with trackClicks (on by default): each distinct http(s) link becomes a short link owned by the campaign, and each recipient's message points at /l/<code>/<delivery token>. A click redirects to the link and counts on the delivery (clickedAt, clicks) and per link. Anchors, paths, mailto: and tel: links stay as written.
  • Opens with trackOpens (off by default): the email carries a 1x1 image from /api/campaigns/o/<token>; the first load marks the delivery opened. Mail apps that load images on their own count as an open too.
  • Unsubscribe. The delivery token is the delivery id signed like a subscription token. Every email has List-Unsubscribe: <…/api/campaigns/unsubscribe/<token>> and List-Unsubscribe-Post: List-Unsubscribe=One-Click, so mail apps show their own unsubscribe button, and a footer with the unsubscribe page and the subscriptions (or notification settings) page. An SMS ends with the unsubscribe page.
  • Skipped rows say why: disabled (the user turned the channel off), unavailable (no address, phone or device), unsubscribed (the subscriber left before their turn) or cancelled.
  • Retention. campaigns:retention deletes the delivery and click rows of campaigns finished more than retentionDays ago; the counts per channel stay on the campaign. Clicks per link are counted from those rows, so they go with them.

From number

With SMS installed, the editor's SMS section has a From select: "Automatic", then the numbers SMS can send from now (GET /api/admin/sms/send-numbers, which needs sms:send-numbers; staff without it see no select, and the campaign keeps its number). The choice is stored as content.sms.from (a number id), and each text goes to Notify's SMS driver with this meta:

MetaValue
fromcontent.sms.from; left out for automatic.
sourcecampaigns, shown as "Sent by" in SMS's message log.
refThe delivery id (cmd_…).
topiccampaigns.message, on a campaign to people.

A message to people that follows the users' choices goes out through notifyUser with the same meta. SMS sends from that number and moves on to another when it cannot send (a number that is gone or turned off is skipped). Without SMS there is no select and the meta stays { campaigns: { campaignId, deliveryId } }.

Managed campaigns

A module can own campaigns: an event, an operation or a team messages its own people from a "Messages" tab on its staff page, without importing campaigns. Its messages go to people through their relationship with it (holding a ticket, being on the team), and they turn them off per owner type ("Event messages"), not per list. A managed campaign is a people campaign with an owner (ownerType, ownerId), a notify topic of its own and a trigger. It is edited only through its owner; the campaigns admin lists it read-only, with a "Managed by" badge linking to the owner.

Declare an owner

At build time, push a definition in the campaigns:owners Nuxt hook. Campaigns calls it once every module is set up, so the owner module hooks it whether or not campaigns is installed, and a host can add its own presets to it.

module.ts
nuxt.hook('campaigns:owners', (owners) => {
  owners.push({
    type: 'event',
    label: { en: 'Event', da: 'Arrangement' },
    // Registered with notify: people turn these messages off per channel on their notifications page.
    topic: { key: 'events.message', label: { en: 'Event messages', da: 'Beskeder om arrangementer' } },
    // Manages the event's messages; checked with the record `campaigns:owner:resolve` gives.
    permission: 'events:manage',
    // The Messages tab goes on this `WidgetTabs` area; the page passes the record under `contextKey`.
    tabArea: 'admin.events',
    contextKey: 'event',
    anchors: [{ key: 'startsAt', label: 'Starts' }],
    triggers: [{ key: 'ticket.paid', label: 'Ticket paid' }],
    // `{id}` stands for the owner's id.
    audiences: [{ key: 'holders', label: 'Ticket holders', grants: [{ kind: 'event', eventId: '{id}', status: 'paid' }] }],
    variables: [
      { key: 'name', label: 'Name' },
      { key: 'startsAt', label: 'Starts', type: 'date' },
      { key: 'url', label: 'Page', type: 'url' },
    ],
    presets: [{
      key: 'reminder',
      label: 'Reminder 1 day before',
      name: 'Reminder',
      audience: 'holders',
      trigger: { type: 'relative', anchor: 'startsAt', offsetMinutes: -1440 },
      content: { email: { subject: 'Tomorrow: {{event.name}}', body: 'See you at {{event.startsAt}}.' } },
    }],
  })
})
FieldWhat it is
typeStored on the campaigns and used in variables ({{event.name}}). Lower case letters, digits and -.
topicThe notify topic its messages follow (key, label, description, defaults: email and push on, SMS off unless set). Unsubscribing from one of its messages turns that channel off for this topic only.
permissionWho manages the owner's messages. They need no campaigns permission.
tabArea, contextKey, tabOrderWhere the Messages tab goes (with Widget and Admin installed), and the context key holding the record whose id is the owner id.
anchorsDates a message can be timed from.
triggersHappenings that send a message to the people they happen to.
audiencesGrant lists (@frigear-nu/auth) the messages can go to. Staff pick one by key; they never edit the grants.
variablesValues for {{<type>.<key>}}: text, date (written in each recipient's language) or url (tracked like any link). {{recipient.name}} is always there.
presetsReady-made messages the "Add message" menu offers.

Answer for your records

At run time, answer the campaigns:owner:resolve Nitro hook for your type. Campaigns calls it to name the owner, to time relative messages, to fill the variables and to check its permission with record.

server/plugins/campaigns-owner.ts
export default defineNitroPlugin((nitro) => {
  nitro.hooks.hook('campaigns:owner:resolve', async (ctx) => {
    if (ctx.type !== 'event') return
    const event = await findEvent(ctx.id)
    if (!event) return
    ctx.owner = {
      name: event.name,
      url: `/admin/events/${event.id}`,
      anchors: { startsAt: event.startsAt },
      variables: { name: event.name, startsAt: event.startsAt, url: eventPublicUrl(event) },
      // `false` holds its relative messages (an unpublished event).
      live: event.status === 'published',
      timeZone: 'Europe/Copenhagen',
      record: event,
    }
  })
})

Then tell campaigns what happens to your records, from your own hooks:

CallWhen
campaignsOwnerChanged(type, id)The record changed (a date, whether it is live). Its relative messages that have not gone out are timed again.
campaignsOwnerRemoved(type, id)The record is deleted or archived. Waiting messages are cancelled, armed ones paused.
campaignsTrigger(type, id, key, { userIds })key happened to these users (a ticket was paid). Each armed message on key goes to each of them once.

Grant kinds used in audiences are resolved by the campaigns:deliver task, outside a request: their members get a system event (grantsSystemEvent() of auth), so they must not read the session or headers.

Triggers

TriggerWhat happens
{ type: 'manual' }Sent now or at a date, like any campaign.
{ type: 'relative', anchor, offsetMinutes, ifLate }Turned on, it is scheduled at the anchor plus the offset (negative is before) and follows the date when the owner changes. A time already passed holds it (held) instead of sending it late, unless ifLate: 'send'; so does an owner that is not live. Staff send a held message now, or cancel it.
{ type: 'event', key }Turned on, it is active (armed): each campaignsTrigger adds a delivery per channel for the people named, and the unique key per campaign, channel and user sends it to each person once. It can be paused and resumed, and it collects its stats on one row.

The audience of a managed message is read when it starts, not when it is turned on: people who joined since get it. Before a relative message starts, campaigns asks the owner once more, so a moved date or an owner gone off-line holds it, and a deleted owner cancels it.

Variables

Texts can use the owner's variables and {{recipient.name}}. In the email body, text values are inserted after the markdown is rendered and HTML-escaped, so a name never becomes a link or markup; url values are inserted as written, so they become links and are tracked. A variable the owner does not have is a 400 validation_failed on save and send.

Access

The owner's routes check its permission before anything is loaded, then with the owner's record. The campaign routes (GET, preview, stats, send, schedule, cancel, activate, pause, resume) take campaigns:manage or campaigns:send as before, or, for a managed campaign, its owner's permission. An important message still needs campaigns:send-important, and who it went to (deliveries) still needs campaigns:pii. The general PATCH and DELETE answer 409 campaign_managed for a managed campaign.

Staff screens

The campaign pages need Admin. They sit under one "Campaigns" item of the admin sidebar, with tabs to the lists.

  • /admin/campaigns lists the campaigns, newest first, with their status, kind, channels, audience, when they went (or go) out and how many were sent, opened and clicked. Past eight campaigns a toolbar searches by name and filters by status and kind. Each row has a menu: Open, Edit campaign, Duplicate, Cancel campaign and Delete campaign, as far as the campaign's status and your permissions allow.
  • Create campaign opens a form: the kind (to lists or to people, fixed once created), the channels, the audience (lists to send to, or people and groups such as roles, teams and operations), the texts per channel and language, and whether to count clicks (on by default) and opens (off by default). A draft may be unfinished; the texts of one channel go together.
  • /admin/campaigns/:id shows one campaign: what keeps a draft from being sent, a summary, the audience with how many it reaches now per channel, the content per channel and language (the email rendered as recipients read it, without its footer), and once it goes out the results: counts, skipped rows by reason, clicks per link and, with campaigns:pii, the recipients.
  • Send campaign first counts who it reaches and asks you to confirm with those numbers. Schedule campaign asks for a date and time in your own time zone. A scheduled or sending campaign can be cancelled.
  • Messages tab on an owner's page (tabArea of its definition), for holders of the owner's permission: its messages in Upcoming (drafts, dated and relative ones, held ones flagged), Automatic (on a happening) and Sent, each with its trigger, audience, status and sent count. Add message starts a blank draft or one of the owner's presets; the form picks one of its audiences, when it goes out (by hand, before or after one of its dates, or when something happens), the texts with the owner's variables, and tracking. A row's menu turns a message on, sends a held one now, pauses, resumes, cancels or deletes it. In /admin/campaigns a managed campaign is read-only, with a "Managed by" badge linking to its owner, and an owner filter.
ActionNeedsOnly when
See campaigns, their audience, content and resultscampaigns:manage
Create, edit, duplicate and deletecampaigns:manageEdit and delete: a draft
Send now, schedulecampaigns:sendA draft with nothing missing
Cancelcampaigns:sendScheduled or sending
Make a campaign to people important, or edit, send or duplicate an important onecampaigns:send-important as well
See the recipients of each deliverycampaigns:piiOnce it went out

The pages hide what you may not do; the routes check again.

The signup component

<ListSignup list="news" />
<ListSignup list="news" title="Get our news" description="Once a month, no more." />
<ListSignup list="news" :title="false" />
PropTypePurpose
liststringThe list's URL name. Required.
titlestring | falseReplaces the list's name as the heading; false shows none.
descriptionstringReplaces the list's description.

It asks for a name, an email address and a phone number (the channels the list has), shows the consent text next to the checkbox and posts in the visitor's locale, which the confirmation message uses. With the captcha option it shows the captcha widget of Forms.

In a Nuxt Content page:

::list-signup{list="news"}
::

Another site. Each list's staff page has a plain HTML <form> to paste into a site that cannot run the component. It posts to the subscribe route, which redirects the visitor to /subscriptions/confirm to check their inbox. A site that posts with JavaScript instead needs its origin in corsOrigins.

Routes

Path builders come from @frigear-nu/campaigns/api (campaignsApi).

RouteWhoWhat
GET /api/campaigns/lists/:slugAnyoneA public list as the signup shows it. A list that is not public is a 404.
POST /api/campaigns/lists/:slug/subscribeAnyone (rate limited){ email?, phone?, name?, locale?, channels?, consent, captcha? }, as JSON or a plain form. Answers { confirm }; a plain form post gets a 303 to the confirm page. 429 rate_limited, 400 captcha_required / captcha_failed.
POST /api/campaigns/confirm/:tokenThe tokenConfirms the subscription. 400 invalid_token (unknown or used), 410 token_expired.
POST /api/campaigns/unsubscribe/:tokenThe tokenUnsubscribes what the token names: a subscription, or a campaign message's lists (answers like a subscription) or the channel of its topic, campaigns.message or a managed message's owner topic (answers { topic, channel, status }). The RFC 8058 one-click target: the body is not read. 400 invalid_token.
GET /api/campaigns/o/:tokenThe tokenThe 1x1 GIF of a campaign email; marks it opened with trackOpens. The same image for any token.
GET /api/campaigns/signup/listsAnyoneThe lists the registration form offers: [{ id, slug, name, description, consentText }].
GET, PATCH /api/campaigns/me/subscriptionscampaigns:subscriptionsThe user's subscriptions; PATCH { lists: { [listId]: { email?, sms? } } } turns channels on (email only) or off.
GET, POST /api/admin/campaigns/listscampaigns:manageEvery list with its counts; creates one. 409 conflict for a URL name in use.
GET, PATCH, DELETE /api/admin/campaigns/lists/:idcampaigns:manageOne list. Deleting it deletes its subscriptions.
GET /api/admin/campaigns/lists/:id/subscriberscampaigns:managePaginated subscriptions, ?status&channel&q&sort&order. Addresses with campaigns:pii.
GET, POST /api/admin/campaigns/lists/:id/accountscampaigns:manage"Add all current accounts" of an auto list: GET answers { accounts } (how many it would add), POST adds them and answers { added }. 409 signup_mode for another list.
GET /api/admin/campaigns/formscampaigns:manageWith Forms: the forms that are not archived, with the fields a list can map.
GET, POST /api/admin/campaignscampaigns:managePaginated campaigns, ?status&kind&owner&q&sort&order (owner: managed, own or an owner type); creates a draft. An important one needs campaigns:send-important.
GET, PATCH, DELETE /api/admin/campaigns/:idcampaigns:manageOne campaign. Only a draft changes or is deleted: 409 not_draft; a managed one only through its owner: 409 campaign_managed.
GET /api/admin/campaigns/:id/previewcampaigns:manage{ recipients, channels }: who it reaches now, per channel. For a campaign to people, the most it can reach.
POST /api/admin/campaigns/:id/sendcampaigns:sendSends a draft (or a held managed message) now. 400 validation_failed (not ready) or audience_not_resolved, 409 not_draft, 409 trigger_not_manual for a managed draft that goes out on its own.
POST /api/admin/campaigns/:id/schedulecampaigns:send{ scheduledAt } in the future.
POST /api/admin/campaigns/:id/cancelcampaigns:sendStops a scheduled or sending campaign; unsent rows are skipped. 409 not_cancellable.
GET /api/admin/campaigns/:id/statscampaigns:manageCounts per channel (total, queued, sent, skipped, failed, opened, clicked, clicks), skipReasons (skipped rows by reason, while the rows are kept) and clicks per link.
GET /api/admin/campaigns/:id/deliveriescampaigns:manage and campaigns:piiPaginated deliveries with their recipient, ?status&channel&sort&order.
POST /api/admin/campaigns/:id/activatecampaigns:send or the owner's permissionTurns on a managed draft by its trigger: scheduled or held (relative), active (on a happening). 409 trigger_manual, not_draft.
POST /api/admin/campaigns/:id/pause, .../resumecampaigns:send or the owner's permissionPauses or resumes an armed message. 409 not_active, not_paused.
GET, POST /api/admin/campaigns/owners/:type/:id/campaignsThe owner's permission{ owner, campaigns }: the owner (name, staff URL, live, anchors) and its messages; creates a draft { name, audience, trigger, channels, content, ... }, audience being the key of one of its audiences.
PATCH, DELETE /api/admin/campaigns/owners/:type/:id/campaigns/:campaignIdThe owner's permissionOne draft message of the owner. 409 not_draft.
GET /api/admin/campaigns/userscampaigns:managePeople for the form of a campaign to people: ?q= searches names (at most 20), ?ids=1,2 names the people a draft lists. With campaigns:pii the search matches emails too and the answer carries them.

Sending and scheduling an important message needs campaigns:send-important as well.

Database

Tables the module adds. Generate and commit a migration after installing.

TableWhat it holds
campaign_listsid (cml_), slug (unique), name, description, channels, doubleOptIn, public, signupMode (off, offer, auto), consentText, consentVersion, formId and formFields (a forms form that signs people up).
campaign_contactsid (cmc_), email (lower-cased, unique), phone (E.164, unique), userId, name, locale.
campaign_subscriptionsid (cms_), listId, contactId, channel (unique together), status (pending, active, unsubscribed), confirmTokenHash (SHA-256 of the confirmation token), confirmExpiresAt, source, consentVersion, requestedAt, confirmedAt, ipHash, unsubscribedAt.
campaignsid (cmp_), kind, name, channels, audience, content, locale, trackClicks, trackOpens, important, status (draft, scheduled, held, active, paused, sending, sent, cancelled), ownerType and ownerId (a managed campaign's owner), topic (the notify topic of a message to people), trigger, scheduledAt, startedAt, materializedAt and materializeCursor (delivery rows added so far), finishedAt, cancelledAt, recipientUserIds (a message's resolved audience), origin (the site links point at), createdBy, sentBy, counts.
campaign_linksid (cmk_), campaignId, shortLinkId (a short_links row owned by campaigns and the campaign), url, position.
campaign_deliveriesid (cmd_), campaignId, channel, userId or contactId (+ subscriptionId), status (queued, sending, sent, skipped, failed), skipReason, attempts, claimId, claimedAt, sentAt, openedAt, clickedAt, clicks, error. No address.
campaign_clicksdeliveryId, linkId, at: one row per counted click, for clicks per link.

Translations

Override any string in your app's i18n/locales/<code>.json, under the campaigns key. Campaigns ships Danish and English, and so do the confirmation email and SMS and the footers of campaign messages.

Next steps

  • Notify – the email and SMS drivers the messages go out through.
  • Email Templates – override the campaigns-confirm and campaigns-message emails.
  • Short Links – the links in campaign messages.
  • Forms – the captcha keys the signup uses, and forms that sign people up.
  • Auth – the registration form's widget area and auth:user:created.
Copyright © 2026