Marketing Automation Reporting API
The Marketing Automation Reporting API allow callers to retrieve statistics and metrics for plans and activities.
Accessing the automation reporting client
The following example demonstrates how to access the IAutomationReportingClient
in a Sitecore context:
using Sitecore.DependencyInjection;
using Sitecore.Xdb.MarketingAutomation.ReportingClient;
using Microsoft.Extensions.DependencyInjection;
namespace Documentation
{
public class AutomationAPI
{
public void Example()
{
var reportingCLient = ServiceLocator.ServiceProvider.GetService<IAutomationReportingClient>();
}
}
}
Operations
There are synchronous and asynchronous versions of each method.
Get plan statistics
The GetPlanStatisticsAsync()
method takes a list of plan IDs and returns a list of PlanStatistics
objects. The example below details the statistics available:
using Sitecore.DependencyInjection;
using Sitecore.Xdb.MarketingAutomation.ReportingClient;
using Microsoft.Extensions.DependencyInjection;
using System;
using Sitecore.Xdb.MarketingAutomation.Core.Reporting;
using Sitecore.Xdb.MarketingAutomation.Core.Collections;
namespace Documentation
{
public class GetPlanStats
{
public async void Example()
{
var reportingClient = ServiceLocator.ServiceProvider.GetService<IAutomationReportingClient>();
var result = await reportingClient.GetPlanStatisticsAsync(new[]
{
Guid.Parse("{19F1B472-11E4-4927-84EC-71E10136CE4E}"), // Plan ID #1
Guid.Parse("{6CCC76C7-85DE-4214-B51B-D045065129A7}") // Plan ID #2
});
foreach (PlanStatistics stat in result)
{
Guid planID = stat.PlanDefinitionId; // The plan ID
long allEnrollmentsCount = stat.AllEnrollmentCount; // All enrollments in the history of this plan
long currentEnrollmentsCount = stat.CurrentEnrollmentCount; // Current enrollments
}
}
}
}
If the system cannot find a plan by the ID given, nothing will be returned for that ID. For example, if the request includes 5 IDs and 2 IDs cannot be found, the system will only return 3 PlanStatistics
instances.
Get plan report
The GetPlanReportAsync()
method takes a single plan ID, a start date, and an end date, and returns a PlanReport
. The start and end date affect the values of ActivityCurrentContactCount
and PlanCurrentContactCount
. The example below details the statistics available:
using Sitecore.DependencyInjection;
using Sitecore.Xdb.MarketingAutomation.ReportingClient;
using Microsoft.Extensions.DependencyInjection;
using System;
using Sitecore.Xdb.MarketingAutomation.Core.Reporting;
using Sitecore.Xdb.MarketingAutomation.Core.Collections;
namespace Documentation
{
public class GetPlanReport
{
public async void Example()
{
var reportingClient = ServiceLocator.ServiceProvider.GetService<IAutomationReportingClient>();
var planId = Guid.Parse("{C5F5C4AA-3D00-41ED-AEA2-740129E340E3}");
var reportStart = DateTime.UtcNow.AddDays(-1);
var reportEnd = DateTime.UtcNow;
var result = await reportingClient.GetPlanReportAsync(planId, reportStart, reportEnd);
var allContactsByActivity = result.ActivityAllContactCount; // The number of contacts that have ever been enrolled by each activity. The dictionary key is the ID of the activity and the value if the enrollment count.
var allCurrentContactsByActivity = result.ActivityCurrentContactCount; // The number of contacts enrolled by each activity within the start and end dates. The dictionary key is the ID of the activity and the value if the enrollment count.
var allContacts = result.PlanAllContactCount; // The number of contacts that have ever been enrolled in any activity of the plan. This is basically a sum of all of the counts from the ActivityAllContactCount dictionary.
var currentContactCount = result.PlanCurrentContactCount; // The number of contacts enrolled in any activity of the plan within the start and end dates. This is basically a sum of all of the counts from the ActivityCurrentContactCount dictionary.
}
}
}