1

I want to save some information about that page that has been clicked by the user so I register a page event on processItem pipeline for this I did below code:

  public class RegisterCustomPageEvents : ProcessItemProcessor
    {
        public override void Process(ProcessItemArgs args)
        {

            foreach (TrackingField trackingParameter in (IEnumerable<TrackingField>)args.TrackingParameters)
                TrackingFieldProcessor.ProcessEvents(args.Interaction, trackingParameter);

            if (!Tracker.Enabled || Tracker.Current == null || !Tracker.Current.IsActive)
            {
                return;
            }

            FireCustomEvent(args);
        }

        private void FireCustomEvent(ProcessItemArgs args)
        {
            var myPageTemplateId = "{ED0B99D5-4992-429F-84FE-F8F3D902CAB5}";

            if (args.Item == null || Context.Item.TemplateID.ToString() != myPageTemplateId)
            {
                return;
            }
            var ev = Tracker.MarketingDefinitions.PageEvents[Guid.Parse("{059A1829-DD32-47B6-8EA6-BEEFAC98DC6E}")];

            if (ev != null)
            {
                var pageData = new PageEventData(ev.Alias, ev.Id);

                pageData.Text = "Event";

                var fullUrl = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;

                pageData.CustomValues.Add("Url", fullUrl);
                pageData.CustomValues.Add("PageTemplateId", args.Item.TemplateID.ToString());
                pageData.CustomValues.Add("ItemVersion", args.Item.Version.Number);

                pageData.ItemId = args.Item.ID.ToGuid();

                try
                {
                    Tracker.Current.CurrentPage.Register(pageData);
                }
                catch (Exception ex)
                {
                    Log.Error("Unable to fire custom event", ex, this);
                }
            }
        }
}
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <processItem>
                <processor type="XXX.RegisterCustomPageEvents, XXX" />
            </processItem>
        </pipelines>
    </sitecore>
</configuration>

My issue is that I am not able to see page events in Interactions table. I tried to abandon the session.

6
  • Can you confirm you are testing and abandoning session on CD or Standalone role? Oct 24, 2022 at 5:35
  • It is on standalone Oct 24, 2022 at 10:13
  • Has the page event with ID "059A1829-DD32-47B6-8EA6-BEEFAC98DC6E" definitely been deployed to ref data DB? Oct 24, 2022 at 15:20
  • @DeanOBrien Yes it is deployed Oct 25, 2022 at 2:24
  • Did you get this working? I tried using the exact same code and could see the pageEvent registered in the interactions table. However, the customValues were missing. Looking into this further, it seems you must create a custom event to store your additional info and add a converter. Oct 30, 2022 at 18:31

1 Answer 1

2

I found the below lines in the Sitecore document:

enter image description here

To achieve this, I followed below link:

https://sitecore.marcelgruber.ca/posts/storing-full-urls-in-page-view-events

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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