1

This is the method I have to register a Contact and their facets to the xDb (I have also registered some of my personal facets). However upon registering, my known contacts visits and visit duration does not show up.

enter image description here

I've tried adding this line according to the documentation provided by sitecore @ https://doc.sitecore.com/en/developers/101/sitecore-experience-platform/tracking-contacts.html but I'm getting this error.

enter image description here

How do I keep track of known contact visits upon registration with my AddContact Method?

public ActionResult AddContact(string email, string UEN, string phoneNumber)
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    var number = new Random();
                    var number2 = number.Next();
                    string emailAddress = number2 + "myrtle@test.test";


                    IDefinition ev = Sitecore.Analytics.Tracker.MarketingDefinitions.Goals[ABCD.iD];

                    if (ev != null)
                    {
                        var registerId = new Guid("8FFB183B-DA1A-4C74-8F3A-9729E9FCFF6A"); // Fake newsletter ID
                        var pageData = new Sitecore.Analytics.Data.PageEventData(ev.Alias, ev.Id);

                        pageData.Data = registerId.ToString();

                        Sitecore.Analytics.Tracker.Current.CurrentPage.Register(pageData);
                    }

                    Contact contact = new Contact(new ContactIdentifier("WebVisit", UEN , ContactIdentifierType.Known));

                    UENInfo uenInfo = new UENInfo()
                    {
                        UEN = UEN                    
                    };

                    client.SetFacet(contact, uenInfo);

                    // Facet with a reference object, key is specified
                    PersonalInformation personalInfoFacet = new PersonalInformation()
                    {
                        FirstName = "User" + number.Next(),
                        LastName = "McSitecore"
                    };

                    FacetReference reference = new FacetReference(contact, PersonalInformation.DefaultFacetKey);

                    client.SetFacet(reference, personalInfoFacet);

                    
                    // Facet without a reference, using default key
                    EmailAddressList emails = new EmailAddressList(new EmailAddress(email , true), "Home");

                    client.SetFacet(contact, emails);

                    // Facet without a reference, key is specified

                    AddressList addresses = new AddressList(new Address() { AddressLine1 = "Cool Street 12", City = "Sitecore City", PostalCode = "ABC 123" }, "Home");

                    client.SetFacet(contact, AddressList.DefaultFacetKey, addresses);


                    client.AddContact(contact); // Extension found in Sitecore.XConnect.Operations

                    // Submits the batch, which contains two operations
                    client.Submit();

                }
                catch (XdbExecutionException ex)
                {
                    // Manage exception
                }
            }
            return View();
        }
4
  • May I know the Sitecore version you're using ? Dec 3 '21 at 5:03
  • You can try checking the logs from the XConnect site folder to see if there is any exception / error messages there. Dec 3 '21 at 5:27
  • Have you done an upgrade to get to this point? IdentifyAs() is still the method to identify users in Sitecore. Your code looks fine.
    – Chris Auer
    Dec 3 '21 at 14:48
  • Please check the details at github.com/AmitKumar-AK/CT.SC/blob/master/src/Feature/Accounts/… and it may be helpful to implement required use case.
    – Amit Kumar
    Dec 7 '21 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.