3

我是 Sitecore 的新手。我正在尝试实现以下进程类来覆盖GeoIP值以进行测试。

我找不到类 Tracker 位于哪个命名空间中。请注意,我使用的是托管在 localhost 上的Sitecore 8 。Sitecore 博客:@sitecorejohn 博客

有人可以帮我解决这个命名空间问题吗?

谢谢。

namespace Sitecore.Sharedsource.Analytics.Pipelines.StartTracking
{
    using System.Net;

    using Sitecore.Analytics;
    using Sitecore.Analytics.Pipelines.StartTracking;

    public class OverrideIPAddress
    {
        public void Process(StartTrackingArgs args)
        {
            if (Tracker.CurrentVisit == null
              || Tracker.CurrentVisit.GeoIp == null
              || Tracker.CurrentVisit.Ip == null)
            {
                return;
            }

            string ip = new IPAddress(
              Tracker.CurrentVisit.GeoIp.Ip).ToString();

            if (ip != "0.0.0.0" && ip != "127.0.0.1")
            {
                return;
            }

            string html = Sitecore.Web.WebUtil.ExecuteWebPage(
              "http://www.whatismyip.com/automation/n09230945.asp");
            IPAddress address = IPAddress.Parse(html);
            Tracker.CurrentVisit.GeoIp =
              Tracker.Visitor.DataContext.GetGeoIp(address.GetAddressBytes());
        }
    }
}
4

1 回答 1

5

Tracker类在Sitecore.Analytics命名空间中。

确保您的项目引用Sitecore.Analytics.dll.

Sitecore 8中,您应该使用Tracker.Currentand Tracker.Current.Interaction而不是Tracker.CurrentVisit

Tracker.Current.Interaction.Ip = address.GetAddressBytes();
Tracker.Current.Interaction.UpdateGeoIpData(optionalTimeout);

您可以考虑在处理器CreateVisit之后将另一个处理器添加到管道XForwardedFor并调用:

args.Interaction.Ip = address.GetAddressBytes();

您不必调用UpdateGeoIpData- 它会在UpdateGeoIpData处理器中自动调用。

于 2015-07-16T11:55:43.433 回答