0

Is there an API to use the form performance? I'm using Sitecore 9.3.

enter image description here

1

The performance data is retrieve using the action GetFormStatistics from Sitecore.ExperienceForms.Client.Controllers.ReportsController class.

I added below the action GetFormStatistics:

namespace Sitecore.ExperienceForms.Client.Controllers
{
  [ServicesController("Forms.Reports")]
  [CamelCaseJson]
  [SitecoreAuthorize(Roles = "sitecore\\Forms Editor,sitecore\\Forms Publisher,sitecore\\Forms Data Administrator")]
  [ValidateHttpAntiForgeryToken]
  [SetFormMode]
  public class ReportsController : ServicesApiController
  {
    private readonly IFormBuilderContext _formBuilderContext;
    private readonly IFormStatisticsProvider _formStatisticsDataProvider;
    private readonly ILogger _logger;

    public ReportsController(
      IFormStatisticsProvider formStatisticsDataProvider,
      ILogger logger,
      IFormBuilderContext formBuilderContext)
    {
      Assert.ArgumentNotNull((object) formStatisticsDataProvider, nameof (formStatisticsDataProvider));
      Assert.ArgumentNotNull((object) logger, nameof (logger));
      this._formStatisticsDataProvider = formStatisticsDataProvider;
      this._logger = logger;
      this._formBuilderContext = formBuilderContext;
    }

    [HttpGet]
    [ActionName("FormStatistics")]
    [ValidateModelState]
    [ResponseType(typeof (FormStatisticsResult))]
    public IHttpActionResult GetFormStatistics(
      [FromUri] FormReportParameters reportParameters)
    {
      if (reportParameters == null)
        return (IHttpActionResult) this.BadRequest(Translate.Text("Invalid or missing parameters."));
      Tuple<DateTime, DateTime> dateRange = ReportsController.ParseDateRange(reportParameters);
      try
      {
        FormStatistics formStatistics = this._formStatisticsDataProvider.GetFormStatistics(reportParameters.FormId, dateRange.Item1, dateRange.Item2);
        if (formStatistics == null)
          return (IHttpActionResult) this.NotFound();
        FormStatisticsResult content = new FormStatisticsResult()
        {
          UniqueViews = formStatistics.Visits,
          Abandonments = formStatistics.Dropouts,
          AbandonmentRate = formStatistics.DropoutRate
        };
        foreach (FieldStatistics formFieldStatistic in this._formStatisticsDataProvider.GetFormFieldStatistics(reportParameters.FormId, dateRange.Item1, dateRange.Item2))
          content.Fields.Add(this.CreateFieldStatisticsResult(formFieldStatistic));
        return (IHttpActionResult) this.Ok<FormStatisticsResult>(content);
      }
      catch (XdbDisabledException ex)
      {
        this._logger.Warn(ex.Message, (object) this);
        return (IHttpActionResult) this.StatusCode(HttpStatusCode.NoContent);
      }
    }

You can call this url :

yourhosturl/api/ssc/forms/reports/reports/formstatistics?formId=68ff3538-9528-4b4d-b374-bf85442f0bb1&startDate=2020-10-06T21%3A00%3A00.000Z&endDate=2020-10-14T20%3A59%3A59.000Z&utcOffset=-18 to get the response from the action.

2
  • Thanks for your quick reply, I have another question does sitecore save the statistics of the answers? for example if a raido button with yes and another is no is their a statistics for each answer Oct 14 '20 at 13:42
  • if the yes button is a submit button and you add an action to save data it will save the statistics, otherwise it will not save them Oct 14 '20 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.