Skip to content

Instantly share code, notes, and snippets.

@Azadehkhojandi
Created April 6, 2016 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azadehkhojandi/b365dd9d443e49d0675ae296eb547999 to your computer and use it in GitHub Desktop.
Save Azadehkhojandi/b365dd9d443e49d0675ae296eb547999 to your computer and use it in GitHub Desktop.
Add Sitecore page event report to Experience Analytics - adding a chart to show top internal search keywords which returns no result (/sitecore/system/Settings/Analytics/Page Events/No search hits found)
public class ByLocalSearchNoResult : PageEventDimensionBase
{
private readonly Guid noSearchHitsFoundId = AnalyticsIds.NoSearchHitsFound.Guid;
public ByLocalSearchNoResult(Guid dimensionId) : base(dimensionId)
{
}
public override bool Filter(PageEventData pageEventData)
{
Assert.IsNotNull((object)pageEventData, "pageEvent");
return pageEventData.PageEventDefinitionId.Equals(this.noSearchHitsFoundId);
}
public override IEnumerable<string> ExtractDimensionKeys(PageEventData pageEvent)
{
Assert.IsNotNull((object)pageEvent, "pageEvent");
yield return CustomStringExtensions.ToCanonical(pageEvent.Text);
}
}
public interface IRegisterPageDataService
{
void RegisterPageEvent(string eventName, string text, string data, string dataKey);
}
public class RegisterPageDataService : IRegisterPageDataService
{
public void RegisterPageEvent(string eventName, string text, string data, string dataKey)
{
if (!Tracker.Enabled)
return;
if (!Tracker.IsActive)
Tracker.StartTracking();
ICurrentPageContext currentPage = Tracker.Current.CurrentPage;
if (currentPage == null)
return;
RegisterPageDataService.RegisterEventOnCurrentPage(eventName, text, data, dataKey, (IPageContext) currentPage);
}
private static void RegisterEventOnCurrentPage(string eventName, string text, string data, string dataKey, IPageContext currentPage)
{
PageEventData pageEventData = new PageEventData(eventName);
pageEventData.Text = text;
string str1 = data ?? string.Empty;
pageEventData.Data = str1;
string str2 = string.IsNullOrEmpty(dataKey) ? string.Empty : dataKey;
pageEventData.DataKey = str2;
PageEventData pageData = pageEventData;
try
{
currentPage.Register(pageData);
}
catch (Exception ex)
{
Log.Error(string.Format("{0} page event not created in current Sitecore Instance: {1}", (object) eventName, (object) ex), typeof (RegisterPageDataService));
}
}
<configuration xmlns:x="http://www.sitecore.net/xmlconfig/" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<sitecore>
<experienceAnalytics>
<aggregation>
<!-- This section hosts the definitions of the Experience Analytics dimensions
'id' attribute is the unique identifier and should match the ID of the corresponding dimension definition item in Marketing Control Panel
'type' attribute references the fully qualified class name and assembly name with the dimension implementation.
-->
<dimensions>
<dimension id="dimension id you added in sitecore /sitecore/system/Marketing Control Panel/Experience Analytics/Dimensions/Visits/By local search no result" type="{yournamespace}.ByLocalSearchNoResult, {yournamespace}" xdt:Transform="Insert" />
</dimensions>
</aggregation>
</experienceAnalytics>
</sitecore>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment