Exclude subscribers who received specific campaign(s)

ele

Member
I encounter a use case on which I'm not sure how to manage it from the MailWizz context. Well, what I want is to be able to exclude the persons who previously received certain campaigns (e.g., sending C10, I want to exclude those who received C2 and C5; "C" for "campaign", of course).

Ideally, the way I'm managing my emailing environment is to have just one list per activity (being software author, it means per app, for example). I don't want to have multiple lists with all the complexity of duplicates, syncing, etc. Just one list and a hashtag list in a custom field (I called "Tags"; it could be "Hashtags") to produce my segments (of course, these hashtags are informed correctly)...

Then, following this type of management, the most logical would be to add a custom field called "Campaigns", then add the names or UID's of the received campaigns in this field. In the campaign setup, we can change the value of a custom field after sending of a campaign, but we can't add a value in this field. We can just overwrite it, while I would need to be able to do something like what is shown below. Here is my issue!

snap_2025-04-25_11-37-43.png

So, I searched an alternative... For example, I see I can exclude subscribers who opened or didn't open a previous campaign(s) (see screenshot below), but not who received it/them (i.e., doesn't matter if they opened or not).

snap_2025-04-25_12-00-53.png

Another option would be to manage this from the definition of a segment where I can indicate campaigns-related condition (see capture below), but again it's about open and click only; not sending/receiving; and I can select one condition only (not both "open AND not open").

snap_2025-04-25_12-05-56.png

I could also manage this by myself through the API (updating the concerned field) after the campaign is sent to a subscriber relying on webhook event, but there's only event on email opening, not sending (see screenshot below).

1745578769563.png

So, what? For me, the easiest way would be to manage this as expressed at the beginning of this post... So, it would require to have a placeholder/variable about current value of a custom field (e.g., "Campaigns") doing I would be able to enter something like "[CURRENT_VALUE] [CAMPAIGN_UID]" to concatenate both values (where [CURRENT_VALUE] returns the list of the previous campaigns already added in this field for the concerned person).

Unless you have an easier way in mind I could have missed...
 
Last edited:
OK, searching the forum, I found this post, then adjusted for my need ;) Here is the result (the campaign name is added in a CAMPAIGNS field after an email is sent to the subscriber). Just take care to create the custom field as textarea to avoid the limit of 255 characters in a text/string field. And, of course, after this, never change the name of your campaigns LOL

Code:
// Updates subscriber's CAMPAIGNS field when a campaign is sent
Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function($campaign, $subscriber, $customer, $server, $sent, $response, $status) {
  
    $subscriberId = $subscriber->subscriber_id;

    if (!$sent) {
        return; // email not sent
    }

    // Get current value
    $fieldTag = 'CAMPAIGNS';
    $field = ListField::model()->findByAttributes(['tag' => $fieldTag]);
    if (!$field) {
        return; // custom field not found
    }

    $fieldId = $field->field_id;

    $subscriberField = ListFieldValue::model()->findByAttributes([
        'field_id' => $fieldId,
        'subscriber_id' => $subscriberId,
    ]);
    $value = $subscriberField ? $subscriberField->value : '';

    // Append campaign name
    $campaignName = $campaign->name;
    $newValue = $value ? $value . " '" . $campaignName . "'" : "'" . $campaignName . "'";

    // Update field or create a new record in custom fields table if missing
    if ($subscriberField) {
        $subscriberField->value = $newValue;
        $subscriberField->save(false); // no validation
    } else {
        $newFieldValue = new ListFieldValue();
        $newFieldValue->field_id = $fieldId;
        $newFieldValue->subscriber_id = $subscriberId;
        $newFieldValue->value = $newValue;
        $newFieldValue->save(false); // Save as a new entry
    }
});

--
EDIT (some hours later): Damnation! I see that even textarea is limited to 255 characters °O° Well, well...
 
Last edited:
Back
Top