This repository is aimed to demonstrate some Sitecore 9 features including custom marketing automation action types implementation https://www.brimit.com/blog/sitecore-9-custom-marketing-automation-action
git clone https://github.com/avershalovich/Demo9.Features.gitDemo9.Features is a reference implementation repository for Sitecore 9 capabilities, specifically targeting custom marketing automation action types. It provides developers with practical examples of extending Sitecore's marketing automation framework with custom actions. The repository serves as educational material for those building advanced marketing automation solutions within Sitecore 9 environments. Developers can reference this codebase to understand implementation patterns for integrating custom actions into Sitecore's marketing automation platform.
[{"step":"Define the custom action's purpose and trigger condition.","action":"Specify what the action should do (e.g., log data, update a facet, send an email) and when it should trigger (e.g., contact visits a page, achieves a goal, or meets a segmentation rule). Use Sitecore’s marketing automation triggers as a reference.","tip":"Start with a simple action (e.g., logging a value) before implementing complex logic. Use Sitecore’s documentation to understand available triggers and facets."},{"step":"Implement the custom action in C#.","action":"Write a class that inherits from `Sitecore.Analytics.Automation.Actions.IAction` and implement the `Execute` method. Ensure the class handles errors and logs outcomes. Use Sitecore’s `Log` class for debugging.","tip":"Leverage Sitecore’s existing facets (e.g., `IContactBehaviorProfile`) or create custom facets for storing additional data. Refer to Sitecore’s developer documentation for facet examples."},{"step":"Configure the action in Sitecore.","action":"Deploy the compiled DLL to the `bin` folder and update the `MarketingAutomation.config` file to register the action. Assign a unique GUID to the action and provide a descriptive name and description.","tip":"Use Sitecore’s serialization or packages to deploy configuration changes. Validate the GUID is unique to avoid conflicts."},{"step":"Test the action in a staging environment.","action":"Create an automation plan in the Sitecore Marketing Automation app, add your custom action, and configure the trigger. Run the plan and verify the action executes as expected by checking logs or facet data.","tip":"Use Sitecore’s `MarketingAutomationEngine` service logs to debug issues. If the action fails, review the logs for error messages and adjust the implementation accordingly."},{"step":"Deploy to production and monitor performance.","action":"After testing, deploy the action to production and monitor its performance in the Sitecore Marketing Automation dashboard. Track metrics like execution time, error rates, and contact engagement to ensure the action meets your goals.","tip":"Set up alerts for errors in the Marketing Automation Engine. Use Sitecore’s reporting tools to analyze the impact of the custom action on your marketing campaigns."}]
Building custom marketing automation actions in Sitecore 9
Learning Sitecore 9 marketing automation extension patterns
Implementing specialized marketing workflows
Understanding Sitecore 9 feature capabilities
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/avershalovich/Demo9.FeaturesCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Implement a custom marketing automation action type in Sitecore 9 for [ACTION_NAME] that performs [SPECIFIC_FUNCTION]. The action should trigger when a contact meets [TRIGGER_CONDITION] and log the following data: [FIELDS_TO_LOG]. Ensure the action integrates with Sitecore's marketing automation engine and handles errors gracefully. Provide the full C# class code and configuration steps for deployment.
Here’s a complete implementation for a custom marketing automation action type in Sitecore 9 that logs a contact’s engagement score when they visit a specific page. This example includes the C# class, configuration files, and deployment steps.
**Custom Action Class (C#):**
```csharp
using Sitecore.Analytics.Automation.Actions;
using Sitecore.Analytics.Automation.Data;
using Sitecore.Analytics.Model;
using Sitecore.Diagnostics;
namespace MySitecoreExtensions.MarketingAutomation
{
public class LogEngagementScoreAction : IAction
{
public IActionResult Execute(IActionContext context)
{
try
{
// Retrieve the contact's engagement score
var engagementScore = context.Contact.GetFacet<IContactBehaviorProfile>()?.EngagementValue ?? 0;
// Log the engagement score to the console (or a custom log provider)
Log.Info($"[Marketing Automation] Contact {context.Contact.ContactId} has an engagement score of {engagementScore}. Triggered by page visit: {context.Session.PageEventData?.ItemId}", this);
// Optionally, store the score in a custom facet
var customFacet = context.Contact.GetFacet<ICustomEngagementFacet>() ?? context.Contact.AddFacet<ICustomEngagementFacet>();
customFacet.LastLoggedScore = engagementScore;
customFacet.LastTriggeredAction = "LogEngagementScoreAction";
return new SuccessResult();
}
catch (Exception ex)
{
Log.Error($"Failed to execute LogEngagementScoreAction for contact {context.Contact.ContactId}", ex, this);
return new FailureResult(ex.Message);
}
}
}
}
```
**Configuration (App_Config/Include/MySitecoreExtensions/MarketingAutomation.config):**
```xml
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<marketingAutomation>
<actions>
<action id="{YOUR-GUID-HERE}" type="MySitecoreExtensions.MarketingAutomation.LogEngagementScoreAction, MySitecoreExtensions" name="Log Engagement Score" description="Logs the contact's engagement score when triggered." />
</actions>
</marketingAutomation>
</sitecore>
</configuration>
```
**Deployment Steps:**
1. Compile the custom action class into a DLL and deploy it to your Sitecore instance’s `bin` folder.
2. Create a custom facet (if needed) by defining it in a Sitecore facet model and deploying it via a Sitecore package or serialization.
3. Update the `MarketingAutomation.config` file with the correct GUID for the action and deploy it to the `App_Config/Include` folder.
4. Restart the Sitecore Marketing Automation Engine service to apply changes.
5. In the Sitecore Marketing Automation app, create a new automation plan, add your custom action, and configure the trigger (e.g., a page visit with a specific event).
**Testing:**
- Trigger the automation plan by visiting a page configured to fire the event.
- Verify the engagement score is logged in the Sitecore logs or stored in the custom facet.
This implementation ensures the action is reusable, handles errors, and integrates seamlessly with Sitecore’s marketing automation pipeline.Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan