daniels

Subscribe To Mailchimp

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:

I've updated the module to 0.0.4. I removed the instructions from this forum, so I don't have to maintain it on multiple places. Just checkout the readme on github 🙂

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

  • Like 14

Share this post


Link to post
Share on other sites

Thanks for sharing Daniels!

It would be a good idea to make it backwards compatible with PHP 5.5 so that it works on older installations otherwise mention that it has PHP 7 dependency.

Regards!

  • Like 2

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
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. 

Share this post


Link to post
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 :-)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Thank you for the feedback  @MarcoPLY 

I've not worked with loginRegister and hooks yet. If you or someone finds a solution, please share it in here 🙂

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
25 minutes ago, daniels said:

manually fill IP, Language and/or Location

Not IP, but language / gender + location

  • Thanks 1

Share this post


Link to post
Share on other sites

I've just rolled out version 0.0.3 - checkout the changelog .

You should be able to update without any changes in your code. 

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

Updated to version 0.0.4  - checkout the changelog .

The Github user ml-s fixed a major issue, where you could not use a Mailchimp core function, the ADDRESS mergefield.

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

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);

		}

	}

});

 

 

 

Share this post


Link to post
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
	]
]);

 

Share this post


Link to post
Share on other sites

Ok @MarcoPLY , I think I got your question completely wrong 😄 I leave my reply anyway if someone needs it one day...

Have you tried to var_dump the subscriber? What do you get there?

Is the $ before country_title intentional?

  • Like 1

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Hello,

my first time using this module and need some help.

I created a new list an setup everything in module settings. But not sure how to create a subscribe form on frontend of my site. 

Any help is appreciated

Thank you

R

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Another little admin helper module...
      Template Field Widths
      Adds a "Field widths" field to Edit Template that allows you to quickly set the widths of inputfields in the template.

      Why?
      When setting up a new template or trying out different field layouts I find it a bit slow and tedious to have to open each field individually in a modal just to set the width. This module speeds up the process.
      Installation
      Install the Template Field Widths module.
      Config options
      You can set the default presentation of the "Field widths" field to collapsed or open. You can choose Name or Label as the primary identifier shown for the field. The unchosen alternative will become the title attribute shown on hover. You can choose to show the original field width next to the template context field width.  
      https://github.com/Toutouwai/TemplateFieldWidths
      https://modules.processwire.com/modules/template-field-widths/
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.1.16
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
    • By MoritzLost
      UPDATE: I have published a stable version of this module!
      Discussion thread:
      Github: https://github.com/MoritzLost/TextformatterPageTitleLinks
      ---
      Hello there,
      I'm working on a tiny textformatter module that searches the text for titles of other pages on your site and creates hyperlinks to them. I'm not sure if something like this exists already, but I haven't found anything in the module directory, so I wrote my own solution 🙂
      It's not properly tested yet and is still missing some functionality I would like to implement, so at the moment it should be considered in BETA. Features include limiting the pages that will get searched by template, and adding a custom CSS class to the generated hyperlinks. As I'm writing this I noticed that it will probably include unpublished and hidden pages at the moment, so yeah ... it's still in development alright 😅
      You can download the module from Github:
      https://github.com/MoritzLost/TextformatterPageTitleLinks
      There's some more information in the readme as well.
      Anyway, let me know what you think! I'm happy about any feedback, possible improvements or ideas on how to improve the module. Cheers.
    • By blad
      Hi guys!
      I just uploaded a module to explore files based on elFinder. By default it will show the "Files" folder.
      Screenshots:

      Video:
       
      To do:
       More options To fix:
       The function of rotating or scaling an image fails  Image editors V 1.01 (view issue)
      Fixed the bug working with the Multi-Language support ( translation of folders ). Fixed the name of elfinder.en  Github:
      https://github.com/LuisSantiago/ProcessElFinder/
      I hope you like it.
    • By BitPoet
      I'm really in love with FormBuilder, but the one thing missing to match all my end users' expectations were repeatable field groups. Think repeaters, in ProcessWire terms. Our primary application of PW is our corporate intranet, so "lines" of fields are quite common in the forms I build. We have all kinds of request forms where the information for a varying number of colleagues needs to be entered (from meal order to flight booking request) and where it is simply impractical to send a form for each, and I don't want to clutter my forms with multiple instances of fields that may only get used ten percent of the time.
      That's why I started to build FormBuilderMultiplier (link to GitHub).
      What it does:
      Adds an option to make a regular Fieldgroup repeatable Lets you limit the number of instances of a Fieldgroup on the form Adds an "Add row" button the form that adds another instance of the Fieldgroup's fields Adds a counter suffix at the end of every affected field's label Stores the entered values just like regular fields Makes the entered values available in preview and email notifications Supports most text based fields, textareas and selects (really, I haven't had enough time to test all the available choices yet) What it doesn't do (yet):
      Support saving to ProcessWire pages (i.e. real Repeaters) I haven't tested all the validation stuff, Date/Time inputs etc. yet, but since I'm utterly swamped with other stuff at work, I didn't want to wait until I have it polished. Any feedback is welcome. There might also be some issues with different output frameworks that I haven't encountered yet. The forms I work with mostly use UIKit.
      Status:
      Still alpha, so test well before using it in the field.
      Known issues:
      When rows are added, the form's iframe needs to be resized, which isn't completely clean yet.
      How it works:
      The Fieldgroup settings are added through regular hooks, as is the logic that adds the necessary field copies for processing the form and displaying previews.
      "Multiplied" field instances are suffixed with _NUM, where NUM is an incremental integer starting from 1. So if you have add two fields named "surname" and "givenname" to a fieldgroup and check the "multiply" checkbox, the form will initially have "surname_1" and "givenname_1" field (I'm still considering changing that to make the risk to shoot oneself into the foot by having a regular "surname_1" field somewhere else in the form less likely).
      When a "row" is added, the first row is cloned through JS and the counter in the fields' IDs, names and "for" attributes as well as the counter in the label are incremented before appending the copies to the Fieldset container in the form.
      To keep backend and frontend in sync, a hidden field named [name of the fieldset]__multiplier_rows is added to the form. Both the backend and the frontend script use this to store and retrieve the number of "rows".
      ToDo:
      Naturally, add the option to store the data in real repeaters when saving to pages. Do a lot of testing (and likely fixing). Make a few things (like the "Add row" button label etc.) configurable in field(set) context. Add a smooth API to retrieve the multiplied values as WireArrays. The mandatory moving screenshot: