Skip to content

Fix: Campaign Builder inactivity filter uses wrong date field (FA-19)#4

Open
konard wants to merge 3 commits intoalanef:masterfrom
konard:issue-2-48f469c896ef
Open

Fix: Campaign Builder inactivity filter uses wrong date field (FA-19)#4
konard wants to merge 3 commits intoalanef:masterfrom
konard:issue-2-48f469c896ef

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Jan 5, 2026

Summary

Fixes the Campaign Segment Builder's "No activity in last X days" filter which was incorrectly returning the same subscribers regardless of the number of days specified.

Root cause: The filter was using subscriber_drips.updated_at which tracks when the drip record was last modified (stage changes, etc.), NOT when the subscriber was last emailed.

Solution

Track email sends in SQLite to enable accurate inactivity filtering:

1. New email_sends Table

Added SQLite table to track all email sends:

  • subscriber_id - SQLite subscriber ID
  • email_type - Type: 'drip', 'dunning', or 'campaign'
  • product_id - For drip emails
  • campaign_id - For campaign emails
  • template_id - Listmonk template ID
  • sent_at - Timestamp of send

2. Track Drip/Dunning Sends

Updated DripProcessor and DunningProcessor to log sends to the new table after each successful email send.

3. Track Campaign Sends (via Listmonk Messenger)

Added /api/webhook/messenger endpoint that receives campaign send notifications from Listmonk's messenger system. This allows tracking of all campaign emails sent via this custom messenger.

Setup: Configure a new messenger in Listmonk pointing to https://your-domain/api/webhook/messenger

4. Updated Inactivity Query

Changed the filter in home.php to query the new email_sends table:

NOT EXISTS (
    SELECT 1 FROM email_sends e
    WHERE e.subscriber_id = s.id
      AND e.sent_at >= datetime('now', '-X days')
)

Files Changed

  • shared/src/SequenceDatabase.php - Added email_sends table and methods
  • campaign-list-builder/public/index.php - Added messenger webhook endpoint
  • campaign-list-builder/templates/home.php - Updated inactivity filter SQL
  • drip-controller/src/DripProcessor.php - Log drip sends
  • drip-controller/src/DunningProcessor.php - Log dunning sends

Test Plan

  • Verify email_sends table is created on database initialization
  • Send a drip email and verify it's logged in email_sends
  • Send a dunning email and verify it's logged in email_sends
  • Configure Listmonk messenger and send a campaign, verify sends are logged
  • Test inactivity filter with different day values - should now return different results
  • Verify existing functionality (drip processing, dunning, segment builder) still works

Note on Migration

For existing subscribers who have received emails before this change, the email_sends table will be empty. The inactivity filter will correctly identify them as inactive (no email send records). You may want to backfill data if historical accuracy is important.

Fixes #2

🤖 Generated with Claude Code

konard and others added 2 commits January 5, 2026 23:07
Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: alanef#2
The Campaign Segment Builder's inactivity filter was incorrectly using
subscriber_drips.updated_at which tracks drip stage changes, not actual
email sends.

Changes:
- Add email_sends table to SQLite schema for tracking all email sends
- Add recordEmailSend() and related methods to SequenceDatabase
- Add /api/webhook/messenger endpoint for Listmonk campaign tracking
- Update DripProcessor to log drip sends to email_sends table
- Update DunningProcessor to log dunning sends to email_sends table
- Update buildQuery() in home.php to use email_sends for inactivity filter

The inactivity filter now correctly identifies subscribers who haven't
received ANY email (drip, dunning, or campaign) in the specified period.

Fixes alanef#2

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] Fix: Campaign Builder inactivity filter uses wrong date field Fix: Campaign Builder inactivity filter uses wrong date field (FA-19) Jan 5, 2026
@konard konard marked this pull request as ready for review January 5, 2026 22:13
@konard
Copy link
Copy Markdown
Author

konard commented Jan 5, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $4.945460 USD
  • Calculated by Anthropic: $2.805645 USD
  • Difference: $-2.139814 (-43.27%)
    📎 Log file uploaded as GitHub Gist (956KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Campaign Builder inactivity filter uses wrong date field

1 participant