2

I am using Sitecore Experience Platform 9.0 rev. 180604 (9.0 Update-2) and my Experience profile does not show the Contacts that I have created, except for one Anonymous Contact that existed a month ago. The custom form submit action is supposed to get the details of the user (firstName, lastName, email) and identifies it as a Contact, but Experience Profile does not show it.

So for the steps I have tried (I actually have two variants of code in adding a Contact):

public virtual ContactIdentifier CreateContact(string email, PersonalInformation personalInfo)
    {
        var identifier = new ContactIdentifier(ContactSource, email, ContactIdentifierType.Known);
        var identifiers = new ContactIdentifier[] { identifier };

        try
        {
            if (CurrentTracker != null && CurrentTracker.IsActive && CurrentTracker.Session != null)
            {
                CurrentTracker.Session.IdentifyAs(ContactSource, email);
                CurrentTracker.Contact.Tags.Set("isEmpty", "false");
            }

            using (var client = SitecoreXConnectClientConfiguration.GetClient())
            {
                var knownContact = new Contact(identifiers);
                client.SetFacet(knownContact, PersonalInformation.DefaultFacetKey, personalInfo);
                client.AddContact(knownContact);
                client.Submit();
            }
        }
        catch (XdbExecutionException ex)
        {
            Log.Error("Exception creating contact", ex, this);
        }
        return identifier;
    }

and the second one which I took the snippet from Sitecore documentation:

public virtual bool CreateContact2(string email, PersonalInformation personalInfo)
    {
        if (CurrentTracker.Contact.IsNew)
        {
            var manager = Factory.CreateObject("tracking/contactManager", true) as ContactManager;

            if (manager != null)
            {
                CurrentTracker.Contact.ContactSaveMode = ContactSaveMode.AlwaysSave;
                manager.SaveContactToCollectionDb(CurrentTracker.Contact);

                var trackerIdentifier = new IdentifiedContactReference(Sitecore.Analytics.XConnect.DataAccess.Constants.IdentifierSource,
                    CurrentTracker.Contact.ContactId.ToString("N"));

                using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient())
                {
                    try
                    {
                        var contact = client.Get(trackerIdentifier, new ContactExpandOptions());

                        if (contact != null)
                        {
                            client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInfo);
                            client.Submit();
                            manager.RemoveFromSession(CurrentTracker.Contact.ContactId);
                            CurrentTracker.Session.Contact = manager.LoadContact(CurrentTracker.Contact.ContactId);
                        }
                    }
                    catch (XdbExecutionException ex)
                    {
                        Log.Error("Error in creating Contact.", ex, this);
                        return false;
                    }
                }
            }
        }
        return true;
    }

Both of them ran successfully. And I can see my Contacts being created in my SQL Server (Xdb.Collection.shard0 and shard1) ContactFacets table:

enter image description here

Additional details:

  • I have enabled my PII and Anonymous indexing
  • I also ran the XConnectSearchIndexer -rr to rebuild my Reporting Database
  • And also disabled my Robot Detection from here

  • And my xConnect services are running, no problem

Am I missing something here?

P.S. I am testing my form via the Experience Editor > Preview mode of the page, does this have an effect?

2
  • Can you see any error in console while you are submitting in preview mode? May 30, 2019 at 17:54
  • Hi @SwatiGupta, I don't see any exceptions but I can see these in yellow warnings: - SessionTimeout not found in settings scForm.Settings - Error: INSTANCE.WEB is not a valid domain. Please add it to the cookie consent manager to authorize the domain. May 31, 2019 at 3:04

2 Answers 2

5

You need to add user interaction (either event or goal) before submitting the contact to XDB. I have Updated your first variant code as below:

public virtual ContactIdentifier CreateContact(string email, PersonalInformation personalInfo)
    {
        var identifier = new ContactIdentifier(ContactSource, email, ContactIdentifierType.Known);
        var identifiers = new ContactIdentifier[] { identifier };

        try
        {
            if (CurrentTracker != null && CurrentTracker.IsActive && CurrentTracker.Session != null)
            {
                CurrentTracker.Session.IdentifyAs(ContactSource, email);
                CurrentTracker.Contact.Tags.Set("isEmpty", "false");
            }

            using (var client = SitecoreXConnectClientConfiguration.GetClient())
            {
                var knownContact = new Contact(identifiers);
                client.SetFacet(knownContact, PersonalInformation.DefaultFacetKey, personalInfo);
                client.AddContact(knownContact);

                // Add User interaction before submit contact
                Guid channelId = Guid.Parse("27A7E0C2-DE17-46C8-8AA3-CFEC0434CCEB");
                var interaction = new Sitecore.XConnect.Interaction(knownContact, InteractionInitiator.Brand, channelId, "userAgent");
                var fakeItemID = Guid.Parse("1D5C266A-112F-4EA2-A69E-E4865ACE2200"); // Replace with real item ID
                PageViewEvent pageView = new PageViewEvent(DateTime.UtcNow, fakeItemID, 3, "en")
                {
                    Duration = new TimeSpan(0, 0, 30),
                    Url = "/Home"
                };
                interaction.Events.Add(pageView);
                client.AddInteraction(interaction);

                client.Submit();
            }
        }
        catch (XdbExecutionException ex)
        {
            Log.Error("Exception creating contact", ex, this);
        }
        return identifier;
    }
2
  • 1
    It worked! Thank you @Himmat! Although it makes sense to have a visitor interact with the pages so they could qualify as an organic Contact, I think it should still be appearing in the Experience Profile and that Sitecore should identify it as a Contact with no interaction yet, rather than hiding them even when we have followed the code as mentioned in the documentation. May 31, 2019 at 6:50
  • I did it but after doing this I am getting two entries in the experience profile as in the screenshot drive.google.com/file/d/1LYNotVBvDguaAyghpoOLrIhDOQgDKzd3/… out of the yellow color one with having Name column as unknown has no data associated (like activity, details) but with the remaining has useful data. I am not sure why two entries are being created. Oct 10, 2020 at 18:49
1

You also need to add at least one Interaction like goal or page view event. Below are the code:

using (var client = this.CreateClient())
{
                    //Set your facets here
                    // Interaction
                    Guid channelId = Guid.Parse(ChannelId);
                    string userAgent = "Form Update Contact";
                    var interaction = new Interaction(contact, InteractionInitiator.Brand, channelId, userAgent);

                    var ItemID = Guid.Parse(HomeId);

                    PageViewEvent pageView = new PageViewEvent(DateTime.UtcNow, ItemID, 3, "en")
                    {
                        Duration = new TimeSpan(0, 0, 30),
                        Url = "/Home"
                    };

                    interaction.Events.Add(pageView);

                    client.AddInteraction(interaction);
                    client.Submit();
}
protected virtual IXdbContext CreateClient()
{
            return SitecoreXConnectClientConfiguration.GetClient();
}
1
  • Hi @Swati, yes you're right, it's the Interaction that's missing. May 31, 2019 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.