Jump to content
ffub

MailChimp list synchronisation

Recommended Posts

Hi all,

I've been looking at adding MailChimp synchronisation to PW. I have a few sites with users that have to register and it's much simpler for me to have the whole user list synchronised into MailChimp rather than adding people on a case-by-case basis (as I have done in the past). 

With this in mind I have created a prototype module that syncs the whole list, a few fields and user roles. This allows you to send MailChimp campaigns to a segment of your users based on their roles. You can download and try out the module here:

https://github.com/ffub/MailChimpSync

I've a few ideas of where I want to take this:

  • Switch to scheduled updates. To avoid updating the whole list users should be flagged as requiring an update when one of the relevant fields is updated. LazyCron or cron jobs would update flagged users.
  • Automatic creation of the list on MailCimp and initial import.
  • It would also be possible to add an interests field in PW and synchronise this too, which would effectively allow you to create lists in PW.

I've had to hook before the user is actually saved as this is the only clean way I could find to get their new email address and their existing one at the same time. This is pretty inefficient as this holds up the user being saved in PW until the MailChimp update is done.

I'd also like to only update the user when the fields defined in the module are updated, rather than the user as a whole.

Stephen

  • Like 4

Share this post


Link to post
Share on other sites

Looks good ffub! I don't yet have a mailchimp account, but this might be a good reason to get one. They are a PHP, Atlanta-based company too, after all. :) 

I've had to hook before the user is actually saved as this is the only clean way I could find to get their new email address and their existing one at the same time. This is pretty inefficient as this holds up the user being saved in PW until the MailChimp update is done.

You can always used a "saved" hook (which gets called after a successful save) rather than "saveReady". Or you could use both, letting "saveReady" populate something that is later used by your "saved" hook. But the only way to grab a previous value before save is to pull it directly from the DB. i.e. 

SELECT data FROM field_email WHERE pages_id=$user->id

Share this post


Link to post
Share on other sites

Heh, now we got 3 mailchimp modules separately that do work differently. I'm holding mine back as it is a lot more complicated to create a good mailchimp module with remote managing lists and campaigns. Lists can't be created via API, reason being that you should work with segments and groups for a list instead of creating a list for every group. This is to avoid creating too many lists. But this get's a little more expensive in "recreating" the functionality Mailchimp already has done very very well.

One thing that is different from your module for example is I don't use PW user but pages. I create campaigns for lists and submit them from a newsletter created from a special page the user can edit and select for submission. So far I haven't got the time to invest and list management is still missing, kinda what you got here but as said not for PW users. But it has a nice admin interface to create campaings and see part of statistics after sending. Thing is that to make it really efficient (as the requests are limited) it would need to have caching built in so it doesn't need to request all those informations everytime, kinda what they suggest in their API docs. 

We maybe should work all together :) I'm on holiday currently in Turkey this week, but maybe I can find some time to share module. 

  • Like 6

Share this post


Link to post
Share on other sites

@Soma it would be lovely if there would be a "MailChimp/newsletter module team" here and maybe a "payment/e-commerce module team", too. :)

  • Like 4

Share this post


Link to post
Share on other sites

Hi, thanks for the feedback. I'm going to have some time to work again on this module next week.

Ryan, I think I will store the email as synched to mailchimp against the user and then use to handle email changes rather than looking up via the database directly. 

soma, I saw you wrote about your MailChimp module on another thread and I certainly think they could work alongside each other. I hadn't realised it was not possible to create a list via the API so I'll have to keep this as a setting. It only needs to be done once though, as my approach is to sync the user database with a single list and build on the segmenting MailChimp encourages.

It may be feasible to have the same module synchronise a page array instead of just $users, which would allow people to manually add people to lists without adding them to the user database. I'm concentrating on $users for the moment though as this is the use case that best fits me. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...