Skip to content

Add Campaign Monitor Segment provider#342

Open
scottnelle wants to merge 3 commits intodevelopfrom
feature/campaign-monitor-segments
Open

Add Campaign Monitor Segment provider#342
scottnelle wants to merge 3 commits intodevelopfrom
feature/campaign-monitor-segments

Conversation

@scottnelle
Copy link
Copy Markdown

Clone Campaign Monitor provider to introduce a version which works based on list segments instead of lists.

Background

This is, apparently, Campaign Monitor's recommended workflow for sending several newsletters with different subscriber bases. In this implementation, the client maintains a single list for all subscribers and sets up segments to control which newsletters each subscriber receives. This has the advantage of allowing a single set of custom fields to be maintained for all users. In a more traditional Campaign Monitor implementation, each user + list association is unique, which means custom fields (like an access token or user preference) must be maintained multiple times for each email address.

Copy link
Copy Markdown
Member

@kevinfodness kevinfodness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments and suggestions, but no blockers. 🍣

Comment on lines +74 to +76
$wrap = new \CS_REST_General( $auth );

return $wrap;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just return the new instance directly?

Suggested change
$wrap = new \CS_REST_General( $auth );
return $wrap;
return new \CS_REST_General( $auth );

}
$auth = [ 'api_key' => $settings['api_key'] ];

$wrap = new \CS_REST_Lists(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo a better variable name would be $lists

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! In a previous iteration I was using the Clients Wrapper, copied over from the existing Campaign Monitor provider. Forgot to change the variable when I switched to the more direct class.

/**
* Gets the lists for the client.
*
* @TODO: Add caching that works on Pantheon and WordPress VIP.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A wp_cache_get/wp_cache_set would work fine on both. Can probably cache lists for 5 minutes?

}

foreach ( $segments as $segment ) {
// Filter segments to only include segments for the list we're using, and exclude default segments.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the list ID filter already handled by providing the list ID to CS_REST_Lists above? Why do we need to filter for it again?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! This comment was left over from an earlier implementation (got all segments and then filtered them by lists) before I switched to using the Lists class/endpoint. Thanks for catching.

* }|false The response from the API.
*/
public function create_campaign( int $newsletter_id, array $list_ids, string $campaign_id = null, string $from_name ): array|false {
// TODO: Move non-email provider code to the core plugin.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO still valid?

}
$auth = [ 'api_key' => $settings['api_key'] ];

$wrap = new \CS_REST_Campaigns( $campaign_id, $auth );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let's call this $campaigns

}
$auth = [ 'api_key' => $settings['api_key'] ];

$wrap = new \CS_REST_Campaigns( $campaign_id, $auth );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$campaigns

}
$auth = [ 'api_key' => $settings['api_key'] ];

$wrap = new \CS_REST_Campaigns( $campaign_id, $auth );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}
$auth = [ 'api_key' => $settings['api_key'] ];

$wrap = new \CS_REST_Subscribers( $list_id, $auth );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$subscribers



/**
* Add subscriber to list
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth asking around to other teams that use this plugin whether this functionality is actually needed. I'd rather that Newsletter Builder be responsible for managing campaigns, and not be responsible for managing list members. If implementers need to do list management, they can do so separately, and this plugin should be focused on sending campaigns to existing lists/segments with existing subscriber bases to avoid trying to do too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants