Sitecore Marketing Automation is a really powerful tool, if used correctly. An often overlooked feature is the ability to use Custom Values when enrolling a contact into an automation plan. By using this feature, you can make an automation plan “contextual”, and with that I mean that you can act on the values that are passed on enrolment.
For example; you have several pages on your website where your customer can register for an event. After registering, you would like to send the customer a reminder email a few days before the event occurs.
When you set this up without Custom Values, then you’d have to set up an Automation Plan per event so you can send a different email, which would not be manageable. With Custom Values, you can just set up a single Automation Plan and use the Custom Values to act on the event data. When enrolling a contact, you would add the following values to the Custom Values; Event Name, Event date. These can then be used to determine when the email should be sent and to include the Event Name within your email.
To be able to use this functionality in a generic way (you should be able to build whatever you want with these components without needing any more code), my advice would be to create the following components on your website:
- A custom submit action for Sitecore Forms that enrols a contact in an Automation Plan, with an option to map Form Fields to Custom Values (the same as you’d sent an EXM email from Sitecore Forms)
- A custom Marketing Automation condition which you can use to compare the value of a Custom Value to a given string
- A custom Marketing Automation condition which you can use to compare the value of a Custom Value to a selected Sitecore item
- A custom Marketing Automation action that replaces the EXM email action, which passes the Custom Values as EXM tokens so they can be used in an EXM email.
When all of these are implemented, you should be able to create a lot of Automation Plans without the need of duplication or custom code. In this blog I’ll start with the custom submit action, and the Marketing Automation conditions and action will follow in a blog post later on.
The custom submit action
The original submit action that’s included with Sitecore Forms can only add a contact to a Marketing Automation Plan, but is not capable of passing Custom Values to the enrolment. We can re-use a lot of code from the “Send email campaign message” submit action, because we’d like the same option where a user can map Form Fields to tokens. When the submit action is complete, the UI should look as follows:
The steps to create this submit action are:
- Duplicate the “/sitecore/client/Applications/FormsBuilder/Components/Layouts/Actions/SendEmailCampaignMessage” item and switch out the “Select emailcampaign message” so it becomes “Select the automation plan”. After that change the speak script so we can get the Automation Plans.
- Create a new Submit Action in “/sitecore/system/Settings/Forms/Submit Actions”
- Extend the “Sitecore.EmailCampaign.Cd.Actions.SendEmail” class so we can expose the ExtractTokens method and consume it in our own submit action.
- Create the code for the submit action that retrieves or creates a contact, and enrolls the contact in the automation plan.
As there are a lot of dependencies and Sitecore items, instead of including the code in this blog post, you can see it in this Github repo. You can use the Sitecore Serialization CLI to push the Sitecore items. If you have any questions, don’t hesitate to send me a message.