Skip to main content

MailerLite Integration

Knowledge > Integrations > MailerLite

What it is / why we use it

MailerLite is the email marketing platform for all ChurchWiseAI properties. As of April 2026, MailerLite handles lead nurture only — newsletter signups, guide downloaders, PewSearch claimants, and cross-property leads. Paying customers (premium_churches) are handled entirely by the code-based Lifecycle Email System (churchwiseai-web/src/lib/lifecycle-emails.ts + Resend + Vercel cron).

MailerLite's current role (leads only):

  • Newsletter subscriber management (signup forms, groups, segmentation)
  • Lead nurture sequences for non-customers (newsletter welcome, cross-property cross-promo)
  • Congregation Care broadcasts (via the CareTab in PewSearch admin dashboard)
  • Manual campaigns (one-off announcements sent from MailerLite UI)

NOT handled by MailerLite (moved to code system):

  • Customer onboarding sequences
  • Win-back sequences for cancelled churches
  • CWA → ShareWise cross-promo (sent via Resend cron at day 7)

All three codebases (churchwiseai-web, pewsearch, sermon-illustrations) share a single MailerLite account. Only churchwiseai-web holds the live API key; PewSearch and ITW proxy through a CWA endpoint so the key never spreads across repos. All calls are fire-and-forget — MailerLite is treated as downstream of Supabase, so API failures never break user-facing flows.

Account Info

  • Platform: MailerLite (connect.mailerlite.com)
  • Account owner: churchwiseai@gmail.com (same Google account as Stripe)
  • API key location: MAILERLITE_API_KEY env var in churchwiseai-web only
  • Agent access: Agents have full REST API access. Never send the founder to the MailerLite dashboard; call the API directly.

How Used Per Product

ProductPurpose
ChurchWiseAISubscriber sync on trial start, checkout completion, cancellation; newsletter signups; demo booking confirmation
SermonWiseUsers synced to sermonwise-users group; Pro subscribers to sermonwise-pro
ShareWiseAIComing Soon signups synced to sharewise-users; paid subscribers to sharewise-paid
PewSearchPremium page subscribers synced via proxy; claims/leads captured to pewsearch-claims
IllustrateTheWordNewsletter subscribers synced via proxy to itw-subscribers; paid to itw-premium
Cross-propertyministry-digest group covers subscribers who opted into the shared pastoral newsletter

Subscriber Lifecycle — When Subscribers Are Synced

Subscribers are added or updated at these trigger points:

  1. Onboard form submission (/api/onboard) — user added to cwa-trial group with subscription_status: active and source_property: churchwiseai
  2. Stripe checkout.session.completed — user moved to cwa-customers group with plan and channel fields set
  3. Stripe subscription cancelled — user moved to cwa-cancelled group
  4. Newsletter/signup forms — all three properties POST to the proxy or the CWA /api/mailerlite/subscribe endpoint with a tag field that maps to a group ID
  5. PewSearch lead capture (/api/leads/capture) — fire-and-forget proxy call to CWA
  6. ITW newsletter (/api/newsletter) — same proxy pattern

Key Groups (from mailerlite-groups.ts)

Groups are populated at setup time via /api/mailerlite/setup. Names follow the kebab-case pattern property-segment:

  • cwa-newsletter, cwa-customers, cwa-trial, cwa-demo-booked, cwa-starter-kit, cwa-cancelled
  • sermonwise-users, sermonwise-pro
  • sharewise-users, sharewise-paid
  • pewsearch-premium, pewsearch-claims
  • itw-subscribers, itw-premium
  • ministry-digest

Custom Subscriber Fields

The following custom fields are created in MailerLite (all text type):

church_name, church_id, plan, channel, subscription_status, source_property, denomination, city, state, signup_date, products_used

Key Environment Variables

VariableUsed InPurpose
MAILERLITE_API_KEYchurchwiseai-webBearer token for all direct API calls
MAILERLITE_PROXY_SECRETAll three codebasesShared secret verifying proxy requests (x-ml-proxy-key header)
MAILERLITE_PROXY_URLpewsearch, ITWFull URL to CWA's /api/mailerlite/subscribe endpoint
MAILERLITE_WEBHOOK_SECRETchurchwiseai-webHMAC-SHA256 secret for verifying inbound MailerLite webhook events

CLI / API Patterns & Gotchas

Proxy endpoint auth: PewSearch and ITW POST to MAILERLITE_PROXY_URL with:

x-ml-proxy-key: <MAILERLITE_PROXY_SECRET>
Content-Type: application/json

{ "email": "...", "name": "...", "source": "pewsearch", "tag": "church_recommendations" }

The proxy maps tag to a group ID via tagToGroup() in mailerlite-groups.ts. If the tag has no mapping, the subscriber syncs without group assignment (not an error).

Upsert semantics: POST /subscribers on the MailerLite API is a true upsert — safe to call on every checkout or signup. No need to check whether a subscriber already exists.

Group IDs are hardcoded constants: Group IDs live in mailerlite-groups.ts as ML_GROUPS. They were populated once by the setup endpoint. If you need to add a new group, run POST /api/mailerlite/setup after adding the definition to ML_GROUP_DEFINITIONS, then commit the new ID to mailerlite-groups.ts.

Rate limit on proxy: The subscribe proxy enforces 5 requests per minute per IP via rate-limit.ts. This is intentional to prevent abuse; batch imports should be done via direct API or MailerLite dashboard import.

Dev mode / missing key: If MAILERLITE_API_KEY is not set, all functions in mailerlite.ts silently return without calling the API. This enables local development without a key. No error is thrown.

API base URL: https://connect.mailerlite.com/api (not the older api.mailerlite.com)

Failure Modes & Recovery

FailureBehaviorRecovery
MAILERLITE_API_KEY not setSilent no-op in all mailerlite.ts functionsSet the env var; subscribers already in Supabase, re-sync when needed
MAILERLITE_PROXY_SECRET mismatchProxy returns 401 to PewSearch/ITWVerify secret matches across all three .env files
Webhook signature invalidWebhook returns 401; bounce/unsub event not processedCheck MAILERLITE_WEBHOOK_SECRET matches the MailerLite webhook config
Group ID missing/wrongSubscriber synced without group assignmentRerun /api/mailerlite/setup to recreate groups; update ML_GROUPS constants
MailerLite API 429 / outageConsole error logged; user flow unaffected (fire-and-forget)Retry manually via API or dashboard bulk import from Supabase export
email_subscribers table out of syncBounce/unsub events not reflectedRe-trigger webhook delivery from MailerLite dashboard

Webhook events handled:

  • subscriber.bounced → updates email_subscribers.status = 'bounced'
  • subscriber.unsubscribed → updates email_subscribers.status = 'unsubscribed'

Cost Model / Usage Limits

  • Free tier: Up to 1,000 subscribers and 12,000 emails/month
  • Paid tiers: Scale by subscriber count; expect to upgrade when total subscribers across all groups exceeds 1,000
  • Automations: Available on paid plans. As of March 2026 no paid automations are active; groups are used for segmentation and manual campaign targeting.
  • API rate limits: MailerLite enforces per-minute limits (undocumented but observed around 60 req/min). The proxy's 5 req/min IP limit is well within this.

MailerLite Automations — Status (April 2026)

9 automations exist. 5 are disabled. The split: MailerLite handles leads (non-customers), the Lifecycle Email System handles customers (premium_churches).

#AutomationStatusTrigger GroupNotes
1CWA Newsletter Welcome SequenceACTIVEcwa-newsletterPrimary lead nurture. Keep. Newsletter signups + guide downloads. 54% open rate.
2Cross-Promo: PewSearch → CWAACTIVEpewsearch-claimsPewSearch claimants → CWA. Keep.
3Cross-Promo: ITW → SermonWiseACTIVEitw-subscribersITW leads → SermonWise. Keep. 0 sends so far.
4Cross-Promo: SermonWise → ITWACTIVEsermonwise-usersSermonWise leads → ITW. Keep. 0 sends so far.
5Cross-Promo: CWA → ShareWise⚠️ ACTIVE — CONFLICTcwa-customers5 in queue. Lifecycle cron also sends crosspromo_cwa_share. DISABLE before launch.
6Win-Back: Cancelled Customers⚠️ ACTIVE — CONFLICTcwa-cancelled0 sends. Lifecycle cron also sends winback. DISABLE before launch.
77-Day AI Ministry CourseDISABLED (Apr 2026)cwa-newsletterIncomplete, double-fired with Newsletter Welcome. Content in lifecycle-emails.ts as course_day1-7 (not yet wired to cron).
8CWA Starter Kit Buyer NurtureDISABLED (Apr 2026)cwa-starter-kitDecember-launch content, 0 sends ever. Needs rewrite before re-enabling.
9CWA Trial NurtureDISABLEDcwa-trialDisabled. Trial churches covered by lifecycle cron onboarding sequence.

Two pending actions before launch:

  • Disable automation #5 (CWA → ShareWise) — conflicts with lifecycle cron
  • Disable automation #6 (Win-Back) — conflicts with lifecycle cron

Lifecycle Email System — Relationship to MailerLite

The lifecycle system (churchwiseai-web/src/lib/lifecycle-emails.ts) sends all timed/triggered emails via Resend (not MailerLite). MailerLite remains the subscriber CRM — subscriber data flows TO MailerLite for segmentation, but emails flow FROM Resend. Architecture doc: knowledge/architecture/lifecycle-email-system.md.

What MailerLite still does:

  • Stores subscriber groups for segmentation (agents and campaigns reference these groups)
  • Receives subscriber sync events (checkout, cancellation, signup) for CRM purposes
  • Handles Care broadcasts (sent via MailerLite's campaign API from the CareTab)
  • Manages unsubscribe/bounce events (webhook → Supabase email_subscribers)

What MailerLite no longer does (moved to lifecycle cron + Resend):

  • Customer onboarding emails (premium_churches — handled by lifecycle cron)
  • Win-back emails for cancelled customers (handled by lifecycle cron)
  • CWA → ShareWise cross-promo for paying customers (handled by lifecycle cron at day 7)
  • Trial nurture (disabled — lifecycle cron onboarding covers trial churches)

Marketing Opt-In Compliance (CAN-SPAM / GDPR)

All properties must collect explicit marketing consent before syncing subscribers to MailerLite.

Implementation Pattern

The CWA onboard form (churchwiseai-web/src/app/onboard/components/OnboardForm.tsx) is the reference implementation:

  1. CAN-SPAM countries (US, CA): checkbox pre-checked by default
  2. GDPR countries (all others): checkbox unchecked, requires explicit opt-in
  3. Country detection: Timezone-based (Intl.DateTimeFormat().resolvedOptions().timeZone)
  4. Storage: premium_churches.marketing_opt_in column (boolean)
  5. Gate: MailerLite sync only fires when marketing_opt_in is true

Per-Property Compliance Status

PropertyFormOpt-In CheckboxGDPR LogicMailerLite Gate
ChurchWiseAI Onboard/onboardYesYes (timezone)Yes (marketing_opt_in)
PewSearch Claim (paid)/claim/[slug]ClaimForm.tsxYesYes (timezone)Yes (stored in premium_churches)
PewSearch Free ClaimPastorLeadCapture.tsx/api/leads/captureYesYes (timezone)Yes (marketing_opt_in !== false)
PewSearch NewsletterEmailCapture.tsx/api/subscribeImplicit (subscribe = consent)NoNo gate (implicit consent)
ITW Signup/signupYes (newsletter checkbox)No GDPR logicConditional on checkbox
ITW Footer NewsletterFooterNewsletter/api/newsletterImplicitNoNo gate

Rules for Agents

  • NEVER sync to MailerLite without checking opt-in status for claim/signup flows
  • Newsletter signups are implicit consent (subscribing IS the consent action) — no additional gate needed
  • When adding new signup forms, always include the marketing opt-in checkbox with timezone-based GDPR default
  • Transactional emails (welcome, payment failed, trial ending) do NOT require marketing consent — they go through Resend directly

See Also

  • Resend Integration — transactional email (magic links, welcome emails); complementary to MailerLite
  • Stripe Integration — checkout events trigger MailerLite subscriber sync
  • Lifecycle Email System — the code-based replacement for all MailerLite automations
  • churchwiseai-web/src/lib/mailerlite.ts — API wrapper
  • churchwiseai-web/src/lib/mailerlite-groups.ts — group ID constants and tag→group mapping
  • churchwiseai-web/src/lib/lifecycle-emails.ts — lifecycle sequence engine + templates