Link statistics

The link click statistics provide statistics about the link clicks in the message bodies of a campaign. They can be used to provide information like:

  • Date of the last clicked link;
  • Total number of link clicks in a campaign;
  • The number of unique link clicks in a campaign;

This topic explains how to obtain these statistics and how to work with them in order to visualize specific information.

The generation of the link statistics objects is handled by Sitefinity CMS. Whenever a subscriber clicks a link in the message body of a campaign, a LinkClickStat object is created and stored in the data base.

The LinkClickStat object contains information regarding the following:

  • The id of the campaign to which the clicked link belongs;
  • The date on which the link was clicked;
  • The id of the subscriber, who clicked the link;
  • The URL of the link;

To query all of the link click statistics for a specific campaign, you must use the NewslettersManager class. The following code gets the link click statistics for the campaign with the specified ID through the Native API. ```C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Telerik.Sitefinity.Modules.Newsletters; using Telerik.Sitefinity.Newsletters.Model;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.EmailCampaigns.Statistics { public partial class EmailCampaignsSnippets { public List GetLinkClickStats(Guid campaignId) { NewslettersManager manager = NewslettersManager.GetManager();

        var linkStats = manager.GetLinkClickStats().Where(l => l.CampaignId == campaignId).ToList();

        return linkStats;
    }

}

}

First, you initialize the NewslettersManager. Then, you call GetLinkClickStats method to retrieve all link click statistics and, finally, you filter the statistics based on the *CampaignId* property.
 
In order to obtain more specific information, you can additionally manipulate the result collection by using the *DateTimeClick*,*SubscriberId*, *Url* properties of the *LinkClickStat* object.
 
As an addition, the Native API exposes methods that upon calling automatically calculate one of the following statistics for you:

- The Date of the last link that has been clicked in the specified campaign;
- The total number of clicks in the specified campaign;
- The total number of unique clicks in the specified campaign;

To obtain these statistics, you must call the respective methods of the *NewsletterManager* class:      ```C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Modules.Newsletters;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.EmailCampaigns.Statistics
{
    public partial class EmailCampaignsSnippets
    {
        public void ExecuteLinkStatsCalculations(Guid campaignId)
        {
            NewslettersManager manager = NewslettersManager.GetManager();

            DateTime lastClickDate = manager.CalculateTheDateTimeOfTheLastClick(campaignId);

            int totalClicks = manager.CalculateTotalNumberOfClicks(campaignId);

            int totalUniqueClicks = manager.CalculateUniqueNumberOfClicks(campaignId);
        }
    }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.