Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为匿名用户收集sitecore信息_Sitecore_Sitecore Analytics_Sitecore9_Sitecore Sxa - Fatal编程技术网

如何为匿名用户收集sitecore信息

如何为匿名用户收集sitecore信息,sitecore,sitecore-analytics,sitecore9,sitecore-sxa,Sitecore,Sitecore Analytics,Sitecore9,Sitecore Sxa,我需要获取从匿名用户收集的sitecore信息,以便他能够导出或选择退出-[GDPR] 任何关于匿名联系人ID的想法 要忘记用户,可以使用以下代码。它将对联系人执行ExecuteRightToBeForgotten功能,并清除其数据 忘记用户 伪造一些数据 执行此操作的方式取决于sitecore版本 Sitcore 9您可以使用 Sitecore 8+您必须从头开始实施该功能。 关于匿名用户-如果用户真的是匿名的,那么您确实需要担心GDPR我的视图。但有时我们会使用表单或WFFM将用户电子邮件和

我需要获取从匿名用户收集的sitecore信息,以便他能够导出或选择退出-[GDPR]


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

要忘记用户,可以使用以下代码。它将对联系人执行ExecuteRightToBeForgotten功能,并清除其数据

忘记用户 伪造一些数据
执行此操作的方式取决于sitecore版本

Sitcore 9您可以使用 Sitecore 8+您必须从头开始实施该功能。 关于匿名用户-如果用户真的是匿名的,那么您确实需要担心GDPR我的视图。但有时我们会使用表单或WFFM将用户电子邮件和敏感个人信息映射到匿名用户。您可以使用该用户的电子邮件地址查询xDB以获取联系人和联系人ID。然后重置信息

另外:请注意,根据WFFFM保存操作配置,匿名用户将存储在核心数据库和联系人列表中

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);
        }
    }
}
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();
        }
    }
}