Skip to content

Mailchimp Guide (part 1) Installation

agustinbv edited this page Nov 3, 2022 · 9 revisions

On this first part, it will be explained how to install and use Mailchimp for Magento 2.

So, what is Mailchimp useful for?

And what can you and can't do with it?

Mailchimp keeps a subscribers list related to an e-commerce store such as Magento, and it is capable of sending campaigns to these subscribers. While that is the baseline functionality, ever since Mailchimp's API incorporated support for e-commerce data on its 3.0 version, it allows you to do much more than that. You can now sync all of your customers, as your products, orders and even carts.

First, let's explain the difference between a customer and a subscriber.

A subscriber is someone who gave us his permission to add him to a certain Mailchimp list (Audience).

On the other hand, a customer is either someone who created an account on the store website, or someone who just bought something from that store, or someone who abandoned a cart. A customer CANNOT be included in a marketing campaign. He can only be sent transactional emails, such as account creation, password reset, purchase invoice, and abandoned cart emails. He possesses a very reduced amount of attributes: first name, last name, address, and a couple more.

While a subscriber does not per se have many more attributes (in fact, he doesn't even have first or last name), through the merge field feature we can add any that is a customer attribute in the e-commerce store.

It should be pointed out that when you create a customer, Mailchimp also creates a subscriber, a special kind with 'transactional' status; this gives you the advantage to add through the merge fields any attributes to your customers ("transactional" subscribers) like you can with regular subscribers.

Installing Mailchimp for Magento 2

1. Select the right version

Go to the extensions repo where the releases are listed. You must search according to your version of Magento to determine which version of the module you can use, There you will find the command to install it.

image

It looks like this:

composer require mailchimp/mc-magento2:103.4.45

There is a version of the module for each 2.x version of Magento 2.

Magento 2.1 uses 100.1.x,

Magento 2.2 uses 101.2.x,

Magento 2.3 uses 102.3.x,

Magento 2.3.6-p1 onwards uses 102.3.x-p1,

and Magento 2.4 uses 103.4.x

2. Install via composer

Execute the aforementioned command in your terminal inside your Magento's root directory. If you have many versions of PHP installed for different purposes can write it like this:

php[version] `which composer` require mailchimp/mc-magento2:103.4.46

`which composer` helps the command to check the full path of Composer when it is globally installed.

3. Update your magento installation

Afterwards, execute the following commands:

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento cache:flush

4. Check the installation

Enter your magento admin page. On the dashboard side bar, you should see a linked titled "Mailchimp" featuring Freddie as the logo.

image

5. Access the menu

Open the Menu, and click on Configuration.

image

6. Activate the module

There you will find a substrings node titled Mailchimp General Configuration, which by default is disabled. Set it to Yes.

image

7. Configure your API key

Click on the button that says Get API Credentials. This will open a pop up to enter your Mailchimp account credentials.

image

Do so and once that happens, a message will appear, showing the API Key to fill in the form space called API Key. Do so, and then click on Save Changes.

image

IMPORTANT: To insert the API Key credentials is NOT the same as copying and pasting an API Key directly. The API Key generated through Get API Credentials is specifically made for the module. It is recommended to use the Get API Credentials button since everything related to that Audience with the the store will be identified as such.

For example, see the two subscribers below:

image

image

The first one subscribed to a Mailchimp Store whose API Key was copied and pasted into the form, while the other one was subscribed to a Store whose API Key was acquired through the pop up. As you can see, the first shows him as subscribed through the store's, while the second shows him as subscribed through the module. You will be able to tell which subscribers in the Audience were linked to the module.

8. Configure the extension

Once you've done this, the stores you've already created through this account will be displayed in the dropdown menu of Mailchimp Store. If you like, you can select one you already have. This will automatically select the Mailchimp List, since a store is linked to an List/Audience and can only have ONE associated with it.

If you want to create a new store to use in this Magento, please read the part 2 of our tutorial.

Once you have the store selected, you will see changes in the section that says "Account Details", which shows a brief rundown of the status of your Mailchimp Store:

image

It tells you how many customers, products, orders and carts have been synced, whether it is completing the initial sync or if has been completed already. This is very important to tell, since no automation email (such as an Abandoned Cart email) whatsoever will be sent until the initial sync has been completed.

What does this initial sync entails? Basically, that all e-commerce data before you installed the module (customers, products, orders) have been successfully synced, and once that's finished, Mailchimp finds out and starts sending automation emails. Once that initial sync is completed, no matter how many new orders or products are added, Mailchimp continues to consider it is fully synced regardless, so the automation emails should work uninterruptedly.

If you want to sync e-commerce data, read part 3 of this tutorial to find out how to do so:

HEADS UP: if you've already configured your cron in Magento to be up and running, you can skip the last step of this tutorial.

9.Configure your crontab

The last step to ensure the correct functioning of the module is setting up the cron correctly.

What is a cron? Basically, it is a task automation that you set in your system to do a certain task every certain defined period of time. Many Magento modules have their own set of cron jobs that must be placed in order for the module to work. The Mailchimp module has 4: One to add subscribers to the newsletter, one to sync the ecommerce data, and one for each to clean the slate.

To set the cron, you can set it automatically or manually.

To set it automatically insert the following command in your terminal inside your Magento's root directory:

php bin/magento cron:install ---force

This command does not exist in version 2.1x, so in case that's the version you are using you must set it manually.

To do that, execute the following command inside your Magento's root directory:

sudo crontab -u filesystemowner -e

To explain, -u is to set the user to whoever is owner of the file system.

The -e option is used to edit the current crontab using a certain text editor.

This will show you the file where you can set the cron jobs to be incorporated by the server.

The format of the cron must look like this template.

# MAGENTO START

* * * * * /usr/bin/php /the/path/to/magento/bin/magento cron:run | grep -v Ran jobs by schedule >> /the/path/to/magento/magento2/var/log/magento.cron.log

* * * * * /usr/bin/php /the/path/to/magento/update/cron.php >> /the/path/to/magento/var/log/update.cron.log

* * * * * /usr/bin/php /the/path/to/magento/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log

# MAGENTO END

Let's explain what is going on here:

The * * * * * is the timeframe in which the main cron job will be executed every since to check if any module (such as Mailchimp) has a cron job to run. Each * represents a different time unit, standing from left to right minutes, hours, days of the month, months, and days of the week (Monday, Tuesday, etc). The * also stands for "every and each of this time unit", so that what * * * * * basically means is "I want this command to be executed every minute of every hour of every day of day the month of every month at every day of the week". It is important to keep this timeframe like this since tampering with it can cause severe errors.

usr/php/bin is the path of the PHP installation your Magento is using to run. In order to accurately determine which it is, execute the following command inside your Magento's root directory:

php --info | grep ini

/the/path/to/magento is the location of your Magento's root directory including it.

cron:run l grep -v Ran jobs by schedule is the command to be executed.

>> /the/path/to/magento/magento2/var/log/magento.cron.log means that the output of the cronjobs will be stored in a log file titled magento.cron.log

Modify the template so that it accurately represents the context of your Magento installation, then copy and paste it in the temp file you're shown, save and exit back to the terminal.

WARNING: Mailchimp for Magento runs its cronjobs every five minutes. While this might tempt you (if it so happens this is the only module you use the cron for) to set the cron to something like 3,8,13,18,23,28,33,38,43,48,53,58 * * * *, DON'T! It's a terrible idea, since the cronjobs are not run every five minutes per se, but every multiple of 5 (0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60). So if you set like shown above, the cron that was meant to run at 0 will be stuck, as every single else, because they never were run at the moment they were meant to.

With this, you're done! Congratulations, you have a Mailchimp Store running in your Magento. Check the following parts of this tutorial to learn more about how to set up your Mailchimp module for proper functioning:

Part 2 explains how to create a Mailchimp Store out of scratch and set it in your module.

Part 3 explains how to start syncing e-commerce data.

Part 4 explains how to setup your email automation for Abandoned Carts.