Merge documentation | Mailchimp | Drupal

If anyone has more complete information on this subject please comment below.


If you installed the drupal MailChimp Module you might want to know how to "Merge Variables"

If you were like me you created a list on mailchimp

Added the Drupal MailChimp Module,

enabled it

went to admin/settings/mailchimp

added the API keys to your installed Drupal MailChimp Module

Hit save

synced it with your account

opened the mail list

and at the bottom you wanted to add your own custom data to each mail added to your list where it says:


"Merge Variables



Select Drupal user variables to send to Mailchimp as Merge Variables. Available Drupal variables are any Profile or Token variables for the given user. For more information on Merge Variables, see the Mailchimp Documentation. Not that some fields, such as ADDRESS fields which are multi-part, cannot be merged with a single token value."

accept there is no drop downs under the list.and when you click on Mailchimp Documentation it takes you to a broken URL.

So I went to my mail chimp account and I added the variables at

admin.mailchimp.com/lists/settings/merge-tags

(note this url will give you an idea of where to look but might not be the same for all accounts)

then I went back to my drupal mailchimp admin (admin/settings/mailchimp)

I clicked, under "MailChimp cron"

rebuild the MailChimp user table

then when I access the mail lists there is a list of posible drupal data I can merge or attach to my mailchimp account.

But there is a limited amount of choices.

-----------Everything below is for adding your own custom tokens to mailchimp---------------

-----------however this next part will only get you on the right track it is half the---------------

-----------solution, I never had time to completely solve this problem-------------------------

So....

What if I want to control what choices are there?

First download the Token Drupal Module, install it and enable it

Then dowload the Custom Tokens Module, install it and enable it

Add your custom tokens to the custom token module in the backend under admin/build/tokens

Now here is where you hack your mailchimp module

Find \modules\mailchimp\mailchimp.module

open the file and find the function mailchimp_mailchimp_merge_keys()

at the very bottom of the function add the following code:



if (function_exists('token_custom_token_list')) {
$custom_tokens = token_custom_token_list('user');
if (isset($custom_tokens['token_custom'])){
while (list($key, $value) = each($custom_tokens['token_custom']))
{
//$custom_tokens['token_custom'];
$out[$key] = t('Token: !field', array('!field' => $value));
}
}
}
if (function_exists('token_custom_token_list')) {
$custom_tokens = token_custom_token_list('user');
if (isset($custom_tokens['token_custom'])){
while (list($key, $value) = each($custom_tokens['token_custom']))
{
//$custom_tokens['token_custom'];
$out[$key] = t('Token: !field', array('!field' => $value));
}
}
}


This checks to see if the custom token module is running and if so it looks to see if there are any tokens it can add to the possible merge fields. Now open the mail chimp admin and bind the merge vars to the custom Drupal tokens. Here is where I had to stop and change gears because this was more work than the client wanted to pay for. When you hit submit there is a script that is ran in mail chimp that submits all the keys. You will need to find that script and make sure that it is mapping correctly to the custom tokens...good luck and please post the answer if you figure it out.


comments powered by Disqus