SITECORE Reports : Extending analytics reports using custom dimensions

 


Dashboard in Content Editor Core Database:




is the same Dashboard in Exp Analytics: 



Presentation details and Layout of Dashboard :






Sitecore Charts Components :



Sitecore Dimension:

Dimension describes the dataDimensions are attributes of your data

For example, the dimension City indicates the city, for example, "Paris" or "New York", from which a session originates. 

The dimension Page indicates the URL of a page that is viewed

From a development perspective, we think about the dimension as a grouping of the data- group by city, group by page, etc 

Sitecore Metrics:

Metrics measure the data. In Sitecore there are 7 standard metrics that measure the different attributes of each dimension:
Visit, Value, Page Views, Time on site, Bounces, Conversion and count

Create your own dimension (also known as flexible dimensions) and collect metrics for it.

Exp analytics Filters ( Master database ) : 

  • You can choose Pages, Visits, or create your own subfolder.
  • You create segments by combining a dimension with a filter.



Custom Report-All Visits by Operating system:

Create and configure the dimension item:

Create the dimension
: you create classes to represent the dimension and do the metrics calculations.

Duplicate one of the existing flexible dimensions.
For Example, Duplicate the "By device type" flexible dimension to "By Operating System".

In the Data section, in the Metric Type field, enter the name of the class you created.
 
Set below values:




Create a segment item




  • In the Review tab, in the Workflow group, click Deploy. By default, this starts data collection for the segment 30 minutes after deployment.

Create FlexibleDimensions.config:

<configuration xmlns:role="http://www.sitecore.net/xmlconfig/role/"> <sitecore role:require="Standalone or Processing">
<experienceAnalytics>
<aggregation>
<!-- Sitecore.ExperienceAnalytics.Aggregation.FlexibleMetrics namespace
within Sitecore.ExperienceAnalytics.Aggregation.dll is your best friend -->
<flexibleDimensions>
<!-- Operating system / DON'T forget to deploy marketing definitions segments ;) / -->
<dimension id="{BC53C7C9-9C3D-4F3D-9253-FE5B59E7C777}" type="Sitecore.ExperienceAnalytics.Aggregation.FlexibleMetrics.Framework.FlexibleDimension`2[[CustomReport.Demo.FlexibleDimensions.OperatingSystemMetrics, CustomReport.Demo],             [Sitecore.XConnect.Collection.Model.OperatingSystemData, Sitecore.XConnect.Collection.Model]], Sitecore.ExperienceAnalytics.Aggregation">
<param type="CustomReport.Demo.FlexibleDimensions.OperatingSystemGroupResolver, CustomReport.Demo"/>
<param type="CustomReport.Demo.FlexibleDimensions.OperatingSystemFactCalculator, CustomReport.Demo"/>
<!-- No need for more params. IKeyComposer is marked as internal which limits us to using only this contructor of FlexibleDimension<TOutputValues, TInputEvents>. -->
<InteractionFilters hint="list">
<!-- All implement IInteractionFilter -> bool ExcludeFromAggregation(Interaction interaction);
Basically these filters exclude some internal Sitecore interactions from aggregation and are used on all flexible dimensions -->
<InteractionFilter type="Sitecore.ExperienceAnalytics.Aggregation.Filters.ExmSyntheticEventFilter, Sitecore.ExperienceAnalytics.Aggregation"/>
<InteractionFilter type="Sitecore.ExperienceAnalytics.Aggregation.Filters.WebVisitFilter, Sitecore.ExperienceAnalytics.Aggregation"/>
</InteractionFilters>
</dimension>
</flexibleDimensions>
</aggregation>
</experienceAnalytics>
<settings>
<!-- EXPERIENCE ANALYTICS - AGGREGATION - SEGMENT DEPLOY DATE OFFSET PADDING
Controls additional padding when interaction's SaveDateTime is compared with segment's deploy date.
The timespan built from the value of this setting is added to the segment's deploy date.
When a segment is being deployed, the DeployDate will be DateTime.UtcNow.Add(SegmentDeployDateOffsetPadding)
Interaction data for the particular segment will be processed if interaction.SaveDateTime > segment.DeployDate
Default value: 00:30:00 (30 minutes)
Reduced to 10 sec for demo purpuses. -->
<setting name="ExperienceAnalytics.Aggregation.SegmentDeployDateOffsetPadding" value="00:00:10" />
</settings>
</sitecore>
</configuration>

Custom Metric class [ output ]: OperatingSystemMetrics.cs:

Add references to these libraries in your Visual Studio solution:
Sitecore.Analytics.Aggregation
Sitecore.ExperienceAnalytics.Aggregation
Sitecore.XConnect
Sitecore.Kernel
Sitecore.XConnect.Collection.Model

namespace CustomReport.Demo.FlexibleDimensions {
using Sitecore.Analytics.Aggregation.Data.Model;
using Sitecore.ExperienceAnalytics.Aggregation.FlexibleMetrics.Framework.Metrics;
using System;

// All implement this interface and inherit from this base class
public class OperatingSystemMetrics : DictionaryValue, IMergeableMetric<OperatingSystemMetrics>
{
//Define properties for your metrics, for example Visits, MonetaryValue, and so on. public int Visits { get; set; }
//Implement the MergeWith method. In this method,            // you specify how data that is calculated for a new interaction is merged into the already existing calculated data.         public T MergeWith<T>(T other) where T : OperatingSystemMetrics, new()
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
T instance = Activator.CreateInstance<T>();
instance.Visits = Visits + other.Visits;
return instance;
}
}
}




OperatingSystemData: the type of object you want to use as a key when you group records for your dimension.



namespace CustomReport.Demo.FlexibleDimensions { using Sitecore.ExperienceAnalytics.Aggregation.FlexibleMetrics.Framework.Grouping;
using Sitecore.XConnect.Collection.Model;
using System;
using System.Collections.Generic;
using System.Linq;
public class OperatingSystemGroupResolver : IGroupResolver<OperatingSystemData>
{
public IEnumerable<VisitGroupMeasurement<OperatingSystemData>> MeasureGroupOccurrences(IInteractionAggregationContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (context.Interaction == null)
{
throw new ArgumentNullException(nameof(context.Interaction));
}
// Could use the IInteractionAggregationContext depening on your needs
// to either get some interaction event (all inhereit from Sitecore.XConnect.Event) like for example
// context.Interaction.Events.OfType<PageViewEvent>();
// context.Interaction.Events.OfType<DownloadEvent>();
// or interaction Facet like WebVisit, IPInfo or other
// Could use DotPeek to check the events facets
// All Events inherit from Sitecore.XConnect.Event.cs withing Sitecore.XConnect.dll
// ConvertToXConnectInteractionProcessor.cs within Sitecore.Analytics.XConnect.dll will give insights about the facets
var webVisitFacet = context.Interaction.WebVisit();
if (webVisitFacet?.OperatingSystem == null)
{
return Enumerable.Empty<VisitGroupMeasurement<OperatingSystemData>>();
}
return new List<VisitGroupMeasurement<OperatingSystemData>>()
{
new VisitGroupMeasurement<OperatingSystemData>(
new VisitGroup(BuildGroupId(webVisitFacet.OperatingSystem)), // could implement JSON Serializer to take care. Check DefaultDeviceInformationSerializer within Sitecore.ExperienceAnalytics.Aggregation.dll
new List<OperatingSystemData>() // could have multiple values in some scenarios, for example Downloaded Assets
{
webVisitFacet.OperatingSystem
})
};
}
private string BuildGroupId(OperatingSystemData operatingSystem)
{
return $"{operatingSystem.Name} {operatingSystem.MajorVersion}.{operatingSystem.MinorVersion}";
}
}
}

//Calculating our metrics values depending on input data



namespace CustomReport.Demo.FlexibleDimensions {
using Sitecore.Analytics.Aggregation;
using Sitecore.ExperienceAnalytics.Aggregation.FlexibleMetrics.Framework.FactCalculation;
using Sitecore.ExperienceAnalytics.Aggregation.FlexibleMetrics.Framework.Grouping;
using Sitecore.XConnect.Collection.Model;
public class OperatingSystemFactCalculator : IFactCalculator<OperatingSystemMetrics, OperatingSystemData>
{
public OperatingSystemMetrics CalculateFactsForGroup(VisitGroupMeasurement<OperatingSystemData> groupMeasurement, IInteractionAggregationContext context)
{
return new OperatingSystemMetrics
{
Visits = 1
// Depending on our Metric we could use the context to Calculate some other values
// (example) instance.Value = context.Interaction.EngagementValue;
// (example) instance.Count = groupMeasurement.Occurrences.Count<DownloadEvent>();
// (example) instance.Conversions = context.Interaction.Events.OfType<Goal>().ToList<Goal>();
};
}
}
}

Naming: Fact_YourDimensionNameMetrics_Table.

When you create the table several columns are mandatory and required by Sitecore:

  • SegmentRecordId

  • SegmentId

  • Date

  • SiteNameId

  • DimensionKeyId

  • FilterId



--To Store the matrics value -- Execute this on Sitecore reporting database CREATE TABLE [dbo].[Fact_OperatingSystemMetrics](
[SegmentRecordId] [bigint] NOT NULL, -- Required
[SegmentId] [uniqueidentifier] NOT NULL, -- Required
[Date] [smalldatetime] NOT NULL, -- Required
[SiteNameId] [int] NOT NULL, -- Required
[DimensionKeyId] [bigint] NOT NULL, -- Required
[Visits] [int] NOT NULL -- Props from OperatingSystemMetrics.cs
CONSTRAINT [PK_Fact_OperatingSystemMetrics_1] PRIMARY KEY CLUSTERED ([SegmentRecordId] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Reference: https://doc.sitecore.com/en/developers/93/sitecore-experience-platform/walkthrough--reporting-on-a-new-dimension.html

Comments