MailChimp integration

We want to use an API to integrate a checkbox to opt in for emails during the Laddr Register page to go to my master brigade mailchimp list; I have only 3 required fields - first name, last name, email - which are already part of the laddr registration template.

Any help or special instructions for that?

I’ve added a MailChimp API wrapper to v1.laddr.io since this is a common request, and created a commented-out example for the registration config file showing how someone could be added to a MailChimp list automatically after registering

You can find and open templates for all the files referenced below under the _parent file tree and just hit save to create local copies that override the inherited templates.

Step 1: Configure MailChimp API key

Create the file php-config/RemoteSystems/MailChimp.config.php and enter:

<?php

RemoteSystems\MailChimp::$apiKey = 'YOUR_API_KEY_HERE';

Replace YOUR_API_KEY_HERE with a MailChmip API. You can obtain one from the Extras > API Keys page under your account page on MailChimp’s website.

Step 2: Activate registration hook

Laddr v2.1.0 and older:

Assuming your laddr instance is up-to-date and someone has loaded your registration page recently, you’ll find the following sample within your _parent tree at php-config/Emergence/People/RegistrationRequestHandler.config.php:

<?php

namespace Emergence\People;

#RegistrationRequestHandler::$onRegisterComplete = function(User $User, array $requestData) {
#    // this hook is run after a new user acconut has been registered (the user is waiting though so keep things moving!)
#
#    // add new user to a MailChimp list
#    \RemoteSystems\MailChimp::call('lists/subscribe', [
#        'id' => 'YOUR_LIST_ID_HERE',
#        'email' => [
#            'email' => $User->Email
#        ],
#        'merge_vars' => [
#            'FNAME' => $User->FirstName,
#            'LNAME' => $User->LastName
#        ],
#        'double_optin' => false,
#        'replace_interests' => false,
#        'send_welcome' => false
#    ]);
#};

Uncomment the commented-out block of code that creates a subscription in MailChimp. If you’re using the web-based IDE you can select the commented-out lines and press CMD+7 to uncomment them all. Be sure to replace YOUR_LIST_ID_HERE with the unique id for the list you want to subscribe users to automatically. It can be found on the MailChimp website under Settings > List name & defaults within the list page.

Laddr v2.2.0 and newer

You’ll find a similar block of code in event-handlers/Emergence/People/RegistrationRequestHandler/registerComplete/mailchimp.php instead

1 Like

Few months back, I remember following your instruction here and I was successful integrating the mailChimp API such that any new registration on the staged website (http://cfd-staging.poplar.phl.io/) get automatically updated to your List (Code For Durham – Master) on MailChimp.

I even went ahead and tested the staged website by registering myself and I could see my details updated to your List on MailChimp. Success!

Followed by which I exported the staged site as a zip file.

Could you throw some light on how to move this to the live site? Or would you instead recommend repeating the same steps (that I followed in stage site) to the live site directly?

Thanks in advance!

Regards,
Jestin

@jestinjs sorry for the slow reply here

Your live site pulls files automatically from your staging site, you should not write anything to the live site unless your intention is to create an “override” on your live site – which should only be in the rare circumstance that you want your live site to vary from your staging site. One common case for overriding files from your live site is having a php-config file for MailChimp containing different API configuration so you could have your staging site using a test list. If you don’t mind testing on staging against the same list you use on the live site then you should not save anything directly to the live site.

If you’ve made changes to files on staging that the live site has already pulled down and cached, you’ll need to use the pull tool to explicitly update your live site. See Develop on staging and push to production

@chris Thank you for the overview. As instructed, I went ahead and ensured all changes in the staging site is working. Followed by which I used the pull tool to explicitly update the live site. However, now when I click on the registration/sign-up botton on the CfD website, it throws an error.

Parse error: syntax error, unexpected '}' in /emergence/sites/cfd-live/data/918 on line 22

Please advise how to fix the same on the live site!

Regards,
Jestin

Hi @chris, I noticed that the registration/signup page on the CfD website is working now. However, I guess the MailChimp integration didn’t go through!

Did somebody restore the site back? So do we need to go about the MailChimp integration steps again on the staging site and push it to the live site?

Let me know,

Regards,
Jestin

@jestinjs there was just a minor syntax error in the config file, I commented out the mailchimp configuration because a chunk of it was cut out if I recall correctly. You should go ahead and follow the MailChimp integration steps again, and just use an incognito browser window to keep an eye on the registration page while you work on the configuration in your main browser. Any syntax errors like that that come up should be easy to fix just by following the line numbers if you see it right away. Make sure you can complete a full registration though when you’re done and verify that the address gets added to mailchimp