contenir-extension / campaign-monitor
The Campaign Monitor add-on for Contenir CMS: keeps a Campaign Monitor list in step with the site's sign-ups and records, through an outbox, and hears back about unsubscribes and bounces.
Package info
github.com/contenir-extension/campaign-monitor
Type:contenir-extension
pkg:composer/contenir-extension/campaign-monitor
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
- contenir/contenir-audience: ^0.1
- contenir/contenir-extension-api: ^0.7.5 || ^0.8 || ^0.9
- guzzlehttp/guzzle: ^7.9
- php-db/phpdb: ^0.6.0
- psr/clock: ^1.0
- psr/container: ^1.1 || ^2.0
- psr/http-client: ^1.0.3
- psr/http-factory: ^1.1
- psr/http-message: ^1.1 || ^2.0
- psr/log: ^3.0.2
Requires (Dev)
- contenir/contenir-qa-tools: 0.1.x-dev
- infection/infection: ^0.34.1
- nyholm/psr7: ^1.8.2
- php-db/phpdb-sqlite: 0.3.x-dev
- phpunit/phpunit: ^11.5.42
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-19 09:05:05 UTC
README
Keeps a Campaign Monitor client's lists in step with a site's sign-ups and CMS records, through contenir/contenir-audience's outbox, and hears back about unsubscribes, bounces and deletions through a webhook. A sign-up or a save only writes a row in the site's database; the CMS's job runner sends it within the minute, so a slow or failing Campaign Monitor never slows a page or a save.
Setting it up
-
Enable the add-on. Its tables are created at the next sign-in, in the site's database, under
ext_campaign_monitor_. -
Write the add-on's config file.
config/autoload/extensions/campaign-monitor.global.phpholds the bindings, andcampaign-monitor.local.php, never committed, the pepper the email hashes are made with. Until there is one, the setup check's one-click Fix writes a fresh one intocampaign-monitor.local.php. It never replaces one already set: a new pepper would forget everyone who unsubscribed. A Mezzio site that signs people up through contenir-audience-mezzio reads the same two files, so it uses the same pepper. Another environment that syncs the same lists needs the same pepper copied to its owncampaign-monitor.local.php.The pepper is a secret mixed into the hashes of the addresses kept for people who unsubscribed, bounced or complained, so the database never holds a readable list of them.
return ['extensions' => ['campaign-monitor' => ['bindings' => [ 'newsletter' => [ 'list' => 'a1b2c3…', 'fields' => ['Name' => 'name'], 'consent' => 'Signing up to the newsletter', 'options' => ['consent_to_track' => 'Yes'], ], 'members' => [ 'list' => 'd4e5f6…', 'source' => 'library.members.member', 'consent' => 'Members who tick Newsletter', 'options' => ['consent_field' => 'newsletter'], ], ]]]];
-
In Site Settings > Integration > Campaign Monitor, enter the API key. The Client list fills from it as soon as you leave the field, or says beside the field that Campaign Monitor refused the key. Choose the client, save, and press Test connection. Later, leave the API key empty to keep the saved one, as the CMS does for any password field, and change the client.
-
For a section binding, bind the listeners in the section's
admin.xml:<events> <listen extension="campaign-monitor" listener="sync-record" event="RecordPostSave"/> <listen extension="campaign-monitor" listener="remove-record" event="RecordPostDelete"/> </events>
-
Press Re-register webhooks. It makes the webhook's secret the first time, and registers each binding's list at
/api/extension/campaign-monitor/eventson the site's own address (site.url), so the site's web server must send/api/extension/to the CMS'sadmin.php, past any Basic Auth.
What it adds
| Extension point | What |
|---|---|
| Settings section | Integration > Campaign Monitor: the API key (masked, in local settings), the client, chosen from those the key reaches, and the webhook's secret (masked). Buttons: Test connection, Sync all now, Re-register webhooks. |
| Field type and script | client: the client's ID, which public/js/client-field.js shows as a list of the clients the API key reaches, filled as the key is typed. Without the script it is a text field for the 32-character ID. |
| Endpoint | clients, at /admin/extension/campaign-monitor/clients, for editors who may update it: a GET answering the clients a key reaches as JSON. The key comes in the X-Campaign-Monitor-Key header, never the address; without one, the saved key is asked. A refused key answers 422 with Campaign Monitor's reason. |
| Listeners | sync-record on RecordPostSave and remove-record on RecordPostDelete, run as the record is saved, since writing a row is quick. |
| Schedule | drain, every minute: sends what's due for up to 40 seconds, then deletes sent messages after 7 days and failed ones after 30. |
| Webhook | events, at /api/extension/campaign-monitor/events?binding=<name>&key=<secret>. A call without the secret is refused before anything runs, and a call for another list is refused too (CMN-2). |
| Migrations | The library's outbox, sync state, suppression, consent and webhook tables, under ext_campaign_monitor_, on the site's database. |
| Screens | Sync, at /admin/extension/campaign-monitor/sync: the counts, and the dead, failed and waiting messages with their last error, to retry or remove. Bindings, at /admin/extension/campaign-monitor/bindings: read-only, exactly what each binding sends. |
| Checks | Setup (config file and pepper, with a one-click fix that makes the pepper), connection (with a way to the settings when the key is refused), the outbox (failed and dead messages) and the webhooks (not registered, deleted or switched off at Campaign Monitor). |
What a saved record does
A section binding names the record's consent checkbox with the option consent_field; without one, being in the
section is the consent.
| The save | Queues |
|---|---|
| A new record, or the checkbox just ticked | a subscribe, with the binding's consent wording as fresh consent from the record |
| Any other save while ticked | an update, which reaches only someone already on the list |
| The checkbox just unticked | a removal, as on_delete says |
| A changed address | a removal of the old one, and the new one as fresh consent while ticked |
| A deleted record | a removal, as on_delete says: unsubscribe by default, archive deletes them from the list, keep leaves them |
Someone who unsubscribed, bounced or complained is never subscribed again without fresh consent, or at all after a complaint or deletion.
How it talks to Campaign Monitor
- Connecting: an API key over HTTP Basic, and the client whose lists are kept. An agency's
key reaches every client it manages;
clients()lists them. - Joining: imports of up to 1,000 people, without autoresponders. Only people who agreed
afresh are sent with
Resubscribe, so someone who unsubscribed isn't quietly taken back. Whether they confirm by email first is the list's own setting. - Updating, unsubscribing and archiving: one request per person. Archiving deletes them, which Campaign Monitor can undo; someone not on the list is already off it.
- Consent to track:
Nounless a field mapped toConsentToTrackor the binding'sconsent_to_trackoption says yes. It is never sent asUnchanged. - Outcomes: a suppressed or deleted address (codes 204 and 205) is never retried. A 429 or
5xx, or a request that never arrived, is tried again after Campaign Monitor's
Retry-Afterwhen it gives one. A 401 or 403 stops the run. - Webhook: registered for
DeactivateandUpdateevents as JSON. Campaign Monitor doesn't sign its calls, so the add-on keeps a secret in the webhook's address, and each call must be for the binding's list. Unsubscribed, bounced and deleted people, and changed addresses, are passed to the shared rules; anything else is passed over.
Testing
Every request is tested against Campaign Monitor's documented replies, including refused keys, rate limits and partial imports, so the suite never calls the real service.
composer check