Signup/signout & 'check if signed' up are available as Rule actions/condition #1593224: provide rules integration for 7.x-2.x
But we can't move users to a certain MailChimp group yet based on a Rule Action.

This would enable us to put users in MailChimp groups based on everything that we can reach with Rules like product purchases, Role, Profile, Userpoints, Link clicked, page visited, age, site activity, etc.

This piece of code seems to contain code on how to move a member to a different MailChimp group through the Mailchimp Module (API):
http://drupal.org/node/1545506#comment-6474668
and may be partly reusable

Information about what MailChimp groups are, and how they can be valuable in email marketing:
http://kb.mailchimp.com/segments/add-groups-to-a-list

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hibersh’s picture

Status: Active » Needs review
FileSize
3.26 KB

Rule action "Subscribe user to a mailchimp group" added

It will be great that have groups property for list entity

silkogelman’s picture

Title: Ability to put a Member into a Group with a Rule Action » Ability to put a Member into a MailChimp Group with a Rule Action

clarifying title to make sure people don't think it's about Organic Groups

silkogelman’s picture

Issue summary: View changes

updated with link to code that contains clues on how to do this

jsibley’s picture

Issue summary: View changes

It has been more than a year since this patch was offered.

Could it please be committed if it works?

This would make mailchimp significantly more useful within Drupal, since mailchimp autres in favor of having one one list and using groups for segmentation.

jsibley’s picture

It looks like the patch needs to be redone to work with the current dev or recommended versions, as it was never committed and development continued.

Since it looks like the current dev is not recommended for production, if I produce a working patch for the current recommended version, would it be committed? This would be my first patch, but I'm willing to try. It looks like just the line numbers need to be adjusted.

rvb’s picture

Thanks jsibley for doing this. This would be a great feature to have!

klausi’s picture

Updated the patch a bit: use an email address instead of a user object, so that you also can subscribe raw emails without users. Changed the option list to use the machine name instead of the numeric list ID.

Currently the action replaces whatever groupings are specified, the Mailchimp API leaves other groupings that are not mentioned in the request as is anyway.

Rodeo.be’s picture

ok, I'm trying to get this working (D7, 7.x-3.1).
What should I select as "actions"?
I tried:
entity data selector: account
Mailchimp List Subscription Field entity selector: ??
Add subscription: yes

adam_b’s picture

Has anyone got farther with this? I'd love to be able to specify groups - but so far I can't even get the patch to apply successfully.

adam_b’s picture

Got klausi's patch applied to v2.12, thanks to a friend.

But although I can see the new action "Subscribe email to a mailchimp group", when I select and try to save it I get an error:
Unknown action mailchimp_lists_user_subscribe_intgroup.

MrPeanut’s picture

FileSize
3.26 KB

I have applied @klausi's patch from #6. I do see the Group in the Group ID fieldset. However, I'm not really sure what the Groups fieldset is for. It says "The group values separated by commas."

Groups

I've entered the group's numerical ID and also the sub-group's numerical ID. Neither one seems to work. I've tried users who are already subscribed and users who are not yet subscribed.

In any case, I'd like to be able to subscribe a user into one of that group's groups. (For example, my "Main Group" has Washington St Location, Riverview Ave Location, etc.)

Lastly, it might be worth moving this development to the 3.x branch.

MegaChriz’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
FileSize
8.98 KB

Here is a patch for the 7.x-3.x version. The implementation is a bit different from the patch from #6, which was for the 7.x-2.x version. This patch provides two Rules actions:

  • Subscribe email to a mailchimp group
    mailchimp_lists_subscribe_intgroup
    This action subscribes a mail address to one or more (sub)groups from a single interest group. It doesn't unsubscribe the mail address from other (sub)groups from the same interest group.
    If the mail address is not yet subscribed or unsubscribed it will be (re)subscribed with a single opt-in (no confirmation mail).
  • Unsubscribe email from a mailchimp group
    mailchimp_lists_unsubscribe_intgroup
    This action unsubscribes a mail address from one or more (sub)groups from a single interest group. In case the mail address is currently not subscribed, the action will do nothing.

About configuring the actions

Both actions will ask you first for the mail address and the interest group ID. After that a list of available groups within that interest group is loaded (eventually via AJAX).
The code for this is taken from rules_action_type_form_alter() in rules/modules/data.rules.inc.

Tested with checkboxes only

In only tested this with interest groups where multiple options are allowed (thus with interest groups that are set in MailChimp as checkboxes), not with single option interest groups (radio buttons).

MrPeanut’s picture

Patch from #11 is working great!! Thank you so much, MegaChriz. That works terrific.

[edit] What would it take to send additional merge fields (e.g. address, city, state, particularly from a Commerce order)?

CountPacMan’s picture

It's a beautiful patch, but I'm getting an error when adding a rule:

Undefined index: intgroups in mailchimp_lists_groups_options_list() line 103 in .../../mailchimp_lists/mailchimp_lists.rules.inc

This is the option list callback for the group subscribe action that you added. Do you have any ideas about what may be causing this? I have created a group on a list in MailChimp, added subscribers to it, and can add it in rules with your patch, but I still get this error.

silkogelman’s picture

Issue summary: View changes
silkogelman’s picture

Issue summary: View changes
MrPeanut’s picture

I am having issues with my user getting updated and losing their groups.

Upon checkout, a user's billing address is copied to an address field on their user profile. I have a Boolean field on my order checkout. If checked, they are subscribed to a list and a group within that list.

The address gets copied to Mailchimp via a Mailchimp field on the user profile (which uses tokens to map the address data).

On checkout, the rule fires to subscribe them to the list. However, there's a second event in my log at the exact same time that says that user was updated. I'm assuming this is when they lose their interest groups.

Would anyone happen to have any idea why they're losing the groups or anything I could do to further test?

Greg Boggs’s picture

Status: Needs review » Needs work
MrPeanut’s picture

Regarding #16, I found that the event Completing the checkout process was causing the issue. Apparently something else was causing the account to be updated during that same event. I changed it to schedule a component evaluation and it seems to be working.

Now I am having trouble getting their address sent via a Mailchimp subscription field (it works if I change a value and save, but doesn't work on the initial subscription), but that is probably a separate issue than this.

MrPeanut’s picture

Sorry to be taking over this issue, but #18 does not completely fix the issue. If I edit a user, they still lose their groups. I do have a Mailchimp subscription field on the account (as that is how I was able to link the Drupal user account address field to the Mailchimp address merge field). Could the Mailchimp subscription field be "erasing" the group info when a user is updated?

RogerRogers’s picture

#13 to fix this you can change line 130 in the mailchimp_lists_rules.inc file to be:

    if (isset($list['intgroups']) && is_array($list['intgroups'])) {

This just checks to make sure intgroups is set. It removes the error. I've tested and it works, though I'm entirely unfamiliar with this code, so not sure if this is masking another issue.

Anonymous’s picture

Does this patch make it able to have a sign up / check if already signed up for mailing list on the checkout panel? It seems to be a feature that was in the MailChimp module before version 2. I'm quite new to the advanced side of Drupal. I know how to apply a patch, but I am not yet so sure about Rules. Any tips on what I need to look at first to implement this? Thanks

r0nn1ef’s picture

The patch in #11 does not apply cleanly to the latest 7.x-3.x branch or release.

gocosmonaut’s picture

I'm having problems with a Rules event. It's set up to add someone to list "After saving a new user account" but it's adding existing users who are just logging in. We have a workflow in Mailchimp itself that sends a welcome email every time someone is added to the list, so it's been sending multiple welcome emails & it looks bad. Any ideas?

gocosmonaut’s picture

One other note, I also changed the event to "Before saving a new user account" and the name was still added. Why does every user event trigger this?

adam_b’s picture

@gocosmonaut: those are two separate problems, neither of which is related to this issue. Please create new issues for them.

ruscoe’s picture

Status: Needs work » Closed (won't fix)

We're going to be ending support for the 7.x-3.x branch due to the upcoming deprecation of the v2.0 MailChimp API. If you're still interested in this feature, please feel free to reopen for the 7.x-4.x branch.

MrPeanut’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev
Status: Closed (won't fix) » Active

Is anyone doing this in 7.x-4.x? (I was using the patch from #11 until I upgraded to 7.x-4.x.)

klausi’s picture

We were not happy with the direction Mailchimp 4.x took and all we really need is the Rules integration, so we created our own module: https://www.drupal.org/project/mailchimp_rules

MegaChriz’s picture

I also created some rules actions in my MailChimp helper module. Also includes a mock for MailchimpLists, useful for automated tests.
Among more, contains a rules action specific for subscribing to interest groups.

MrPeanut’s picture

@MegaChriz — I actually have been and currently am using your module. However, with that, I can only subscribe to visible interest groups (i.e. Checkboxes).

With your patch from #11, I could subscribe to hidden groups as well. It was extremely helpful for categorizing our members based on where they subscribed.

MegaChriz’s picture

@MrPeanut
Oh crap, someone decided that hidden interest groups never need to be loaded in #2839768-3: Performance problems with mailchimp_get_lists(). My module does show hidden interest groups with version 7.x-4.7.

Here is another patch which skips interest categories that are hidden in MailChimp.

This caused significant performance improvements for us, since we have a bunch of admin-only categories that we use for customer acquisition stuff, but which they'll never see, so it doesn't make sense to retrieve them with every mailchimp_get_lists() call.

MegaChriz’s picture

@MrPeanut
I updated the MailChimp Helper module. When interest groups are loaded for Rules, extra API calls are made to retrieve them, including the hidden ones. The loaded interest categories and groups are cached separately.

MrPeanut’s picture

Status: Active » Closed (won't fix)

Awesome, that works! Thanks so much, MegaChriz. Truly appreciate your quick help. Setting this back to closed.

MegaChriz’s picture

@MrPeanut
Actually, when I started updating a site to MailChimp 7.x-4.8 today I ran into the same issue. And I started updates because I ran into the following issue: #2852475: Already subscribed member gets status "pending" when he/she subscribes using double opt-in, but gets no confirmation mail.