Personalizing Marketo Emails with ChatGPT

Everyone knows that emails perform best when you personalize the email based on the person you are sending to. This post will show you how to go beyond simply using lead and company tokens in your emails and instead use ChatGPT to create fully personalized email subject lines and bodies.

Personalizing Marketo Emails with ChatGPT Video

Verdict on ChatGPT Personalization

There are many different scenarios where we could use ChatGPT to personalize our Marketo emails. For example, two examples that come to mind right away:

  • Respond to formfills by sending ChatGPT the information submitted in the form
  • Personalize our nurture emails by giving ChatGPT the website of the company that a person works for

It is the second scenario here that forms the basis of this blog post and my testing.

I was quite impressed by ChatGPT’s performance when it came to creating an email snippet to insert in the email body. I think the Coca-Cola example below is a good example of how personalized ChatGPT can make our email content just by providing it with a website.

Personalizing an email for Coca-Cola using ChatGPT
Personalizing an email for Coca-Cola

From my experience, the subject lines returned from ChatGPT are very repetitive and generic (see the Google sheet linked below). In contrast to the email body where there is a larger character range for ChatGPT to personalize the content I think it is expected that since the subject line is so short it is hard for ChatGPT to use the information it finds from the website.

While the subject lines are generic and repetitive they are at least personalized to include the company name that ChatGPT finds from the website. This is useful when you do not have information about the person’s company in Marketo yet.

Refining the ChatGPT Prompt

As always the most important part of any project involving ChatGPT is to test and refine your prompt so that you are getting the outcomes you desire.

To make this easy you can:

  1. Make a copy of this Google sheet
  2. Install the GPT for Sheets and Docs extension
    • See this section to learn how to connect this extension to your ChatGPT account
  3. Import lead information from your Marketo database
  4. Use the GPT formula to test your prompt for each lead in the sheet
  5. Duplicate this sheet and change the prompt so that you can compare how the outcome changes by comparing different sheets with different prompts

Email Body Prompt

Using the prompt below as an example there are a few important points to bear in mind so that the output is in the best format to use in Marketo emails:

  • If we want ChatGPT to produce more than one paragraph of text e.g. 50 words, then we will need to ask ChatGPT to insert a special set of characters e.g. <n> , that we will use later on in a velocity script to insert line breaks in our emails. N.B. Be careful what set of characters you use here because some special characters can break the JSON syntax of the webhook that we send from Marketo. For example, I tried \n but this broke JSON syntax when used in the webhook payload.
  • Giving ChatGPT context about the purpose of the email and where the snippet will be placed will help it generate the most appropriate snippet
  • Since we do not have the option to modify the text returned from ChatGPT once we receive it in Marketo via webhook (see below) we need the output text from ChatGPT to be ready to insert into the email right away. I was having issues with ChatGPT still inserting a greeting even though I mentioned that the snippet would be inserted after the greeting so I had to explicitly tell it not to do this.
  • In the case that ChatGPT can’t find any information from the website we ask it to give a fallback value i.e. NA, that we can filter on in our email script token later on so that we know to use default text

Write an email snippet for a person who works at the company with the website {{company.Website}} speaking to their company’s use case and how The Workflow Pro can solve their company’s pain points. Write from the perspective of the The Workflow Pro brand, make the snippet around 100 words in length, using line breaks in the form of <n> after roughly every 50 words if needed.The snippet you provide will be inserted after the greeting and before text encouraging this person to compare us to competitors so you should not include a greeting or any other text besides the snippet. If you cannot find out any information from the website then return NA.

Email Subject Line Prompt

Once again it is important that the output from ChatGPT is ready to be inserted into the email without any modification. When I first tested this prompt ChatGPT was putting inverted commas around the subject line or returning the response in this format “Subject line: xxxx” so I had to explicitly tell it to exclude quotation marks and any extra words or characters.

Write an email subject line for a person who works at the company with the website {{company.Website}} speaking to how The Workflow Pro can be valuable for their company. It is important that you only return the subject line with no quotation marks or any extra words or characters. If you cannot find out any information from the website then return NA.

Getting ChatGPT Content into Marketo

Once we have refined our prompts for the email body and the subject line we need to create fields to store the text returned from ChatGPT for these entities.

Creating Fields to Store ChatGPT Content

Looking at the docs we can see that a “String” field will work to store the subject line since a string can hold 255 chars. Using the same docs we can see that we will need a “Text Area” field (30k character limit) to store the email body.

Creating a field in Marketo to store the email body returned by ChatGPT
Creating a field to store ChatGPT email body

Creating ChatGPT Webhooks

Now we will need to create 2 webhooks:

  • One webhook to populate the subject line field
  • One webhook to populate the email body field

See the Making ChatGPT Requests Using Marketo Webhooks section to see how to set up a webhook to make requests to ChatGPT and store the output in a Marketo field. Notice how company tokens are used in the payload body to send lead information to ChatGPT.

Marketo webhook to send a request to ChatGPT to get a subject line for an email
Webhook to get a subject line
Mapping ChatGPT's response to the subject line field in Marketo
Mapping ChatGPT response to the subject line field

Populating Marketo Emails with ChatGPT Content

Using the ChatGPT content fields is as easy as referencing the lead tokens within your email subject line and email body. However, in the case that ChatGPT cannot find any information from the website and returns NA we cannot rely on using the default value associated with the lead field token because this will only insert the default when the field is empty and not when the field is “NA”.

Defining email script tokens for the subject line and email body
Defining email script tokens

We need to use email script tokens to insert default text when the field is “NA”. See the video at the top of the post to see how to create these tokens and insert them in your email.

Three important things to note about using the email script tokens below:

  • When creating your script tokens make sure to check the box on the right-hand side for each field that is used in your script. This is most important when you copy a script from one token to another.
  • One important thing to note about script tokens is that they will only work for emails that are nested in the same program or folder where the script token is defined
  • When using both of the email script tokens in an email it is important that the variables you use in the scripts i.e. a and b in the scripts below, have different names or else one script will overwrite the value of the variable with the same name that the other script populated. For example, if both scripts populate variable “a” then the email body script will overwrite the variable “a” with its value and both the subject line and email body will have the same value.

Setting a Fallback Value Using an Email Script Token

#if (!$lead.aIEmailSubjectLine.isEmpty() && $lead.aIEmailSubjectLine != "NA")
    #set( $a = $lead.aIEmailSubjectLine)
#else
    #set( $a = "The Workflow Pro was named 2023 best content creator")
#end
${a}

For those of us not familiar with code, the script above will either return:

  • The email subject line field when the email subject line field is not empty and not filled with NA
  • Or default text

How To Render Line Breaks in Text Area Tokens

Using the email body field in our email is a little more complex because of the need to insert line breaks. You can test this out for yourself or take my word for it but line breaks in a text area field do not render when the text area field is used as a token in an email.

Using the email script token in the email body
Using the email body script token

This was a pain for me to figure out how to fix and involved a while of messing around with an email script token but don’t worry I got you! All you have to do is copy the code below into an email script token and you will be ready to go.

#if (!$lead.aIEmailBody.isEmpty() && $lead.aIEmailBody != "NA")
    #set( $b = $lead.aIEmailBody.replace("<n>", "<br /><br />"))
#else
    #set( $b = "After years of producing top notch content the Workflow Pro was named 2023 MOPs Content Producer of the Year!")
#end
${b}

The only difference between this script and the email subject line script is that this code will return the email body field with our special set of characters i.e. <n>, replaced with new line tags so that we get the line breaks we desire.

Testing Before Roll Out

Refining your prompt using the Google sheet and process described at the start of this blog is a crucial first step before rolling these ChatGPT-enabled emails off the production floor. Since these emails will be customer-facing we want to make doubly sure that everything is working as expected so I recommend doing the following:

  • In the smart campaign that you want to send the email include 2 webhook actions to populate the ChatGPT email body and subject line
  • Include a “Send Alert” action, set the “Send To” field to “None”, and then put your email in the “To Other Emails” field
  • Click “View Campaign Members” and create a list view containing the ChatGPT email fields along with the lead fields that you send to ChatGPT
Smart campaign flow actions in Marketo for testing emails personalized by ChatGPT
Flow actions for testing ChatGPT emails
List view in Marketo showing fields populated by ChatGPT
List view showing ChatGPT fields

Now you can monitor the emails coming to your inbox and the smart campaign member list with the tailored view to see what values are being pushed into the ChatGPT email fields and how the resulting emails are rendering.

Once you are happy with how the ChatGPT emails are performing you can swap that “Send Alert” step with the “Send Email” step that will start sending these emails to your customers. All there is left to do now is to set up a champion challenger test to see how the ChatGPT subject line and email body perform compared to the default text that would otherwise be in this email.

What’s After ChatGPT Personalized Emails?

Just can’t get enough ChatGPT content eh? Well then take a look at how you can use ChatGPT to:

Leave a Reply

Your email address will not be published. Required fields are marked *