Dynamic Segments
Segments (campaign-segment) are dynamic, rule-driven queries evaluated at dispatch time by SegmentEvaluator. Instead of manually maintaining static sub-lists, define reusable audience criteria once and attach the segment to any sendout.
Segment Structure
Section titled “Segment Structure”Each campaign-segment entry defines:
title&handle: Human name and machine handle (for example,aegean-vip).match_mode:all(Match ALL rules / logicalAND) orany(Match ANY rule / logicalOR).list_id(optional): Scopes evaluation to active subscribers of a specific mailing list before applying rules.rules: Repeatable rule rows, each containingrule_source,rule_field,rule_operator, andrule_value.
Rule Sources & Fields
Section titled “Rule Sources & Fields”SegmentEvaluator supports three rule sources:
1. Contact Profile (contact)
Section titled “1. Contact Profile (contact)”Evaluates fields on the Contacts record:
- Core identity:
primary_email(oremail),first_name,last_name,title,company_name(ororganization) - Locale & geography:
country_code(orcountry),preferred_language(orlanguage),timezone - Consent & taxonomy:
marketing_opt_in,tags,roles,source,created - Nested domain metadata:
domain_meta.<key>(for example,domain_meta.charter_tierordomain_meta.preferred_marina) - Custom fields: Any additional custom field stored on the
Contactsblueprint.
2. List Subscription (subscription)
Section titled “2. List Subscription (subscription)”Evaluates rows in campaign_subscriptions:
in_list: Contact is actively subscribed to the target list handle or ID.not_in_list: Contact is not subscribed to the target list.subscription_status: Matchespending,subscribed,unsubscribed,bounced, orcomplained.subscribed_at: Compares the subscription confirmation timestamp (before,after,within_days).
3. Campaign Engagement (engagement)
Section titled “3. Campaign Engagement (engagement)”Evaluates delivery and tracking history in campaign_events and campaign_sendout_recipients:
opened_campaign: Contact opened the specified campaign handle or ID.not_opened_campaign: Contact received or did not open the specified campaign.clicked_campaign: Contact clicked any tracked link in the specified campaign.clicked_link: Contact clicked a specific destination URL (supportsequalsorcontains).opened_within_days: Contact opened any campaign within the lastNdays.received_sendout: Contact was targeted by a specific sendout UUID.
Supported Operators (rule_operator)
Section titled “Supported Operators (rule_operator)”SegmentEvaluator implements 16 type-aware operators:
| Category | Operators | Notes |
|---|---|---|
| Equality | equals, not_equals |
Case-insensitive string comparison; supports booleans (1/0, true/false). |
| Substring | contains, not_contains, starts_with, ends_with |
Works on strings and multi-value arrays such as tags or roles. |
| Numeric | gt, gte, lt, lte |
Compares numeric values (e.g., booking counts or loyalty scores). |
| Presence | is_empty, is_not_empty |
Checks whether a field is empty, null, or missing. |
| Set Membership | in, not_in |
Matches comma-separated values (for example, DE,CH,AT for country_code). |
| Date & Recency | before, after, within_days |
Parses ISO-8601 dates or Unix timestamps; within_days checks rolling windows. |
Evaluating Segments in PHP
Section titled “Evaluating Segments in PHP”Use Campaign::segments() (SegmentEvaluator) to count or preview matching contacts programmatically:
<?phpdeclare(strict_types=1);
namespace ProcessWire;
$campaign = \Totoglu\Campaign\Campaign::requireInstance($wire);$segments = $campaign->segments();
$segment = $wire->entries->findOne('type=campaign-segment, handle=aegean-vip');if ($segment !== null) { $total = $segments->count($segment); $matches = $segments->evaluate($segment, limit: 50, offset: 0);
foreach ($matches as $contact) { $email = (string) $contact->get('primary_email'); // Inspect or preview matched contact }}