Last active
April 1, 2016 17:51
-
-
Save gillissm/2f2c2d8bb37067daedb4 to your computer and use it in GitHub Desktop.
Code samples used to help explain the steps requried for Sitecore Experience Anayltics custom dimensions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore.Analytics.Aggregation.Data.Model; | |
using Sitecore.ExperienceAnalytics.Aggregation.Dimensions; | |
using System; | |
namespace TheCodeAttic.ExperienceAnalytics.Aggregation | |
{ | |
public class CustomerTypeVisitDimensionBase : VisitDimensionBase | |
{ | |
public CustomerTypeVisitDimensionBase(Guid dimensionId): base(dimensionId) | |
{ | |
} | |
public override string GetKey(IVisitAggregationContext context) | |
{ | |
//Making a call to our CRM system to determine the contact type. | |
//In a fuller implementation, we could track the customer type as a custom contact facet. | |
return CRMInterface.CustomerType(context.Visit.ContactId); | |
} | |
public override bool HasDimensionKey(IVisitAggregationContext context) | |
{ | |
//Need to confirm that key will / does exist. | |
return Guid.Empty != context.Visit.ContactId; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///Extracted from Sitecore.ExperienceAnalytics.Aggregation.Dimensions.DimensionBase | |
namespace Sitecore.ExperienceAnalytics.Aggregation.Dimensions | |
{ | |
public class MetricCalculationsForVisitBase | |
{ | |
public virtual SegmentMetricsValue CalculateCommonMetrics(IVisitAggregationContext context, int count = 0) | |
{ | |
Assert.ArgumentNotNull((object)context, "context"); | |
if (context.Visit.Pages == null) | |
return (SegmentMetricsValue)null; | |
return new SegmentMetricsValue() | |
{ | |
Visits = 1, | |
Value = context.Visit.Value, | |
Bounces = context.Visit.Pages.Count == 1 ? 1 : 0, | |
Conversions = Enumerable.Count<PageEventData>(Enumerable.SelectMany<PageData, PageEventData>((IEnumerable<PageData>)context.Visit.Pages, (Func<PageData, IEnumerable<PageEventData>>)(page => (IEnumerable<PageEventData>)page.PageEvents)), (Func<PageEventData, bool>)(evt => evt.IsGoal)), | |
TimeOnSite = Enumerable.Sum<PageData>((IEnumerable<PageData>)context.Visit.Pages, (Func<PageData, int>)(page => DimensionBase.ConvertDuration(page.Duration))), | |
Pageviews = context.Visit.Pages.Count, | |
Count = count | |
}; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<experienceAnalytics> | |
<!--FROM <web root>\App_Config\Include\ExperienceAnalytics\Sitecore.ExperienceAnalytics.Reduce.config--> | |
<reduce> | |
<dimensions> | |
<dimension id="{DBBB04C0-84DC-41F2-9B06-C2207284923A}" type="TheCodeAttic.ExperienceAnalytics.Aggregation.CustomerTypeVisitDimensionBase, TheCodeAttic.ExperienceAnalytics.Aggregation" /> | |
</dimensions> | |
</reduce> | |
<!--FROM <web root>\App_Config\Include\ExperienceAnalytics\Sitecore.ExperienceAnalytics.Aggregation.config--> | |
<aggregation> | |
<dimensions> | |
<dimension id="{DBBB04C0-84DC-41F2-9B06-C2207284923A}" type="TheCodeAttic.ExperienceAnalytics.Aggregation.CustomerTypeVisitDimensionBase, TheCodeAttic.ExperienceAnalytics.Aggregation" /> | |
</dimensions> | |
</aggregation> | |
</experienceAnalytics> | |
</sitecore> | |
</configuration> | |
<!--Be sure to rename from 'XML' to 'config' if you plan to use--> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment