12

I upgraded my site from Sitecore 7.5 to 8.1, and following is the code that I'm using to retrieve the page events:

foreach (PageData page in args.Context.Visit.Pages)
{
    if (page.PageEvents != null)
    {
         foreach (var pageEvent in page.PageEvents)
         {
             if (pageEvent.IsGoal)
                Log.Error("Goal: " + pageEvent.Name.ToString(), "PageEventProcessor");
         }
     }
}

the page events are being retrieved except the goals, Although I can see the following data in the interaction collection in MongoDB:

"PageEvents" : [
    {
        "Name" : "Mobile Click",
        "Timestamp" : NumberLong(0),
        "Data" : "Mohammed Test",
        "DataKey" : "650fce89-87bb-4768-ab40-8bc988d7a729",
        "Text" : "Location Name and other information",
        "PageEventDefinitionId" : LUUID("e7798282-5362-af4d-80ce-07055fcf3b86"),
        "IsGoal" : true,
        "DateTime" : ISODate("2015-08-23T16:12:21.686Z"),
        "Value" : 10
    }
],

Am I doing something wrong in the retrieving code? Is there another code I should use? Any suggestions?.

  • What is the template of your goal item? – Vlad Iobagiu Sep 27 '16 at 15:02
  • It is a goal template /sitecore/templates/System/Analytics/Goal, – Mohammed Syam Sep 27 '16 at 15:07
  • Have you made sure it's the same visit you are checking? – josedbaez Sep 27 '16 at 16:55
  • Actually I want to go through all visits, How I can do that? – Mohammed Syam Sep 27 '16 at 17:02
  • Well because I imagine the current visit (args.Context.Visit) is not the one you registered the goal on because the session needs to die before it gets added to the db right? – josedbaez Sep 27 '16 at 17:10
2

Looking at the OP, the comments, your code and Sitecore's, I believe that this issue is likely caused by a bug in the PageEvent.IsGoal property, whereby the property is not being correctly set to true for events that are goals. I have not yet confirmed this bug, but if I am correct then the following should help you work around the issue:

Solution

Try changing your code to the following:

foreach (PageData page in args.Context.Visit.Pages)
{
    if (page.PageEvents != null && 0 < page.PageEvents.Count)
    {
         foreach (var pageEvent in page.PageEvents)
         {
             var pageEventItem = pageEvent.PageEventDefinitionId != Guid.Empty 
                 ? Tracker.DefinitionItems.Goals[pageEvent.PageEventDefinitionId] 
                 : Tracker.DefinitionItems.Goals[pageEvent.Name];

             if (pageEventItem == null || !pageEventItem.IsGoal) 
             {
                 throw new Exception("I must be null because I definitely should be a goal. Still I should never be thrown because I came from the Goals property of the trackers definition items");
             }   

             Log.Info("Goal: " + pageEvent.Name.ToString(), "PageEventProcessor");

             // now do something with your goal
         }
     }
}

Notice that in the above solution, I am using the pageEventItem.IsGoal property instead of the pageEvent.IsGoal property. I have not sufficiently tested this to figure out if the problem is simply with the PageEvent.IsGoal flag is not set when you check it, but I expect that to be the case. Regardless, the PageEventItem.IsGoal should be accurate and more reliable, as that property is read directly from the item's field.

Arrival at Solution

While I am still working to figure out if this is actually a bug in xDB, I came to this solution by looking at how Sitecore aggregates goals in the <interactions> pipeline.

Remember that a Goal is really a conversion, and since there weren't any processors with "Goal" in the name, I had a look at the Sitecore.Analytics.Aggregation.Pipeline.ConversionsProcessor.

After reviewing the processor I realized that Sitecore's approach was nearly identical to yours though slightly different - Sitecore's code uses the item's field to determine if it's actually a goal. Since checking the value of that field should be more reliable than a property that may or may not have been correctly set on a C# object, I am left to infer that the issue is likely a bug in Sitecore with the PageEvent.IsGoal property and that you should work around the issue by using the PageEventItem.IsGoal property, instead.

Next Steps

The first thing that I recommend you do is try the above workaround. Next, I would get in touch with Sitecore Support and show them what you've tried and what you are seeing. They should be able to provide further assistance, in addition to documenting and fixing the bug, if confirmed.

Good luck!

-1

For performance reasons, interaction details (like page events) are only loaded when needed.

Play around with the following in order to load historical data:

var contactRepository = Factory.CreateObject("tracking/contactRepository", true) as ContactRepository;
var interactions = contactRepository.LoadHistoricalInteractions(arg.Session.Contact.ContactId, 10);
  • The OP's code is in a custom interactions processor. So there won't be any session. And there will already be a loaded visit in the pipeline args. So I don't think your code will be helpful. – Dmytro Shevchenko Dec 7 '16 at 5:57

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.