revolunet / react-mailchimp-subscribe

React subscribe form for Mailchimp.
https://revolunet.github.io/react-mailchimp-subscribe/
244 stars 49 forks source link

Can we add people to groups or tag them on submission? #54

Open ConnorVO opened 3 years ago

ConnorVO commented 3 years ago

Tried adding a hidden input like Mailchimp suggests, but that doesn't seem to work.

MichaelMarner commented 3 years ago

You can do this already using a custom form, just add the group information to the data you are sending. For example:

        onSubmit={e => {
          e.preventDefault();
          this.props.onSubmit({
            EMAIL: this.state.email,
           'group[8291][1]': '1'
          });
        }}
thisisthais commented 3 years ago

is there a way to do this with tags? I tried

onValidated={(formData) =>
                    subscribe({
                      ...formData,
                      tags: ['MY TAG NAME'],
                    })
                  }

the request was posted succesfully but the tag was not added

smac89 commented 2 years ago

If anyone is wondering, here is the doc that describes how to automatically add customers to groups: https://mailchimp.com/help/automatically-add-subscribers-to-a-group-at-signup/

is there a way to do this with tags? I tried

onValidated={(formData) =>
                    subscribe({
                      ...formData,
                      tags: ['MY TAG NAME'],
                    })
                  }

the request was posted succesfully but the tag was not added

I don't think this can be done in the same way as the groups thing, but you can checkout their tags api

liordavid commented 1 year ago

I managed to solve adding tags with <MailSubscribeForm status={ status } message={ message } onValidated={(formData) => {subscribe({...formData, "tags": "SOME TAG NUMBER"})}} />

tim-basic commented 1 year ago

@liordavid Where do you find the tag number?

tim-basic commented 1 year ago

I managed to get tags working like this within a custom form:

  const handleSubmit = (e) => {
    email &&
      firstName &&
      lastName &&
      rsvpFor &&
      numAttending &&
      email.indexOf('@') > -1 &&
      onValidated({
        'group[54061][1]': '1',
        EMAIL: email,
        MERGE1: firstName,
        MERGE2: lastName,
        MERGE9: rsvpFor,
        MERGE7: numAttending,
        tags: '10511025,10511021',
      });
  };

I got the tag numbers by making an embedded form with the tags and then looking at the tag input in the generated code.