In this scenario, you, the customer, has a database/list of sorts and you want to collect some or all of the information associated with your subscribers, preferably as it changes, and save it back to your database to do something with it.
Anywho, what might you want to do with that information you ask yourself? Well...
Before you even think about continuing, you are going to need:
We'll start out by reminding you that these are just a few ways we've devised for accomplishing this. The crafty chimps in our labs and some of our savvy users often cook up new and ingenious ways of getting things done. By the way, if you are one of them, we'd love to hear your ideas... we might even send you a t-shirt or something!
Additionally, we STRONGLY discourage the practice of simply pulling your entire list, cycling though every user, and pulling down their details as a method of syncing up with us. It's an ugly, inefficient, brute force method of syncing this. That said, we understand that sometimes that is simply unavoidable...once, or maybe twice. And isn't it much more enjoyable to implement a unique, smart, and scalable solution? We think so, so we hope you keep reading.
By and far one of the most requested functions people ask about are ways to capture Subscribes, Unsubscribes, and Profile Updates in a real-time manner. We support two standard, durable methods for syncing data and have documented two other methods that are sometimes useful for performing syncs via the API:
Webhooks essentially allow you to subscribe to various events occurring in our systems and have your systems receive notifications about them in near real-time. While we could go on and on about how they work here, we've already documented them separately, so follow that link and read through that.
As of the v1.2 release of our API, we now support some much smarter, more durable methods for obtaining only the updated data that you need via the API - just keep an eye out for the since parameters
Keeping an internal database/list synced with your MailChimp list is by and far the type of sychronization that users are interested in and currently doing. As such after v1.2 and later releases of our API support an additional since parameter for the listMembers method. Using that parameter you can simply request all changes for a particular status since a certain date and time which typically would be the last time you ran your sync scripts. We also added an additional status, updated. Here's a recap of the statuses -
There are two caveats to be aware of when only using the API sync methods:
Many organizations like to pull in stats and reports from their Campaigns and Lists to do cool things with them internally. There are now a few extra API methods and updates to help you keep with these tasks
For each of those items that should be captured we will start by editing the "finished" form for each by:
Here are the forms that you'll be editing:
| Data to Track | Form to Edit |
|---|---|
| Subscribes | Confirmation "Thank You" Page |
| Unsubscribes | Unsubscribe Success Page |
| Profile Updates | Update Profile "Thank You" Page |
What you are going to do is stick a fake image tag with some merge tags in the URL, probably near the bottom of the page and out of the way. Here are some examples:
<img src="http://www.example.org/sub?email=*|B64EMAIL|*" height="1" width="1"> <img src="http://www.example.org/unsub?email=*|B64EMAIL|*"> height="1" width="1"> <img src="http://www.example.org/profile?email=*|B64EMAIL|*"> height="1" width="1">
Depending on what you need, you can use any merge tags you have created or even our unique email ids (*|UNIQID|*) when creating that URL.
Ok, now on your server you will need to create the script(s) that will read in the variable(s) and update your system(s) appropriately. While you don't have to, we highly suggest returning valid image data just to be sure it display correctly in all browsers - some will ignore the tag if there is a not valid image, others (like IE) may place a nasty placeholder in your form - ew. Of course that image can (and probably should) be incredibly small and blank so the user doesn't even notice it.
In case you didn't get what we just did, putting that image tag in there makes a request back to your server. Sure it's a little hacky and weird to do that, but you know what? It works!. In fact, if you look around, there are lots of systems that keep site and use stats using that exact same method (our opens tracking in your campaigns does this).
Finally, you may also want to consider adding some logic on your side to handle the inevitable cases where a user accidentally hits a page repeatedly and you don't want or should not keep making changes on your system.
Here are the forms that you'll be editing:
| Data to Track | Form to Edit |
|---|---|
| Subscribes | Signup Form |
| Unsubscribes | Unsubscribe Page |
| Profile Updates | Update Profile Form |
The one complaint most people have with this method is that slow connections may see some of the page load before their browser actually does the redirect. The best we can tell you to do is to remove, comment, and hide as much as possible on the page and put the redirect at the very top. In case you are not familiar with meta redirects, here's some documentation. Basically you will stick a tag like one of these in there:
<meta http-equiv="refresh" content="0;URL=http://www.example.org/sub"> <meta http-equiv="refresh" content="0;URL=http://www.example.org/unsub?email=*|EMAIL|*"> <meta http-equiv="refresh" content="0;URL=http://www.example.org/profile?email=*|EMAIL|*">
Then you have them on your site and you have their email address. At this point you will essentially be responsible for replicating those forms and submitting the appropriate API call to us: