Tags & Segmentation
Tags
Tags are freeform labels attached to subscribers. Stored in om_tags and om_subscriber_tags.
php// Tag management
$tag_id = OM_Tags::create( 'vip-customer' ); // returns int
OM_Tags::assign( $subscriber_id, $tag_id );
OM_Tags::remove( $subscriber_id, $tag_id );
$tags = OM_Tags::get_for_subscriber( $subscriber_id ); // returns array
// Check if subscriber has tag
$has = OM_Tags::has( $subscriber_id, 'vip-customer' ); // bool
// Get all subscribers with a specific tag
$subs = OM_Tags::get_subscribers( $tag_id );
Assigning a tag fires:
phpdo_action( 'om_tag_assigned', $subscriber_id, $tag_id );
Segments
Segments are saved dynamic filters. A segment query is re-evaluated at send time — subscribers enter or leave based on current data. Stored as JSON conditions in om_segments.
Condition types:
| Condition | Operator | Value |
|---|---|---|
status_is | = | subscribed / unsubscribed / bounced / pending |
tag_is | has | tag slug |
tag_not | doesn't have | tag slug |
list_is | on | list ID |
list_not | not on | list ID |
field_equals | = | custom field key + value |
field_contains | contains | custom field key + string |
field_gt | > | custom field key + number |
field_lt | < | custom field key + number |
opened_campaign | opened | campaign ID |
clicked_campaign | clicked | campaign ID |
not_opened | did not open | campaign ID |
subscribed_after | after | ISO date |
subscribed_before | before | ISO date |
source_is | = | source string |
engagement_gte | >= | 0–100 |
engagement_lte | <= | 0–100 |
Conditions are grouped: conditions within a group are ANDed; groups are ORed.
php// Create a segment
$seg_id = OM_Segments::create(
'High-Value Engaged',
[
// Group 1: tag is vip AND engagement >= 60
[
[ 'type' => 'tag_is', 'value' => 'vip' ],
[ 'type' => 'engagement_gte','value' => 60 ],
],
],
'VIP subscribers with high engagement score'
);
// Resolve subscribers matching a segment
$subscriber_ids = OM_Segments::resolve( $seg_id ); // returns int[]