DEV Community

Derrick Sherrill for WayScript

Posted on

Create Automated Custom Marketing Campaigns for your Audiences with WayScript

Introduction

Today, it seems like there's software to do everything. When looking for an email marketing solution, you may find yourself being overwhelmed with the huge amount of options available. With dozens of providers, it's hard to visualize a long term solution right away. But why should you? In the beginning, it's important to get a working solution, built on a platform that's ready to grow with you. Then, as you iterate on your solutions, they should become more robust and powerful, fitting your users' needs along the way.

Here at WayScript, we're offering a platform that gives you this unlimited power and customization for your applications while still giving users the ability to create working solutions fast.

In this tutorial, let's look at how easy it is to integrate your different applications together, leverage the power of multiple third party services, to create custom powerful marketing tools.

What's the Goal?

Let's build an application to send out custom emails to specific individuals, who's information is stored in some type of data storage. It seems like several complex interactions, but let's break it down:

  • Retrieve user email data from a database
  • Conditionally select certain users to receive our marketing email.
  • Process user data to write truly custom emails
  • Send our emails using a third party service, like SendGrid or MailChimp

Pretty neat right? Traditionally, you would need to build a pretty robust application to do all of this in the same location. This is where the power of WayScript is evident. Let's get started building this.

If you want to view this script before walking through the tutorial, check it out here.

Pulling Data from our Database

WayScript offers database modules which make it very easy to extract your data, no matter what the storage is. In this example, we'll work with an SQL based database hosted on a heroku server. This is where my application is storing its user data and if the user is subscribed to receive emails from us. In WayScript, this is as simple as pulling that module into a new script.

The SQL module allows us to easily setup our SQL database in WayScript. Once connected, we can begin querying our database with custom conditionals to extract only the specific user data that we want. How cool is that? For any marketer, this is amazing. Why? Because segmenting your users using data, to provide highly targeted ads is music to our ears. The only limit is how much data you have in your database.

For the purposes of this tutorial, I'm just going to query for all users subscribed to the newsletter, but play around with some more advanced SQL queries for your own purposes.

SELECT * FROM app_users where email_subscribed = 1;  

What this will do is allow us to create WayScript variables that we can pass to other modules in our script. It'll look something like this:

Notice how we can import only the columns that are important to us. This will create list type variables in wayscript that we'll be able to loop over to extract the individual values to use.

Processing our Data

In this specific example, we have a problem. In our database we're storing email domains and strings in two different columns. This is likely to make it easier to identify key users by their email domains. Users from high value domains could potentially translate to a higher return on our marketing investment into them. But, this presents a problem for us because we need to create X@domain.com email addresses to use a service like SendGrid.

We can knock this requirement out with just a simple python concatention.

email_beginning = variables['Column_2_Item'] 

email_domain = variables[ 'Column_3_Item'] 

total_email = email_beginning + '@' + email_domain 

variables['email_address'] = total_email  

This is a very simple operation right? But on other platforms this simple fix could present a whole suite of problems. With WayScript, the problem is solved in a few seconds. We're just concatenating the strings we need and passing back the full email address as a variable.

Building the HTML

Okay great! We've gotten the users from a database, conditionally selected the users we're looking to target, and processing their data using a simple python step. Now, we have the ability to create custom HTML depending on any conditional we want. In this tutorial, we'll just send all the users the same HTML file to their email, but it's just as quick to make conditional statements. These conditional statements could be anything, such as "If the user is high priority" followed by the correct action such as "send high priority html template."

For now, let's just create a simple customized HTML document.

Just like the other programming modules, we'll input custom HTML code into an editor:

Here, column_1_Item is just the iterable of the specific user's name. So for the first iteration it's just equal to the first name in the database, being "Derrick".

Sending the user email

Sweet! So we've got the emails built to send to the specific users. Now let's just send it out. There's a variety of options here, such as SendGrid, MailChimp, Gmail and others. If you're preferred marketing software isn't available, just suggest it to us! In this tutorial we'll work with SendGrid:

Wrapping Up

As always, if you have any questions, comments, feedback, or suggestions, please let us know on WayScript or through our discord.

Top comments (0)