12

I'm pretty new at Sitecore, so I don't know if this is possible. I am able to log some custom page events (click on an anchor on the client side) in xDB. I can then query this with Robomongo. But besides that I need to create a report that displays this information.

How can I create a new report in Experience Analytics that accesses the information in MongoDB? I have been trying to pass the MongoDB values to a fact table in the Reporting database, but no luck so far.

1
  • Could you please share the logic how are you logging the custom events and query for mongodb also
    – user3621
    Aug 2, 2019 at 18:15

2 Answers 2

9

Basically, it is a kind of difficult sometimes to query the MongoDB directly, I had a similar scenario and following what I did:

I created aggregation processor that will be called when you rebuild the analytics database or when aggregation occurs:

public class PageEventProcessor : AggregationProcessor
{
    protected override void OnProcess(AggregationPipelineArgs args)
    {
        Assert.ArgumentNotNull(args, "args");
        var fact = args.GetFact<PageEvent>();
        foreach (var page in args.Context.Visit.Pages)
        {
            try
            {
                foreach (var pEvent in page.PageEvents)
                {
                    try
                    {
                        var eventkey = new PageEventKey
                        {
                            EventId = pEvent.PageEventDefinitionId,
                            Date = args.DateTimeStrategy.Translate(pEvent.DateTime),
                            ItemId = pEvent.ItemId,
                            PageId = page.Item.Id
                        };
                        var eventValue = new PageEventValue
                        {
                            Count = 1
                        };
                        fact.Emit(eventkey, eventValue);
                    }
                    catch (Exception ex)
                    {

                    }
                }
            } 
            catch(Exception ex)
            {

            }
        }
    }
}

Classes needed:

public class PageEventValue : DictionaryValue
{

    public int Count { get; set; }

    internal static PageEventValue Reduce(PageEventValue left, PageEventValue right)
    {
        var profileValue = new PageEventValue
        {
            Count = left.Count + right.Count
        };

        return profileValue;
    }
}

public class PageEvent : Fact<PageEventKey, PageEventValue>
{
    public PageEvent() : base(PageEventValue.Reduce)
    {
    }
}

public class PageEventKey : DictionaryKey
{
    public Guid EventId { get; set; }
    public Guid PageId { get; set; }
    public Guid ItemId { get; set; }
    public DateTime Date { get; set; }
} 

Also you need to include the following configuration:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <group groupName="analytics.aggregation">
        <pipelines>
          <interactions>
            <processor type="DllName.PageEventProcessor, DllName" />
          </interactions>
        </pipelines>
      </group>
    </pipelines>
  </sitecore>
</configuration>

Hope this help!

2
  • I tried it and it seems to be working great but the fact table doesn't get updated
    – Eduardo
    Nov 2, 2016 at 1:11
  • add exception handling to the code and check the log files to see if there are any errors. Nov 2, 2016 at 8:24
3

There's a Sitecore guide on how to create custom reports here:

https://doc.sitecore.com/developers/90/sitecore-experience-manager/en/creating-a-custom-experience-analytics-report.html

Steps below:

  • Create a report page item based on template ExperienceAnalyticsReportPage under: core/sitecore/client/Applications/ExperienceAnalytics/Dashboard.
  • Add a chart rendering to the report page item. You can use an existing one (e.g. ExperienceAnalyticsAreaChart)
  • Add a parameters item to the PageSettings item and set metric and segments of the chart
  • Set datasource of chart rendering (step 2) to the recently created parameters items

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.