Handle the event and build the interactions

To create a new event handler for the Sitefinity Insight connector, inherit the InteractionTrackingHandlerBase<T> abstract class override its ComposeInteractions method.
For more information, see Track data server-side » Create new data collection handlers.

NOTE: Make sure you register the new event handler in Sitefinity CMS backend.

You first override the built-in event handler to upload the submit form data to Sitefinity Insight and then you override the List<Interaction> ComposeInteractions CustomSubmitFormEvent @event method of the class:

C#
using System;
using System.Collections.Generic;
using Telerik.DigitalExperienceCloud.Client;
using Telerik.Sitefinity.DataIntelligenceConnector.Cookies;
using Telerik.Sitefinity.DataIntelligenceConnector.EventHandlers;
using Telerik.Sitefinity.Security.Claims;
using Telerik.Sitefinity.Services;

namespace SitefinityWebApp.Events
{
    public class CustomSubmitFormTrackingHandler : InteractionsTrackingHandlerBase<CustomSubmitFormEvent>
    {
        public override List<Interaction> ComposeInteractions(CustomSubmitFormEvent @event)
        {
            string subject = ClaimsManager.GetCurrentUserId().ToString();

            // If there is no logged in user, take the autogenerated guid from the cookie
            if (subject == Guid.Empty.ToString())
            {
                var cookieManager = new CookiesManager();
                subject = cookieManager.GetCookieValue();
            }

            string obj = SystemManager.CurrentHttpContext.Request.Url.AbsolutePath;
            string predicate = "Submitted Custom Form";
            var subjectMetadata = new Dictionary<string, string>()
            {
                { "Email", @event.Email },
                { "FirstMeal", @event.FirstMeal },
                { "SecondMeal", @event.SecondMeal },
                { "Dessert", @event.Dessert },
            };
            var objectMetadata = new Dictionary<string, string>();

            List<Interaction> interactions = new List<Interaction>();
            interactions.Add(this.InteractionMng.CreateInteraction(predicate, obj, subject));
            interactions.Add(this.InteractionMng.CreateInteractionSubjectMetadata(subject, subjectMetadata));

            return interactions;
        }
    }
}