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?

  • Can you see any error in console while you are submitting in preview mode? – Swati Gupta May 30 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. – Bien Angelo Relucano May 31 at 3:04
8

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;
    }
  • 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. – Bien Angelo Relucano May 31 at 6:50
3

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();
}
  • Hi @Swati, yes you're right, it's the Interaction that's missing. – Bien Angelo Relucano May 31 at 6:52

Your Answer

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

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