spatie / mailcoach-support

Questions and support for Mailcoach
https://mailcoach.app
31 stars 2 forks source link

[Feature request] Add tag to group of subscribers #170

Closed RicardoRamirezR closed 4 years ago

RicardoRamirezR commented 4 years ago

Hi there,

After sending a campaign, a group of subscribers should open the newsletter, Mailcoach will take care of registering the openings.

Now is the time for a campaign focused on that group of subscribers, it would be nice to have some way of putting a tag on them. (I've already did that at database label)

electronick86 commented 4 years ago

Hello Ricardo

I did something similar using a Segment Class :

class DynamicActiveSubscribers extends Segment
{
    public int $numMonths;

    /**
     * DynamicActiveSubscribers constructor.
     * @param int $numMonths
     */
    public function __construct(?int $numMonths)
    {
        $this->numMonths = $numMonths;
    }

    public function subscribersQuery(Builder $subscribersQuery): void
    {

        if($this->numMonths){
            $subscribersQuery
                ->whereDate('subscribed_at', '>', Carbon::today()->subWeeks( config('myapp.active_subscribers.recent_weeks') )->toDateString())
                ->orWhereHas('opens', function (Builder $query) {
                    $query->whereDate('created_at', '>', Carbon::today()->subMonths( $this->numMonths )->toDateString())  ;
                });
        }

    }

    public function description(): string
    {
        return "DynamicActiveSubscribers ($this->numMonths months)";

    }
}

That way, campaign can only be sent to users that recently subscribe OR that open a campaign in the last X months.

freekmurze commented 4 years ago

Mailcoach doesn't to automatic tagging on open and clicks, because everyone will likely want to do something else.

When installing into a Laravel app, you can leverage events and manually tagging to get your desired result.

https://mailcoach.app/docs/v2/package/advanced-usage/handling-events https://mailcoach.app/docs/v2/package/working-with-lists/working-with-tags