我找到了获取所需数据的方法,但我使用的是 Sitecore 版本 6.6,但在 6.5 中应该是相同的。如果您选择电子邮件活动的“已发送”文件夹中的消息,您将在项目详细信息的消息预览选项卡中找到“监控行为”按钮。此按钮打开分析数据对话框,其中显示您需要的信息。现在,通过这种方式在后端获取这些信息:
//get the message item we need the statistics for
var campaignMessage = Sitecore.Modules.EmailCampaign.Util.GetMessage(itemId);
//FlowDesigner will use the sc_ContentDatabase database
Sitecore.Context.Items["sc_ContentDatabase"] = Sitecore.Context.Database;
//get the flow by plan id
var flow = new FlowDesigner().ItemsToFlow(campaignMessage.PlanId);
Assert.ArgumentNotNull(flow, "flow");
var infos = new Dictionary<string, StateInfo>();
int totalVisitorsCount = 0;
foreach (State state in flow.States)
{
totalVisitorsCount += state.Visitors;
infos[state.Name] = new StateInfo(state.Id, state.Name, (double)state.Visitors, default(double), default(int), string.Empty);
}
foreach (StateInfo info in infos.Values)
info.UsersPct = (totalVisitorsCount == default(double)) ? default(double) : Math.Round((double)((info.UsersTotal / totalVisitorsCount) * 100.0), 1);
TotalUserCount = totalVisitorsCount.ToString();
SentNotCompleted = infos["Send not Complete"].UsersTotal.ToString();
InvalidAddress = infos["Invalid Address"].UsersTotal.ToString();
SoftBouncePercent = infos["Soft Bounce"].UsersPct.ToString();
HardBouncePercent = infos["Hard Bounce"].UsersPct.ToString();
MessageOpened = infos["Message Opened"].UsersTotal.ToString();
ClickedThroughPercent = infos["Clicked Through Message"].UsersPct.ToString();
VisitorBouncedPercent = infos["Visitor Bounced"].UsersPct.ToString();
MessageUnopened = infos["Message Unopened"].UsersTotal.ToString();
这是对 Sitecore 用于获取统计数据的代码的轻微修改。修改是我将项目放在字典中,这样我就可以轻松地按名称引用它们,但计算逻辑没有改变。您可以获得的状态是:
- 收件人排队
- 发送未完成
- 无效地址
- 软反弹
- 硬反弹
- 消息未打开
- 消息已打开
- 通过消息点击
- 访客反弹
- 非生产性访客
- 富有成效的访客
您可以分别使用 Sitecore.Shell.MarketingAutomation.BusinessObjects.StateInfo 的 UsersTotal 和 UsersPct 属性以数字或百分比显示统计数据。