Campaign Manager

Send professional campaign messages to your subscribers.

Recipient Groups

Plugins can register recipient groups, which are like subscriber lists except the recipients are generated by the system. For example, a store plugin might offer All customers and Customers with paid orders. See Subscribers for how groups are used.

Groups are registered with two events, which should be handled in the boot method of the plugin registration file.

  • responsiv.campaign.listRecipientGroups returns the groups supported by the plugin.
  • responsiv.campaign.getRecipientsData resolves a group to the email and name of each recipient.
public function boot()
{
    Event::listen('responsiv.campaign.listRecipientGroups', function() {
        return [
            'my-plugin-all-customers' => 'All customers',
            'my-plugin-paid-customers' => 'Customers with paid orders',
        ];
    });

    Event::listen('responsiv.campaign.getRecipientsData', function($type) {
        if ($type === 'my-plugin-all-customers') {
            return Customer::getAllCustomers();
        }

        if ($type === 'my-plugin-paid-customers') {
            return Customer::getPaidCustomers();
        }
    });
}

Moving the logic to a class, like the Customer class above, is the recommended approach.

Registering Groups

The responsiv.campaign.listRecipientGroups handler returns an associative array with the type codes as keys and the names as values. Prefix the type code with your plugin name to avoid conflicts with other plugins.

return [
    'my-plugin-recipient-type' => 'My plugin recipient type',
];

Returning Recipients

The responsiv.campaign.getRecipientsData handler is passed the type code. It must check that the type belongs to the plugin, and return nothing otherwise. The handler returns an associative array with the email addresses as keys and the recipient names as values.

return [
    'greatguy@domain.tld' => ['first_name' => 'Some', 'last_name' => 'Person'],
    'coolgal@domain.tld' => ['first_name' => 'Another', 'last_name' => 'Person'],
];

Email addresses should be lowercase, since they are matched against existing subscribers. Recipients that are not already subscribers are created as confirmed subscribers.