Mailing lists are the heart of all things MailChimp. Lists allow us to gather a database of email address, and other additional information, by asking people to subscribe to our list or by doing so automatically based on other actions they take within our application. Once subscribed, and added to a list, these addresses can be sent emails. MailChimp lists allow users to manage their own subscriptions, and to easily opt-out as desired.
In this tutorial we'll look at creating our first list in the MailChimp UI. We'll create one for a weekly newsletter on our site. And then we'll install the MailChimp Signup module and use it to create a simple form that allows users to subscribe to our mailing list.
The MailChimp Signup module can be used to create a page with a sign up form on it by specifying the internal path for the new page and choosing which list, or lists, the sign up form should allow a user to subscribe to. In addition, you can also create a sign up form as a block. These blocks are then available to place into any region on your site via the Drupal block administration screen. This gives you a lot of flexibility when it comes to placing sign up forms. Learn more about placing blocks on your site in the Working with Blocks in Drupal 7 video lesson.
Sign up forms created using the MailChimp Signup module will work equally well for anonymous and authenticated traffic. These are a great substitute for the copy/paste HTML forms that MailChimp gives you, with some distinct advantages, like for example keeping the labels of fields up to date if they change in MailChimp without having the copy/paste a new version of the HTML form.
By the end of this tutorial you should be able to create a MailChimp list and allow people to subscribe to that list via your Drupal site.
Further your learning
- When you create a list in MailChimp you provide some default configuration for that list. Where do you change those default settings?
- Which of the MailChimp project's sub-modules are required to be able to create a form that will allow visitors to subscribe to a MailChimp list? (Hint: there are 2 of them).
- What are the display modes available for a signup form created in Drupal? How do they differ?
- Further exploration: Can you add an “Interest group" to your MailChimp list and then have it displayed on the subscription form in Drupal?
Additional resources
One of the main advantages of using the MailChimp module to integrate Drupal with MailChimp is that you can allow users of your site with a Drupal account to manage their MailChimp subscriptions right through the Drupal user interface. In this tutorial we'll look at adding a MailChimp Lists field to Drupal's user entity type and then configuring that field so that we can allow users to subscribe/unsubscribe from a MailChimp list by signing in to their account. We'll also look at how we can allow users to opt-in to a MailChimp list when they register for a new account on our Drupal site.
The MailChimp Lists module is super flexible, and allows you to create a relationship between any fieldable Drupal entity and a list in MailChimp. While we're going to be using the module exclusively with user entities there are a lot of other options available. Basically, any entity with an email address can be subscribed to a list by adding the MailChimp Lists field to the entity type, choosing the list that subscriptions should be added to, and telling the field which other property, or field, on entities of this type contains a valid email address.
By the end of this tutorial you should be able to configure your Drupal site to allow users to manage their MailChimp subscription from within Drupal. As well as allow new users to opt-in to your mailing lists when they sign up for an account.
Further your learning
- Why does the MailChimp Lists module use a Drupal field API field to track subscriptions?
- Can you describe the primary difference(s) between allowing users to subscribe via the MailChimp Lists module, and allowing users to subscribe via the MailChimp signup module?
- Further exploration: What happens if you delete the account of a user who is subscribed to a MailChimp list?
- Further exploration: Can you create a new node type that can be subscribed to a MailChimp List? Give a use case for doing so.
Additional resources
- MailChimp Lists module documentation (drupal.org)
MailChimp allows us to collect additional information about contacts that are subscribed to a list. Similar to Drupal's Field UI you can add any number of new data points, called merge fields, to a contact in MailChimp. In this lesson we'll look at how to configure merge fields in the MailChimp UI, and then demonstrate how to synchronize the value of a field in Drupal with the MailChimp merge field. This will allow us to create first and last name fields in Drupal that keep the contacts information up to date in MailChimp.
Then, we'll install the date and Token modules, and add a Birthday field to our Drupal user entities. This will allow us to look at some of the more complex configuration options available when merging field values in MailChimp. By checking the advanced option on the form for configuring the mapping of Drupal field values to MailChimp merge fields we can allow users to use Drupal 7 tokens. This opens up all kinds of new options for massaging the data within Drupal a little before sending it to MailChimp so that we can match the format that MailChimp's API expects the data to be in.
For example, we’ll use tokens to customize the format of a Drupal date field, which stores its value in the database using ISO Date format, so that it matches the MM/DD
format that MailChimp expects, using a token like the following: [user:field-birthday-iso:custom:m]/[user:field-birthday-iso:custom:d]
If you're using the advanced field mapping form I highly recommend that you also install the Token module. The MailChimp module provides integration with the Token module’s UI for browsing the list of available tokens, making it much easier to create complex mapping patterns.
By the end of this tutorial you should be able to add additional merge fields to a MailChimp list and keep the content of those fields in sync with fields from a Drupal user account.
Further your learning
- What is the use case for merge fields?
- List the three merge fields that are added to every MailChimp list by default? Which of these is required, and why?
- When you are configuring the mapping between a Drupal field and a MailChimp merge field using the select list interface the list is populated with a variety of options. Where do these options come from, and what do they represent?
- Further exploration: Can you setup Drupal to collect a users address/location and then merge that data into MailChimp using a MailChimp address merge field?
Additional resources
Before you start sending email newsletters to your mailing list, it's a good idea to have a plan, set some goals, and understand what you're trying to accomplish. In this tutorial, you'll get a quick primer on email marketing and the things you can do to ensure your campaigns are successful.
I’m not an email marketing expert by any stretch of the imagination. But there are lots of suggestions in here that will help you further your own research into creating successful campaigns, as well as some good ideas about where to start. If you’ve never planned an email marketing campaign, then this tutorial is for you. If you’re an experienced veteran, there may be some good refreshers in here. You can also skip ahead to the next tutorial and start sending emails.
Further your learning
- List three things you should do as part of the copy editing/review process every time you send a campaign.
- What are some things you can do to prevent your emails from being labeled as SPAM?
- Further exploration: Write a draft set of guidelines for you or your team to follow when preparing to send a new email marketing campaign.
Additional resources
There are two ways you can send an email to a MailChimp list: through the MailChimp UI, or via Drupal. In this tutorial we'll look at using the MailChimp UI to send an email campaign to our mailing list. We'll also use MailChimp to segment an existing mailing list into smaller, more targeted, groups to send a campaign to, allowing us to be more effective with targeting those users on our list that we know will care about a specific announcement.
The MailChimp UI for composing and sending an email campaign is awesome, and has some great tools for content creators. In this tutorial we'll choose a a template, draft a newsletter, send a test email, and then finally send the real thing.
After that, we'll look at how we can use the values of the merge fields associated with subscribers in our list to segment the list and send a campaign to just the people in a specific location. Or example use case is that our hypothetical ice cream store has physical locations in Aspen, Carbondale, and Glenwood Springs. When a user signs up for our mailing list they can optionally let us know which store, or stores, they frequent. Then, when our Aspen store has its two year anniversary, and we're going to offer specials at just that store for the weekend, we can email our list and let them know. Rather than spam the entire list, we can target just those people who have identified that they frequent the Aspen location. Pretty cool.
By the end of this tutorial you should be able to send a new email campaign from within MailChimp to your list of subscribers, as well as know how to leverage list segmentation.
Further your learning
- Can you give two example use cases for list segmentation?
- What are the different ways that you can preview an email campaign in the MailChimp?
- What are merge tags in MailChimp?
- Further exploration: Explore the various templates and themes provided by MailChimp. Are there any that would serve as a good starting point for your email campaigns?
Additional resources
In an earlier tutorial, we looked at sending emails from the MailChimp UI. Now let's look at sending a campaign to our MailChimp list via Drupal. In this tutorial, we'll enable the MailChimp Campaigns module, and send a campaign through the Drupal UI. We'll also talk about the various advantages and disadvantages of doing it this way vs. via the MailChimp UI. The big win is that your site's administrators don't have to know anything about MailChimp, instead they can just do all their work right in Drupal. There is also the ability to use a token-like syntax to include the content of existing nodes on your Drupal site rather than copy/pasting their content into MailChimp.
By the end of this tutorial, you should be able to send a MailChimp email campaign via Drupal, and understand the advantages and disadvantages of this approach in order to help you decide which method is best for you.
Further your learning
- What additional permission(s) does the MailChimp campaign module add, and what do they allow?
- What are the two primary advantages to sending email campaigns through the Drupal UI?
- Explain the use case for the MailChimp text format. What does it allow that other text formats do not?
- Further exploration: Can you use Views to create a list of archived/sent campaigns that is available to the public on your site?
Additional resources
The MailChimp Lists module provides integration with the Views Bulk Operations module. This integration allows site administrators to create a view, and then use the contents of that view to create a new segment for a list in MailChimp. This is pretty cool because there are a lot of things that Drupal knows about your users that MailChimp doesn't. So we can begin to use the powerful Views module to create list segments that might otherwise be impossible to generate.
In this tutorial we'll install the Views Bulk Operations module (VBO) and it's dependencies. Then, we'll create a view of users on our site that can be filtered based on the user's role. Finally, with the VBO integration, we can use this to create a new segment in our mailing list for just users on our site with a specific role.
By the end of this tutorial you should be able to create a new list segment in MailChimp based on the content of a view in Drupal.
Further your learning
- What does the Views Bulk Operations module do?
- Can you list three examples of list segments you could create with the information in Drupal that you couldn't create directly in MailChimp?
- Further exploration: Can you create a view that allows administrators to create a new MailChimp segment that contains only users who logged in to your site in the last month?
Additional resources
One of the best features of MailChimp is its awesome template creation tools, and their ability to allow anyone to create beautiful email templates. Unfortunately, the templates created in MailChimp are not supported by the Drupal MailChimp Campaign module without a little extra work. In this tutorial we'll take a look at creating a template in MailChimp using their drag and drop template creator. Then, we'll walk through the extra steps required in order to have these custom templates you create available in Drupal when using the MailChimp Campaigns module to send a campaign.
In addition to just making the templates appear in Drupal, we’ll also want to declare which regions in the template should be editable within Drupal. So we’ll use the mc:edit=""
HTML attribute in our template. Any DOM element we add this attribute to will become a section, which content creators on our Drupal site can insert content into.
By the end of this tutorial you should be able to create a custom email template in MailChimp and know how to make it show up as an option in Drupal. You should also understand how to edit your template's code to include editable regions that Drupal can display and editors can use.
Further your learning
- Why do you need to export a template to HTML and then re-import it?
- What does the custom `mc:edit` attribute do in an HTML email template?
- Further exploration: Can you create a new template that is a 2x2 grid, and make that template available to someone creating an email campaign in Drupal?
Additional resources
MailChimp offers the ability to set up RSS-based email campaigns that automatically send daily, weekly, or monthly emails to your subscribers based on the content of an RSS feed. In this tutorial we'll look at creating an RSS feed of ice cream flavor updates in Drupal using Views, and then configuring a campaign in MailChimp to use the content of that RSS feed to send a daily email to anyone subscribed to our Flavor of the Day list.
I'm not going to cover creating an RSS feed in Views during this tutorial. Instead I assume that you've already created the necessary feed on your own site. If you’re not familiar with creating feeds with Views check out this video tutorial, Creating Views Attachments, which demonstrates how to create an RSS feed in Views.
In order for your RSS-based campaign to work, your Drupal site needs to accessible to the web, so that when MailChimp tries to read the content of your RSS feed, it can do so. If you're just testing this out, you can use a tool like ngrok.com, or just create a dev site on Pantheon or Acquia to play with.
By the end of this tutorial you should be able to create a campaign in MailChimp that pulls data from an RSS feed in Drupal and sends an email with that data to your mailing list on a regular basis.
Further your learning
- Give an example of a use case for RSS-based campaigns that would be useful for your users.
- What do you need to do on the Drupal side of things in order to create an RSS-based campaign?
- Can you send an RSS-based campaign to a segment of a MailChimp list?
- Can you test an RSS-based campaign with a Drupal site on your localhost?
- Further exploration: Can you add an RSS feed to a regular campaign template? Hint: *|RSSFEEDBLOCK|*
Additional resources
- Creating Views Attachments, covers how to make an RSS-feed in with Views
- MailChimp documentation for creating an RSS-driven mail campaign
- MailChimp's Merge Tags for RSS-driven campaigns
- MailChimp's RSS item tags
MailChimp has the ability to trigger a webhook, or push notification, whenever someone takes an action on their MailChimp account. For example, when someone unsubscribes from your mailing list by clicking the link in their email, instead of logging in to their Drupal account and using the checkbox provided there. Drupal, can be configured to listen for these webhook notifications, and take action whenever one is received. This is particularly useful for allowing Drupal to update cached data about subscribers in real time.
If you're using MailChimp with Drupal I highly recommend configuring the webhook integration. It helps to keep the information contained in Drupal and in MailChimp in sync. And, it is super easy to do. In addition, whenever a notice is received, the MailChimp module triggers hook_mailchimp_process_webhook()
, documented in mailchimp.api.php
. This allows your custom modules to respond to someone subscribing or unsubscribing from your mailing list in any way you want.
In this short tutorial we'll look at how to enable web hooks for your lists in MailChimp, and then talk about why this is an important feature to enable.
In order for the webhook integration to work your Drupal site needs to be accessible to the internet so that it can receive HTTP posts from MailChimp's API.
By the end of this tutorial you should be able to configure Drupal to respond to MailChimp webhook notifications.
Further your learning
- Why is it important to configure the MailChimp webhooks?
- Can you give an example of an action that would cause a MailChimp webhook to be triggered?
Using the MailChimp Activity module we can allow site administrators to view activity and statistics for any Drupal account subscribed to our mailing list, or any entity for that matter. In our example we only have user accounts subscribed at the moment though.
Once enabled, and configured, the MailChimp Activity module will display a tab for each user account with details about what emails they have received and whether they have opened them or not. This is a subset of the data that MailChimp collects for us to help analyze the success of our campaigns. It's only a small portion of the data available, but it's nice to be able to see it right in Drupal. It also opens up the opportunity for content creators who have access to Drupal, but not MailChimp, to see how their email campaigns are performing.
In this tutorial we'll take a look at enabling the MailChimp Activity module, configuring it to display the information we want, and the permissions that it provides to determine who is allowed to view these statistics on your Drupal site.
By the end of this lesson you should be able to navigate to the "MailChimp Activity" tab for any user of your site and get a report of their actions on your mailing list.
Further your learning
- Why would you want to show a user's MailChimp activity in Drupal instead of MailChimp?
- What new permission(s) does the MailChimp Activity module add and what do they allow?
- Further exploration: What happens if you create a MailChimp Activity entity for a entity type + bundle that doesn't have a MailChimp Lists field attached?
Before we set up a multisite we need to understand how Apache and Drupal work together to deliver the site we intend. In this lesson we'll look at the documentation for Drupal multisites, and then discuss the way you need to set up your Drupal directories. We'll also review the workflow that Apache and Drupal go through to get the correct site displaying in the browser.
Additional resources
Multi-site - Sharing the same code base (drupal.org)
In this lesson we'll be building a simple university site, udrupal.com, with different areas, each with their own website: the main site, a news site, and an alumni site. The news site is simply a subdomain of the main domain name, news.udrupal.com, and the alumni site actually has its own separate domain name, udrupalalumni.com. To get this done, you're going to learn how to confirm the DNS is working for the domain names. That is, that they are currently pointing to the right server. Then we're going to configure an Apache vhost on our server so that Apache knows where to find our Drupal code base. We'll finish things up by installing our main Drupal site, udrupal.com.
Additional resources
With our domains and Apache configuration in place, we need to make sure all three sites can be installed at the different domains by creating our multisite directories in the sites folder. In this tutorial, we'll create the necessary Drupal site directories and settings files for the three sites so they are all running smoothly, check the domains and install the other two sites, and wrap up by changing the theme on the alumni site.
Before we get started, you should make sure you have two empty databases created for the two new sites we'll be installing.
In this tutorial we're going to be working directly on a server using the command line. You can feel free to use a GUI interface for your site, like an SFTP app or just your local machine file browser and editor apps. If you want to brush up on using the command line, you can check out our free Command Line Basics series.
If we want to do development work on the university multisite, we need to do a few things to have this run smoothly in a local development environment with all of those URLs. The sites.php file is going to let us define aliases for the site configuration folders in /sites
. In this tutorial we'll explain why local development with multisite is tricky, and how to get it set up properly.
Additional resources
example.sites.php (api.drupal.org)
Drush is a really great tool for managing your Drupal site quickly and easily. If you don't already know about Drush, you should definitely check it out. When working with a multisite installation though, Drush can get confused if you don't give it all the information it needs. In this lesson we'll walk through how to use Drush properly with a multisite installation, covering both how to manage just an individual site and how to work with all of your sites at the same time.
One of the best ways to improve both the speed, and relevancy, of search results for a Drupal site is to stop using the Drupal core search module and start using Apache Solr. Solr is a Java-based application that provides an API for interacting with Apache Lucene via HTTP to facilitate the creation of excellent applications for performing full-text content searches, with a special focus on internet-based search applications. The quick pitch for why you should use Solr is it's insanely fast, especially when compared with Drupal's default Search module, and it can be scaled to handle millions of search queries per second and huge piles of data.
Since Solr is a third party application we need a way to bridge the gap between Solr and Drupal. Really, there are two parts to this puzzle: getting the data out of Drupal and into Solr so it can be processed and indexed, and passing a search query from Drupal to Solr in order to retrieve, and display, search results. For that, we'll use the Search API module, and the Search API Solr module.
In order to demonstrate a real-world use case we'll pretend that we're the owner of a website that contains a database of fish species. As the database has grown over time we've begun to feel the limits of Drupal's MySQL full-text search and want to improve our search tools. Using Solr will allow for better matches in full-text search, faster searches, and a lot of additional functionality like partial word matches, spell checking, facets, and more.
In this series we'll cover:
- What Apache Solr is and why you should consider using it
- Installing Solr and configuring it to work well with Drupal content
- The contributed Search API module
- The contributed Search API Solr module
- Configuring Drupal to send content to Solr for indexing
- Retrieving search results from Solr and displaying them in Drupal on both a stand-alone page and with the Views module
- Using Solr field boosting to influence result relevancy
- Using the contributed Facet API module with Solr to allow for faceted search results
- Configuring stop words, synonyms, and promoted search results in Solr
This series is for anyone that wants to improve the quality of the search functionality of their Drupal-powered site. There is some system administration required to install Solr, but it's pretty straightforward. Almost everything else is done via configuration in Drupal's, or Solr's, user interface and by editing simple XML configuration files. So, no PHP, or module development experience required. We do however assume that you're already familiar with basic Drupal administration.
Additional resources
Apache Solr is a world class search application built on top of the Lucene indexer. Before we start trying to integrate Solr with Drupal lets talk about what Solr is, and what makes it so good, as well as how Solr differs from the Drupal core database-backed Search module. This tutorial is a short presentation explaining Solr, Lucene, and things to consider when choosing Solr as a search technology.
Lucene is an open-source search indexer written in Java and governed by the Apache foundation. It is the underlying library that handles storing indexed content, and does so in a way that makes it extremely flexible. By treating each record as a document made up of any number of different fields Lucene is capable of storing just about anything you throw at it, as long as the resource can be broken up into fields and the textual data can be extracted from those fields. This makes it a good choice for indexing web based content where you might be dealing with HTML, PDF, XML, Microsoft Word, and all kinds of other document formats.
Solr, is an HTTP API for interacting with the Lucene application that makes it easier to create custom search applications. Like Lucene it is also open source, written in Java, and governed by the Apache foundation. Solr's extensive use of XML configuration files allows you to modify almost everything about how Solr works without having to write any Java. This makes it a great choice for anyone that's familiar with PHP but doesn't have Java experience.
When compared with Drupal core's Search module, or any MySQL full-text search tool, Solr has some distinct advantages. Including:
- Best-in-class stemming and tokenization
- Scalability; it's designed to scale both vertically and horizontally as needed
- Built-in support for facets, geospatial searches, and other advanced query options
In addition to these advantages, using Solr for your search can dramatically improve your Drupal site's performance by eliminating costly full-text queries, which can quickly turn MySQL into a bottleneck for sites with even a modest amount of content.
By the end of this tutorial you should be able to explain the advantages that Solr provides over Drupal core's search module and why it's a good choice for building ultra-fast, and accurate, search applications.
Additional resources
When it comes to integrating Apache Solr with Drupal there are currently two different modules that can be used, Search API, and the Apache Solr module. While both are valid options, for this series we've chosen to focus on the Search API module because amongst other things it's generally more flexible, and based on conversations with people in the community who are working on Solr integration it is currently seeing more focused development efforts and will likely superseded the Apache Solr module sometime in the future.
This tutorial provides some background information on the Search API module and why we've chosen to use it. We'll look at how the Search API module bridges the gap between Solr and Drupal, and explain some of the commonly used terms we'll encounter in the module's UI and codebase.
By the end of this lesson you should be able to explain the Search API module's terminology, requirements, and position in the Drupal ecosphere, as well as be able to make a good case for why someone should choose the Search API module as a starting point for creating better search tools in Drupal.
Additional resources
Before we can start building a search application we need some sample data that we can index and use for testing, not to mention a site we can use to test this all out on. In this tutorial we'll walk through installing Drupal 7 and importing some sample data.
In order for this to work I built a Drupal 7 site with a content type named Fish, and then imported a whole bunch of descriptions of various fish from Wikipedia. You should be able to use the provided database dump in order to get up and running with a sample Drupal site pre-populated with some sample data.
If you're not planning on following along and building the fish finder application in the Search API and Solr series, or are planning on implementing Solr search on your own site instead you can probably skip this tutorial. Just note that the rest of the tutorials in the series assume you've got a working Drupal 7 site with some content.
By the end of this tutorial you should have a working Drupal 7 site with sample content running on your localhost for playing with while watching the rest of the series.