revolunet/react-mailchimp-subscribe

Adding GDPR fields and a few examples

Opened this issue · 2 comments

Hi. This was a very handy thing to plug in, I would have loved to see examples of adding more advanced fields though, maybe an expanded example. For instance I wanted to adopt GDPR early but couldn't quite figure out how to get the data sent. I ended up hacking in this:

onValidated({ EMAIL: email.value, FNAME: fname.value, LNAME: lname.value, GDPR: {[27]: gdpr.value} });

It triggers a warning though, any ideas how to do it in a better way? The bracket in the variable name was my main issue, they expect gdpr[27] for the GDPR email field.

I actually found out it doesn't consistently add the GDPR value so I ended up making my own instead. I can make a PR for the richer implementation of the form as an example when I get it done.

It looks like the GDPR values are different per account. Mine was gdrp[37317].

Here is how I implemented it:

<MailchimpSubscribe
  url={URL}
  render={({ subscribe, status, message }) => (
    <form onSubmit={e => {
      e.preventDefault();
      const form = e.target;
                            
      const formData = {
        EMAIL: form.email.value,
        [GDPR_NAME]: form.gdpr.checked ? form.gdpr.value : '',
      };

      subscribe(formData);
  }}>
    {/* ... */}
  </form>
</MailchimpSubscribe>