jack
jack

Reputation: 1538

Sitecore Analytics Api - Emails Sent, Open and Click throughs

We are using Sitecore 6.5 and we have Email campaigns setup and the emails get triggered automatically at different stages of the signed-up users life cycle.

I have been tasked to get the stats for - total count of emails 'sent', 'open rates' and the 'click throughs'(this is user clicking the link on the email and visiting our site).

Does any one know how this can be done using Sitecore Analytics API. I need to pull this information and display it as a report.

I am new to Analytics and any help will be much appreciated.

Edit: I will need to display this in a web page as 4 columns they are : date, total emails sent, total emails opened and total emails with click throughs. Hence, if you can point me to the right apis that will great.

Thanks

Upvotes: 2

Views: 1997

Answers (2)

Ivan Krumov
Ivan Krumov

Reputation: 41

I have found the way to get the data you need but I am using Sitecore version 6.6, but in 6.5 this should be the same. If you select a message that is in the "sent" folder of an email campaign, you will find a "Monitor Behavior" button in the message preview tab of the item details. This button opens the analytics data dialog that displays the information you need. Now, getting this info in the backend is achieved this way:

//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();

This is a slight modification of code that is used by Sitecore to get the statistics data. The modification is that I put the items in a dictionary so I get easily refer them by name, but the calculation logic is not changed. The states you can get are:

  • Recipient Queued
  • Send not Complete
  • Invalid Address
  • Soft Bounce
  • Hard Bounce
  • Message Unopened
  • Message Opened
  • Clicked Through Message
  • Visitor Bounced
  • Unproductive Visitors
  • Productive Visitors

You can show the statistics data in numbers or in percent - respectively using UsersTotal and UsersPct properties of Sitecore.Shell.MarketingAutomation.BusinessObjects.StateInfo.

Upvotes: 4

divamatrix
divamatrix

Reputation: 1126

Jack - In the Sitecore backend, there's an area under the marketing center that has Engagement Plans and this is really where you need to look. Keep in mind one thing.. which is that these have available which specific users.. but it's not going to show the specific "users" in the reports. That's available in the backend but isn't a simple API call at this point.

All the tracking of emails is done with engagement plans and the states. Every email in ECM has a field called Engagement Plan that points to the specific engagement plan that is being used to track things. Browsing to that engagement plan in the content editor or marketing center will bring up a screen where you can see the states in the engagement plan and see how many emails are in what state. The ECM engagement plan includes states for everything from "Queued to be sent" to opened and clicked links and had a productive visit.

There should be an engagement plan in place for every email that you have configured in ECM and depending on the type of email being sent, you can also get to it for email blasts that are in the "Sent" folder by clicking the "monitor behavior". There's also an executive dashboard with shows some stats as well although that's more of a 10000 foot view.

Upvotes: 5

Related Questions