Thursday, December 7, 2023

seperating the internal traffic in sitecore dashboard experience analytics


Add following facets on the Databases:

1) Core Database

Create a new type Traffic as remaining types defined in sitecore.with the template
/sitecore/client/Speak/Templates/Pages/Speak-DashboardPage



1) PageSettings(/sitecore/client/Speak/Templates/Pages/PageSettings)
copy devices pagesttings(/sitecore/client/Applications/ExperienceAnalytics/Dashboard/Audience/Devices/PageSettings) and rename to traffic type create as below

ExperienceAnalytics Stylesheet(/sitecore/client/Speak/Templates/Pages/Page-Stylesheet-File) same as remaining exp analytics stylesheet


2) Master Database

create a visit type under the /sitecore/system/Marketing Control Panel/Experience Analytics/Dimensions/Visits as By Traffic template(/sitecore/templates/System/Experience Analytics/Dimension)

and Create a  segment name All visits by traffic with the below template

/sitecore/templates/System/Experience Analytics/Segment



create a cshrap code as below

using Sitecore.Analytics;
using Sitecore.Analytics.Aggregation.Data.Model;
using Sitecore.ExperienceAnalytics.Aggregation.Dimensions;
using System;

namespace Domain.Infrastructure.Analytics
{
  public class ByTraffic : VisitDimensionBase
  {
    public ByTraffic(Guid dimensionId) : base(dimensionId)
    {

    }
    public override bool HasDimensionKey(IVisitAggregationContext context)
    {
      return context.Visit.Ip.Length > 0;
    }

    public override string GetKey(IVisitAggregationContext context)
    {
      if ((Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(1).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(2).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(3).ToString() == "some ip"))
      {
        return "Dynatrace Portal";
      }
      else if ((Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(1).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(2).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(3).ToString() == "some ip")
        || (Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(1).ToString() == "some ip"))
      {
        return "Dynatrace Synthetic Monitors";
      }
      else if ((Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(1).ToString() == "some ip")
      || (Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(1).ToString() == "some ip" && Tracker.Current.Session.Interaction.Ip.GetValue(2).ToString() == "some ip")
      || (Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "207" && Tracker.Current.Session.Interaction.Ip.GetValue(1).ToString() == "211" && Tracker.Current.Session.Interaction.Ip.GetValue(2).ToString() == "37" && Tracker.Current.Session.Interaction.Ip.GetValue(3).ToString() == "4")
      || (Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "10")
      || (Tracker.Current.Session.Interaction.Ip.GetValue(0).ToString() == "127" && Tracker.Current.Session.Interaction.Ip.GetValue(1).ToString() == "0" && Tracker.Current.Session.Interaction.Ip.GetValue(2).ToString() == "0" && Tracker.Current.Session.Interaction.Ip.GetValue(3).ToString() == "1"))
      {
        return "Internal Public IP";
      }

      return "External";
    }
  }
}

add add a below patch config

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <experienceAnalytics>
      <api enabled="true">
        <dimensions>
          <dimension id="ByTraffic ID from Master db">
            <transformer type="Sitecore.ExperienceAnalytics.Api.Response.DimensionKeyTransformers.DefaultDimensionKeyTransformer, Sitecore.ExperienceAnalytics.Api"/>
          </dimension>
        </dimensions>
      </api>
      <reduce>
        <dimensions>
          <dimension id="ByTraffic ID from Master db" type="Domain.Infrastructure.Analytics.ByTraffic, Domain.Infrastructure" />
        </dimensions>
      </reduce>
      <aggregation>
        <dimensions>
          <dimension id="ByTraffic ID from Master db" type="Domain.Infrastructure.Analytics.ByTraffic, Domain.Infrastructure" />
        </dimensions>
      </aggregation>
    </experienceAnalytics>
  </sitecore>
</configuration>

result:



No comments:

Post a Comment