2015-11-04 1 views
2

Я создал пользовательский поставщик GEOIP, но код, который я всегда возвращаю неизвестную страну в Analyt Analytics.Sitecore custom GEOIP провайдер неизвестна страна или неизвестный регион

enter image description here

Ниже приведены мои коды:

public class GeoLiteProvider : LookupProviderBase 
{ 
    public override WhoIsInformation GetInformationByIp(string ip) 
    { 
     const string ModuleName = "Utilities.GeoIP"; 
     string vLogging = Settings.GetSetting(ModuleName + ".VerboseLogging", "false"); 
     bool vLoggingResult = false; 
     bool verboseLogging = bool.TryParse(vLogging, out vLoggingResult); 

     if (!vLoggingResult) 
     { 
      verboseLogging = false; 
     } 


     WebRequest rssReq = WebRequest.Create("http://www.telize.com/geoip/" + ip); 
     WebProxy px = new WebProxy("http://www.telize.com/geoip/" + ip, true); 

     rssReq.Proxy = px; 
     rssReq.Timeout = 2000; 

     WhoIsInformation information = new WhoIsInformation(); 

     try 
     { 
      WebResponse rep = rssReq.GetResponse(); 
      StreamReader content = new StreamReader(rep.GetResponseStream()); 
      var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); 
      System.Collections.Generic.Dictionary<string, object> jsonObject = (System.Collections.Generic.Dictionary<string, object>)serializer.DeserializeObject(content.ReadToEnd()); 


      if (jsonObject != null) 
      { 
       information.Country = jsonObject["country"] != null ? jsonObject["country"].ToString() : string.Empty; 

       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.Country = " + information.Country, this); 
       } 

       information.Region = jsonObject["region"] != null ? jsonObject["region"].ToString() : string.Empty; 
       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.Region = " + information.Region, this); 
       } 

       information.City = jsonObject["city"] != null ? jsonObject["city"].ToString() : string.Empty; 
       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.City = " + information.City, this); 
       } 

       information.PostalCode = string.Empty; 
       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.PostalCode = " + information.PostalCode, this); 
       } 

       information.Latitude = double.Parse(jsonObject["latitude"].ToString()); 
       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.Latitude = " + information.Latitude, this); 
       } 

       information.Longitude = double.Parse(jsonObject["longitude"].ToString()); 
       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.Longitude = " + ((information.Longitude == 0) ? string.Empty : information.Longitude.ToString()), this); 
       } 

       information.MetroCode = string.Empty; 
       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.MetroCode = " + information.MetroCode, this); 
       } 

       information.AreaCode = jsonObject["area_code"] != null ? jsonObject["area_code"].ToString() : string.Empty; 
       if (verboseLogging) 
       { 
        Log.Info(ModuleName + ": information.AreaCode = " + information.AreaCode, this); 
       } 
      } 
      else 
      { 
       Log.Info(ModuleName + ": IP location cannot be determined. IP Address: " + ip, this); 
       information.BusinessName = Settings.GetSetting(ModuleName + ".NoLocationText", "Not Available"); 
      } 

      if (verboseLogging) 
      { 
       Log.Info(ModuleName + ": IP Lookup Complete", this); 
      } 

     } 
     catch(Exception ex) 
     { 

      Log.Error(ModuleName + ": Exception occurred. Exception: " + ex.Message, this); 
     } 

     return information; 
    }} 

Config Patch:

<lookupManager> 
     <patch:attribute name="defaultProvider">geoLite</patch:attribute> 
     <providers> 
     <add patch:after="*[@type='Sitecore.Analytics.Lookups.MaxMindProvider,Sitecore.Analytics']" name="geoLite" type="Core.Utilities.LookupProvider.GeoLiteProvider, Core.Utilities" /> 
     </providers> 
    </lookupManager> 

Я также создал конвейер для переопределения IP-адрес, чтобы я мог проверить это в моей локальной машине но все еще не удается.

public class OverrideIPAddress 
    { 
     public void Process(StartTrackingArgs args) 
     { 
      Tracker.Current.Interaction.Ip = System.Net.IPAddress.Parse("1.68.0.0").GetAddressBytes(); 
     } 
    } 

Sitecore.Analytics.Tracking.Config:

<startTracking> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.RaiseStartTracking, Sitecore.Analytics" /> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.InitializeTracker, Sitecore.Analytics" /> 
     <processor type="Utilities.GEOIP.OverrideIPAddress, Core.Utilities" /> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.TrackerInitialized, Sitecore.Analytics" /> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.UpdateGeoIpData, Sitecore.Analytics" /> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.ProcessQueryStringCampaign, Sitecore.Analytics" /> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.ProcessQueryStringPageEvent, Sitecore.Analytics" /> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.ProcessQueryStringTriggers, Sitecore.Analytics"> 
      <triggers hint="raw:AddTrigger"> 
      <trigger querystring="sc_rss" eventname="RSS"/> 
      </triggers> 
     </processor> 
     <processor type="Sitecore.Analytics.Pipelines.StartTracking.ProcessItem, Sitecore.Analytics"/> 
     </startTracking> 

Вот что я получаю, когда я debugg в моей локальной машине:

enter image description here

Кроме того, я добавил это в мой BaseLayouts.

@Html.Sitecore().VisitorIdentification() 

Дайте мне знать, что у меня пропало.

ответ

0

Я абсолютно уверен, что страны должны быть коды стран, которые выравнивают с элементами в пути /Sitecore/система/Настройки/Аналитика/Lookups/Страны

Вы заметите, что эти пункты все они имеют поле «Код страны», и это значение, которое вы обычно находите в данных аналитики.

Судя по тому, что вы разместили выше, я предполагаю, что ваша служба возвращает полное имя? Я хотел бы предложить установить статический словарь в конвейере Init, который считывает все значения CountryItem, введенные по имени страны, и вы можете использовать это для кодирования значений из вашей службы. Возможно, в Sitecore уже есть такой словарь, но с беглым взглядом я не смог его найти.

Смежные вопросы