Skip to content

Mailchimp Guide (part 2) Subscribers

Gonzalo Dominguez edited this page Aug 16, 2022 · 2 revisions

Using Mailchimp in Magento 2

Part 2 - Syncing subscribers

We have seen how to install the extension and get the API Key, now it is time to sync our subscribers.

Subscriber are associated to a MailChimp list, the one we selected when creating our MailChimp Store, you have to keep in mind that when you choose a store you are also choosing a list, because once you create a store you will not be able to switch its MailChimp list.

image

As you can see in the picture there are two labels, Total Member Subscribers and Total List Subscribers, the first value is all the members associated in your MailChimp account (Including all lists), and the second value is the members of the list you have selected.

As you know, MailChimp is quite picky (And hard to deceive) about the origin of the subscribers. If you buy a list and try to upload it, they are going to notice and ban your account.

This leads to the question... What is the correct way to configure everything?

The first thing you should do, is enabling "Double Opt-In" in your Magento, first you need to go to Stores/Configuration/Newsletter, and inside of the menu "Subscription Option" we should enable the "Need to confirm" option.

image

Next, we have to verify in the extension's configuration that the value of "Magento always manage emails" is set to "No" (This is to prevent Magento from sending the confirmation email, since this will be done by MailChimp)

image

This is enough for MailChimp to send the opt-in email, going to MailChimp and enabling double opt-in in your List is not necessary (although desirable).

So now, when someone subscribes in your Magento store, the subscriber will show as waiting for confirmation (This is the reason we enable the "Need to confirm" option in Magento) and is going to be sent to MailChimp with confirmation required, that way, MailChimp is going to send the verification mail to the subscriber.

This takes us to the next step... enabling Two Way Sync.

What is this? When a user makes a change to their subscription on MailChimp (Like changing their name or unsubscribing), then MailChimp will try to update your store with a webhook.

This basically makes synchronisation work in both ways,when something changes in your Magento store it will update MailChimp, but also if something changes on MailChimp it will update your store, that way both ends are always synchronised.

Next we are going to see what we want when there is a deletion, this means a subscriber unsubscribed in mailchimp and mailchimp is notifying us of this situation.

We have to understand how webhooks are composed.

In this link: [https://developer.mailchimp.com/documentation/mailchimp/guides/about-webhooks/]{.underline}

There is documentation about webhooks, actually it is quite simple, every time

there is a modification, mailchimp is going to make a POST to our store.

These POSTs are not processed at the moment, but are saved in a table (mailchimp_webhook_request) to be processed later by a cronjob, this is done to avoid overloading your store in certain situations. However, not overloading your store is not always possible, because for example, if you import a list in mailchimp and you have configured a webhook, mailchimp will make a POST to your store for each new subscriber that is imported, notifying that there is a new subscriber.

In that case, you should go to mailchimp and delete that webhook, to avoid

overload. To do that, once you go to mailchimp and choose your list.

image

In Settings you have an option to go to your Webhooks.

image

And there, you will have all your webhooks associated with the list (You can have as many as you want).

Clicking on Edit, you can do several things, from changing when you want the webhook to call you, to deleting it definitively. In case you are importing a list in mailchimp, it is convenient to remove the "subscribes".

image

When there is an unsubscribe, as you can see in the documentation, the data being sent is subscriber data (Name, email, etc) and the list. But a list can be associated with many mailchimp stores, and a mailchimp store can be associated with many magento stores. So there is not an exact way to know from which store the subscriber is unsubscribing from.

What it does is that it looks for all the stores in your Magento that have this list associated, and unsubscribe from each of them, there is no way to unsubscribe from one, because mailchimp doesn't know about magento stores, it only knows about lists.

If you're fairly neat in your setup you shouldn't have any problems with this, but it's good to know.

The next thing to do is to look at the merge fields.

As we saw in part 1, you can add fields to your subscribers (and to your customers from version 10x.x.37).

The merge fields are fields that by default mailchimp doesn't have, but you can add them whenever you want. You can ONLY add customer attributes. So if you want to add something that is not already there, you will have to add it as a customer attribute

So the first thing to do, is to add a new merge field

image

To two columns, one for Mailchimp and one for Magento.

In the mailchimp one it will show all the MERGE tags that are defined in your list.

image

If you go in mailchimp to your list, you can find in Settings a menu item that takes you to your MERGE tags.

image

There you will find something like this.

There you have a column Field label and type, which indicates the name you are going to see that field in mailchimp and the type of the field, then you have if it is required or not, if it is visible or not and the internal name(which is always in capital letters).

If you look in Magento, you will have almost the same data, the internal name, the label and the type. This way you can have I think quite clear which MERGE tags you are referring to.

image

In the other column, you are going to have all the customer attributes.

image

At this point, you have to map one to the other, being careful that they correspond, and they have the same type.

So in 2 minutes, after I have defined my MERGE tags in mailchimp I can set them up.

image

What things do you have to take into account? If you put a MERGE tag as mandatory in mailchimp, you're going to have to map it, and you're going to have to make sure that this data is in magento.

For example, in my case if I had put the GENDER as mandatory in mailchimp, I would have to do something to make it also mandatory in magento, otherwise it would fail when it tries to synchronise.

For the last thing I leave the case of PHONE, if you look at magento, there is no custom attribute for a phone number, this attribute, like others, for example the postal code or the city, are part of an address, so if I want to pass the PHONE I have no choice but to pass a complete address.

Obviously the extension maps a magento address to a mailchimp address.

When you changes the mailchimp store on this configuration, the data in the tables remains there (this is because if you wish to return to the old mailchimp store you don't need to re-sync), but if you don't think to return to this old store the better option is delete this old data.

image

The button only appears if unused register need to be deleted

For now, this is all about subscribers, in the next one we will see how to synchronise your ecommerce data.