Enrich a CRM as subscribers migrate
benecaster_migration_subscriber_imported fires once for each person a Migration Wizard import brings across, when their account, feed link and migration record all exist. This recipe uses it to push each person into a CRM.
It fires once per row, so a 5,000-person export fires it 5,000 times in one request. One HTTP call per person is how an import times out halfway through and leaves a half-finished batch. The example schedules the CRM call and returns straight away.
It does not fire for a row that was skipped. It does fire for someone already on your Patreon scorecard, whose record the import takes over.
What’s in $data. From the export: email, source_tier, display_name and join_date (the raw cell). All but email may be null, because a field can be left unmapped. From the wizard: patron_id, batch_id, mapped_tier_slug, token_type, is_free, source_joined_at and grace_period_ends_at. The feed token is never included, so logging the array cannot leak anyone’s private feed link.
Segment on is_free, not on token_type. follower is always a free member, but subscriber is not always paying: a free source tier can be mapped to a free Benecaster tier, which holds a subscriber token. is_free is the podcaster’s own answer from the tier-mapping step. Get this wrong and a welcome sequence asks free members to set up a payment they never had. A free member has no grace deadline either, so the example drops it for them.
join_date is what the file said and source_joined_at is what was stored. A null source_joined_at beside a filled-in join_date means the date could not be read; the person was still imported.
Code
<?php
// Queue a CRM update per migrated person. Note what this does NOT do:
// call the CRM inline. On a large import that would be thousands of
// blocking HTTP requests in one PHP process.
add_action(
'benecaster_migration_subscriber_imported',
static function ( int $user_id, int $show_id, string $platform, array $data ): void {
wp_schedule_single_event(
time(),
'acme_push_migrated_supporter',
[
'user_id' => $user_id,
'show_id' => $show_id,
'platform' => $platform,
'tier' => $data['mapped_tier_slug'],
// Segment on is_free, never on token_type: a free source
// tier can land on a free tier as a 'subscriber'.
'is_free' => $data['is_free'],
'joined_at' => $data['source_joined_at'], // may be null
// A free member has no deadline, whatever the batch says.
'deadline' => $data['is_free'] ? null : $data['grace_period_ends_at'],
]
);
},
10,
4
);
Hooks Used
Need this built rather than just documented? See our services →