【问题标题】:how to collect sitecore information for anonymous如何收集匿名站点核心信息
【发布时间】:2018-11-29 13:54:52
【问题描述】:

我需要获取从匿名用户那里收集的站点核心信息,以便他可以导出或选择退出 - [GDPR]

关于匿名联系人 ID 的任何想法!

【问题讨论】:

    标签: sitecore sitecore-analytics sitecore9 sitecore-sxa


    【解决方案1】:

    执行方式取决于站点核心版本。

    关于匿名用户 - 如果用户真的是匿名用户,那么您确实需要担心 GDPR(我的观点)。但有时我们会使用表单或 WFFM 将用户电子邮件和敏感的个人信息映射到匿名用户。您可以使用该用户的电子邮件地址查询 xDB (Contact Identifiers) 以获取联系人和联系人 ID。然后重置信息。

    另外:请注意,基于 WFFFM 保存操作配置,匿名用户将存储在 Core DB 和联系人列表中。

    【讨论】:

      【解决方案2】:

      要忘记用户,您可以使用以下代码。它将对联系人执行 ExecuteRightToBeForgotten 函数并清理他们的数据。

      忘记用户

      public bool ForgetUser()
      {
          var id = _contactIdentificationRepository.GetContactId();
          if (id == null)
          {
              return false;
          }
      
          var contactReference = new IdentifiedContactReference(id.Source, id.Identifier);
      
          using (var client = _contactIdentificationRepository.CreateContext())
          {
              var contact = client.Get(contactReference, new ContactExpandOptions());
              if (contact != null)
              {
                  client.ExecuteRightToBeForgotten(contact);
                  client.Submit();
              }
          }
      
          return false;
      }
      

      伪造一些数据

      public void FakeUserInfo()
      {
          var contactReference = _contactIdentificationRepository.GetContactReference();
      
          using (var client = SitecoreXConnectClientConfiguration.GetClient())
          {
              // we can have 1 to many facets
              // PersonalInformation.DefaultFacetKey
              // EmailAddressList.DefaultFacetKey
              // Avatar.DefaultFacetKey
              // PhoneNumberList.DefaultFacetKey
              // AddressList.DefaultFacetKey
              // plus custom ones
              var facets = new List<string> { PersonalInformation.DefaultFacetKey };
      
              // get the contact
              var contact = client.Get(contactReference, new ContactExpandOptions(facets.ToArray()));
      
              // pull the facet from the contact (if it exists)
              var facet = contact.GetFacet<PersonalInformation>(PersonalInformation.DefaultFacetKey);
      
              // if it exists, change it, else make a new one
              if (facet != null)
              {
                  facet.FirstName = $"Myrtle-{DateTime.Now.Date.ToString(CultureInfo.InvariantCulture)}";
                  facet.LastName = $"McSitecore-{DateTime.Now.Date.ToString(CultureInfo.InvariantCulture)}";
      
                  // set the facet on the client connection
                  client.SetFacet(contact, PersonalInformation.DefaultFacetKey, facet);
              }
              else
              {
                  // make a new one
                  var personalInfoFacet = new PersonalInformation()
                  {
                      FirstName = "Myrtle",
                      LastName = "McSitecore"
                  };
      
                  // set the facet on the client connection
                  client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfoFacet);
              }
      
              if (contact != null)
              {
                  // submit the changes to xConnect
                  client.Submit();
      
                  // reset the contact
                  _contactIdentificationRepository.Manager.RemoveFromSession(Analytics.Tracker.Current.Contact.ContactId);
                  Analytics.Tracker.Current.Session.Contact = _contactIdentificationRepository.Manager.LoadContact(Analytics.Tracker.Current.Contact.ContactId);
              }
          }
      }
      

      ContactIdentificationRepository

      ​​>
      using System.Linq;
      using Sitecore.Analytics;
      using Sitecore.Analytics.Model;
      using Sitecore.Analytics.Tracking;
      using Sitecore.Configuration;
      using Sitecore.XConnect;
      using Sitecore.XConnect.Client.Configuration;
      
      namespace Sitecore.Foundation.Accounts.Repositories
      {
          public class ContactIdentificationRepository
          {
              private readonly ContactManager contactManager;
      
              public ContactManager Manager => contactManager;
      
              public ContactIdentificationRepository()
              {
                  contactManager = Factory.CreateObject("tracking/contactManager", true) as ContactManager;
              }
      
              public IdentifiedContactReference GetContactReference()
              {
                  // get the contact id from the current contact
                  var id = GetContactId();
      
                  // if the contact is new or has no identifiers
                  var anon = Tracker.Current.Contact.IsNew || Tracker.Current.Contact.Identifiers.Count == 0;
      
                  // if the user is anon, get the xD.Tracker identifier, else get the one we found
                  return anon
                      ? new IdentifiedContactReference(Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource, Tracker.Current.Contact.ContactId.ToString("N"))
                      : new IdentifiedContactReference(id.Source, id.Identifier);
              }
      
              public Analytics.Model.Entities.ContactIdentifier GetContactId()
              {
                  if (Tracker.Current?.Contact == null)
                  {
                      return null;
                  }
                  if (Tracker.Current.Contact.IsNew)
                  {
                      // write the contact to xConnect so we can work with it
                      this.SaveContact();
                  }
      
                  return Tracker.Current.Contact.Identifiers.FirstOrDefault();
              }
      
              public void SaveContact()
              {
                  // we need the contract to be saved to xConnect. It is only in session now
                  Tracker.Current.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave;
                  this.contactManager.SaveContactToCollectionDb(Tracker.Current.Contact);
              }
      
              public IXdbContext CreateContext()
              {
                  return SitecoreXConnectClientConfiguration.GetClient();
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-19
        • 1970-01-01
        • 2018-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多