Since I could add the subscription fields on default user accounts only (and not user Profiles) and I have different roles that need to be subscribed to different lists, I could not set the default value (subscribed) on my Mailchimp subscription field.

I then went on setting up Rules that "After saving new user account", with condition on account role, would subscribe the new user to the specific mailchimp list with the provided rule "Subscribe or unsubscribe entity from a mailchimp list".

The problem is that this doesn't work immediately.
If I create a new user and then navigate to his account edit page, I see his Mailchimp subscription field unchecked (unsubscribed). As expected, the user mail is not present in my list from the Mailchimp site either.

I then tried to set the Rule to edit the specific field value to 1 (or checked, i.e. subscribed), without using the provided rule but instead adding action "Set a data value", without success. The problem here is that the action won't support writing a specific value (user supplied, i.e. boolean TRUE) but only a data selector.

If instead a user manually set the value of the subscription field on his account page, it will work.

The question could be rephrased into a very basic support request: "How to automatically subscribe new users to Mailchimp lists based on their account role?"

Thanks

Comments

ruscoe’s picture

Status: Active » Postponed (maintainer needs more info)

Hi,

I just set up a test rule as you described and it worked correctly. The exported rule is below.

In this example, the MailChimp subscription field is named field-subscribe and I have a condition on the user having the authenticated user role.

{ "rules_mc_subscribe_on_create" : {
    "LABEL" : "MC Subscribe on create",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "mailchimp_lists" ],
    "ON" : { "user_insert" : [] },
    "IF" : [
      { "user_has_role" : { "account" : [ "account" ], "roles" : { "value" : { "2" : "2" } } } }
    ],
    "DO" : [
      { "mailchimp_lists_user_subscribe" : {
          "entity" : [ "account" ],
          "field" : [ "account:field-subscribe" ],
          "subscribe" : 1
        }
      }
    ]
  }
}

Does this work for you?

merauluka’s picture

Version: 7.x-3.2 » 7.x-3.x-dev
Status: Postponed (maintainer needs more info) » Active

I would like to bring this back up.

I recently created a rule using MailChimp with the exact results reported here. When I did an Object Log on mailchimp_lists_process_subscribe_form_choices I found it was being called multiple times during the user creation process.

My situation is a little different than kopeboy in that I'm using rules to create my user account, but the MailChimp rule I'm running is weighted higher so it should be running after the user is created.

I used the rule you setup above (updating the field name to match mine) and I had the same results. It appears that the user account is subscribed then immediately unsubscribed. Watchdog reports that the account was subscribed successfully, but I'm not seeing the email come through into MailChimp. Manually checking the box on a user's account works.

merauluka’s picture

Update: I just changed my filter on MailChimp to view unsubscribed email addresses and I can verify that my test attempts are there. So the accounts are making it to MailChimp, but are immediately unsubscribed afterward.

merauluka’s picture

Status: Active » Closed (works as designed)

Another Update: I was able to get the rule working for the "After updating an existing user account" event by putting the MailChimp subscribe logic into its own rule, weight at 10. I didn't have to force save anything on the account at all and it appears to have worked correctly now. Attached is my rule output.

{ "rules_subscribe_to_mailchimp" : {
    "LABEL" : "Subscribe to MailChimp",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "10",
    "OWNER" : "rules",
    "TAGS" : [ "providers" ],
    "REQUIRES" : [ "rules", "chp_misc" ],
    "ON" : { "user_update" : [] },
    "IF" : [
      { "list_contains" : { "list" : [ "account:roles" ], "item" : "8" } },
      { "NOT list_contains" : { "list" : [ "account-unchanged:roles" ], "item" : "8" } }
    ],
    "DO" : [
      { "chp_rules_action_entity_subscribe" : {
          "account" : [ "account" ],
          "field" : [ "account:field-newsletter-subscription" ]
        }
      }
    ]
  }
}