Jump to content

Subscribe To Mailchimp


daniels
 Share

Recommended Posts

This is a lightweight alternative to other newsletter & newsletter-subscription modules.

You can find the Module in the Modules directory and on Github

It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.

This module fits your needs if you...

  • ...use Mailchimp as your newsletter / email-automation tool
  • ...want to let users subscribe to your newsletter on your website
  • ...want to use your own form, validation and messages (with or without the wire forms)
  • ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms)
  • ...like to subscribe, update, unsubscribe or delete users to/from different lists
  • ...like the Mailchimp UI for creating / sending / reviewing email campaigns

*I have only tested it with PHP 7.x so far, so use on owners risk :)

EDIT:

Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  ?

If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!

  • Like 15
Link to comment
Share on other sites

I made it work with PHP 5.x just by changing one line.

SubscribeToMailchimp.module - Line 23 - before:

public function subscribe(string $email, array $data = [], string $list = "") {

SubscribeToMailchimp.module - Line 23 - after:

public function subscribe( $email,  $data = [],  $list = "") {

This works without any problems so far.

  • Like 3
Link to comment
Share on other sites

Hey, thanks for the feedback @giannisok and for the solution @wbmnfktr.

I have just updated to version 0.0.2 with the ability to unsubscribe and delete users. I also removed the 'string' type declarations, hope it works now with your PHP version @giannisok .

When I have the time I'll change my dev machine setup, so I can test with different PHP versions. But since I use Valet, I think I can only downgrade to php5.6 anyway.

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

Hi, Daniels,

thanks for sharing this! I have just ran into an issue while testing:

After successful initial subscription of an user, I could unsubscribe him again, but after that no more subscription of the same user would work.

Is this due to a limitation of Mailchimp?

Link to comment
Share on other sites

Hey @Mikel, seams like with the original mailchimp subscribe forms, it is possible (and in my opinion it should be) to resubscribe. I will have a look on that! Thanks for the input. 

 

Meanwhile (e.g. for testing) you can use the delete method to completely delete and resubscribe a user. That is working for me with the current version.

  • Like 2
Link to comment
Share on other sites

Just now, jacmaes said:

@Mikel Pretty sure you can’t subscribe to a list you previously unsubscribed from. It’s a Mailchimp “feature”. 

Ok, thanks, I was not sure, so, in my special use case it will be better not to unsubscribe the user, but to delete him.

So if he likes to subscribe again in the future, he will get added again. 

Link to comment
Share on other sites

Just now, daniels said:

Hey @Mikel, seams like with the original mailchimp subscribe forms, it is possible (and in my opinion it should be) to resubscribe. I will have a look on that! Thanks for the input. 

 

Meanwhile (e.g. for testing) you can use the delete method to completely delete and resubscribe a user. That is working for me with the current version.

Thanks, thats just what I implemented and testet this moment. Working flawless :-)

Link to comment
Share on other sites

Hi @daniels,

many thanks for that great module! As a little helper, I added a checkbox to the modules config page that can test the current settings.

If you don't mind, I sent you a pull request.

Spoiler

screen_mc_01.jpg.2942d7d8e600e4daffe012203cd77e63.jpg

screen_mc_02.thumb.jpg.2126b3c5a773e0a2364b89ef9a86f053.jpg

screen_mc_03.thumb.jpg.72d7f8a7ecf98c847901d8f2d3da8d64.jpg

screen_mc_04.thumb.jpg.816fadabfb86e4b59baa044490efc5f5.jpg

 

  • Like 3
Link to comment
Share on other sites

@horst this is awesome!! Thank you, I will totally merge it in. It looks really great and is super helpful. I didn't even know, that this is possible via the module settings ?

I also had a look at the issue mentioned by @Mikel . To resubscribe users (and I think this is indispensable) I had to add a getStatus method and change how the subscription method works. Now if a user resubscribes, he will get the double-opt-in mail again.

I made a PR for this too, maybe you can take a look. I will merge both PRs than to version 0.0.3 (and hopefully don't mess it up .... :D) later this week. 

https://github.com/danielstieber/SubscribeToMailchimp/pull/2

  • Like 3
Link to comment
Share on other sites

Thank you for the modules. it's so great!
I don't know if some one have already try but, Is it possible to integrate this in the loginRegister module?
I try to looking in the validation process of the module but I think at moment need make an hook to ___processRegisterForm, is it correct? If yes How I can do the hook?

thank you.

Link to comment
Share on other sites

I've created an issue regarding features of MailChimp, that currently can't be used with the module. Also I'd like to make it more flexible, if Mailchimp roles out new stuff.

My question to you:

Do you currently use this MailChimp features or would like to have it in the module?

- Groups (Interests) (Setup up 

- VIP

- manually fill IP, Language and/or Location

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...

How can I use this moule for all users who are saved with a specific category?

I'm not sure which Class and method need to use and also maybe I not get the correct fields.

wire()->addHookAfter('Pages::saved', function($event) {
	$page = $event->arguments(0);

	if($page->template == "user"){

		if ($user->hasRole('login-facebook')) {

			$mc = $modules->get("SubscribeToMailchimp");
			$email = $page->email;
			$subscriber = [
				'FNAME' => $page->pad_firstname,
				'MMERGE4' => $page->$country_title,
			];
			$mc->subscribe($email, $subscriber);

		}

	}

});

 

 

 

Link to comment
Share on other sites

Hey @MarcoPLY ,

not sure if I get it right, but do you want to add user to specific categories?

In the API naming, groups are called 'interests'. You can add them as additional parameters as in the example below.

To get the interest IDs is a little pain-in-the-ass but I'll try to guide you:

1. Go to  https://api.mailchimp.com/playground/ and enter your API key.

2. Click on 'Lists' and choose 'interest-categories' from the 'Subcategories' of your related list.

3. Choose 'interest' from 'Subcategories' of your related interest category

4. Now you can click on each interest and you'll get the id which should be the ID that you have to use in the 'interests' part of the example below.

 

Please let me know if this works for you! When I find some time, I'll add a way to get these ids in the module Settings in PW admin.

 

Example from the docs:

// Work with additional parameters (not merge_field values!)
$mc->subscribe('john.doe@example.com', NULL, NULL, [
	'language' => 'en', // find language list here: https://kb.mailchimp.com/lists/manage-contacts/view-and-edit-contact-languages#Language-Codes
	'vip' => true, // boolean vip status
	'location' => [ // geo location based on lat/log coordinates 
		'latitude' => '48.8722344',
		'longitude', => '2.7736192'
	],
	'interests' => [ // subscribe user to interest categories / groups based on group id
		'32fec3561e' => true, 
		'63mel4395m' => false
	]
]);

 

Link to comment
Share on other sites

Hi @daniels, thank you for your reapply! eheh, yes you have right. I explain better what I have to do

In addition to the  loginRegister module I also use the registration via Facebook. This registration bypasses the registration form and don't send the data to mailchimp. 

I thought about making a hook for all the users that are registered, regardless of the method. Then use Pages::saved (I'm not sure it's right) and pass data to mailchimp when the user's page is created.

But the attempts I tried don't work, I'm probably wrong the way I access the data. Do you know how can I create this action, to send the data to mailchimp when the users page it's created?

(Sorry, I have thought just now that maybe this was a question to put in general)

Link to comment
Share on other sites

No worries ? I suggest testing the subscribe function in a normal doc with test data. If this works (which should :)) try to dump your real data wherever you want to implement the subscription. If you can var_dump the right data there, you should be able to perform the subscription there ?

Let me know if you have questions regarding the module itself or run into errors there.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...