Integration of Mailchimp Email Marketing in Wagtail Form Builder Pages.
Project description
Wagtail Mailchimp Integration
Integrate Mailchimp in Wagtail Project
Features
- Add a Mailchimp Audience Sign Up Form to your Wagtail Page.
- Benefit: Users can subscribe to your mailing list directly using a form hosted on your website.
- Integrate Mailchimp Audience subscription option to your custom form pages created with
Wagtail Form Builder
- Benefit: You have an event registration page? Why not use it to get subscribers to your mailing list!
Installation
Install from pip
pip install wagtail-mailchimp-integration
Add wagtailmautic
to your installed apps. Make sure wagtail.contrib.settings
and django_countries
is also added.
INSTALLED_APPS = [
...
"wagtailmailchimp",
"wagtail.contrib.settings",
"django_countries",
...
]
Run migrations
python manage.py migrate wagtailmailchimp
Usage
Settings
A Mailchimp settings section will be added to the Settings
section of the Wagtail Admin.
The steps below explain how to add the setup the Mailchimp settings, as shown on the screenshot above
- Click on Settings
- Select Mailchimp Settings
- Add the Mailchimp API Key. See next section on how to obtain the API Key.
- Add an optional default Mailchimp Audience ID. You can follow the steps outlined here
- Save
Obtaining Mailchimp API Key
You need to obtain your API key from Mailchimp. Mailchimp provides a free trial that can get you started if you do not have an account yet.
Below are the steps you can follow to get the API Key on Mailchimp, after logging in:
- Click on your account profile icon
- Select Account & billing
- Click on Extras -> API Key
- Create a new API Key, giving it an appropriate name, for example
CMS Integration
Copy the API key that will be created.
Adding a Mailchimp Audience Signup Form Page
Below is a sample snippet on how to set up a Wagtail page that will render a signup form to allow users signup to your audience/mailing list
# models.py
from wagtail.models import Page
from wagtailmailchimp.models import AbstractMailChimpPage
class MailingListSubscribePage(AbstractMailChimpPage, Page):
parent_page_types = ['home.HomePage']
template = "path_to_template.html"
content_panels = Page.content_panels + AbstractMailChimpPage.content_panels
After running your migrations and adding the Page from the Wagtail Admin Explorer, the editor will look similar to the screenshot below
Under Mailchimp Settings, you have the following fields:
Mailchimp Audience
- This is the Audience you want your users to sign up toDouble opt-in
- Check if you want to have an extra step which includes an extra confirmation step that verifies each email address. You can find More details on double op-tin hereSuccess Redirect Page
- optional Wagtail Page to redirect to after successful submissionThank you text
- Message to show after successful submission, if no success redirect page provided
In your template, the form
context will contain the Mailchimp audience signup form.
<form method="POST">
{% csrf_token %}
{{ form }}
<div class="field">
<button type="submit" class="button submit-button">Submit</button>
</div>
</form>
You can style the rendered form and fields as you like.
Integrating Mailchimp Audience subscription option to your custom form pages
Let's say you have a single-page form that uses Wagtail Form Builder.
You use this to building custom forms for collecting user information, say registrants to a workshop/event. You want to have an option to allow these users to also subscribe to your mailing list.
The screenshot below shows what you aim to achieve - adding an option to allow users subscribe to your Mailchimp audience:
The following snippet shows how you can achieve this:
# models.py
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import InlinePanel
from wagtail.contrib.forms.models import AbstractFormField
from wagtail.models import Page
from wagtailmailchimp.models import AbstractMailchimpIntegrationForm
class FormField(AbstractFormField):
page = ParentalKey('SampleEventFormPageWithMailingListIntegration', on_delete=models.CASCADE,
related_name='form_fields')
class SampleEventFormPageWithMailingListIntegration(AbstractMailchimpIntegrationForm):
parent_page_types = ['home.HomePage']
template = 'event_registration_page.html'
landing_page_template = 'form_thank_you_landing.html'
content_panels = Page.content_panels + AbstractMailchimpIntegrationForm.integration_panels + [
InlinePanel('form_fields', label="Form fields"),
]
Run your migrations, and create the page from the Wagtail Admin Explorer.
The editor form will look similar to below:
- Select the MailChimp Audience you want to integrate. This is a dropdown of the available audiences from your Mailchimp account
- Set up your custom form fields to match your Mailchimp Audience Signup Form fields. Pay attention to field types with
choices like
Checkboxes
,Radio buttons
andDropdowns
, as the options must exactly match your Mailchimp signup form options.
Go back to the Wagtail Admin Explorer, and locate where the page you created is listed. Hover around the page title, and
you will see a button named Mailchimp Integration
as below
Click it, and it will open a page, where you will match the Mailchimp signup form fields, with the fields in your form.
Make sure you do the matching correctly as this will inform Mailchimp on how to extract your user data from your Custom form.
Once again, make sure for choice options in your page form fields
match exactly
the choice options in your mailchimp audience signup form on Mailchimp
After following the above steps and rendering the form in your template, the Join Our Mailing List
checkbox will be
appended at the end of your form fields.
You can try it to make sure everything works and users are being added to your mailing list before making the page public.
You can find and follow a working sample in sandbox/home/models.py
file
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wagtail_mailchimp_integration-0.1.0.tar.gz
.
File metadata
- Download URL: wagtail_mailchimp_integration-0.1.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3780104e3e3fc7066b103c12f210255d7f85b522e62e29fd569d2518813f38f |
|
MD5 | 645f1f9f7d4c6b7a0c6edaf5783965a8 |
|
BLAKE2b-256 | c85098d2d22288cdd9f9a94f495d3a93d187e950352eda82c67cdc7e182cc732 |
File details
Details for the file wagtail_mailchimp_integration-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: wagtail_mailchimp_integration-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1406c97fe341872c8425320b88379606884644334bd8bdf424ce9a9047cb30c |
|
MD5 | ae9d2ad11eba47a3f40a18cb8ca04808 |
|
BLAKE2b-256 | 30d8341b0a633681e0ffed1a2f178999fbe8902dadb4af5bf115cd5bf8f511f4 |