2

I'm using sitecore 9.1.1.

I need to insert custom contact facet and custom interaction facet using below pipeline processor. I have already added custom values successfully in the same processor.

Personal() and WebVisit() are null hence getting error(object reference not set).

is there any other way around to get it done by injecting into args object.

public class ConvertInteractionFacet : ConvertToXConnectInteractionProcessorBase
{    
    public override void Process(ConvertToXConnectInteractionPipelineArgs args)
    {
        if (args != null)
        {
            //contact facet
            args.XConnectContact.Personal().FirstName = "myfirstnametest";
            args.XConnectContact.Personal().LastName = "mylastnametest";

            //interaction facet
            args.XConnectInteraction.WebVisit().SearchKeywords = "mytesting123";
        }
    }
}
5
  • Why are you do it on ConvertToXConnectInteraction which is when the session is closing. Why not do it in session? – Chris Auer Mar 1 at 14:55
  • sitecore is capturing all the interaction post session end. I wanted to inject my custom values into same interaction that sitecore was going to submit to xConnect. I got only this way around to make it happen successfully. please suggest if you have any better approach. Thanks. – Erwin Paul Mar 1 at 15:31
  • When you say it is capturing post session end, you mean you need it that way? I added an answer for how to capture these two in session. Now sure if it meets your needs. I will delete if it doesn't. – Chris Auer Mar 1 at 16:00
  • it wont work as client.submit() creates new interaction in xDB. at the same time sitecore also adding interaction into table hence we are using ConvertToXConnectInteraction processor to inject custom data before sitecore creating interaction against contact. – Erwin Paul Mar 1 at 16:50
  • 1
    Client submit does not create a new interaction on contact updates. It just updates the contact. Interactions updates, sure. But you can use my code below to add a search term event to your session interaction. – Chris Auer Mar 1 at 16:52
2

Going off the comments that you might feel its the only place you can add this data is in session end. Here is the code to do it in session.

Search word: https://doc.sitecore.com/developers/93/sitecore-experience-platform/en/triggering-built-in-events.html

var searchEvent = Tracker.MarketingDefinitions.PageEvents[AnalyticsIds.SearchEvent.Guid];

Sitecore.Analytics.Tracker.Current.CurrentPage.Register(new PageEventData(searchEvent.Alias, searchEvent.Id)
{
    Data = "sitecore experience platform"
});

Updating personal info names. This is not complete code. You should have your own code for getting the xConnect client and contact. My getting code can be found in my answer here (Bind current visitor with Sitecore contact)

public void UpdateFacetInfo(ContactInfo contactInfo)
{
    var contactFacetsProvider = new ContactFacetsProvider();
    var contactReference = this.contactIdentificationRepository.GetContactReference();

    var facetsToGet = new List<string>
    {
        PhoneNumberList.DefaultFacetKey
    };

    using (var client = this.contactIdentificationRepository.CreateContext())
    {
        var contact = client.Get(contactReference, new ContactExpandOptions(facetsToGet.ToArray()));
        if (contact == null)
        {
            throw new ArgumentNullException(nameof(contact));
        }

        // set personal info
        var personalInformation = contact.GetFacet<PersonalInformation>(PersonalInformation.DefaultFacetKey) ?? new PersonalInformation();

        personalInformation.FirstName = contactInfo.FirstName;
        personalInformation.LastName = contactInfo.LastName;

        client.SetPersonal(contact, personalInformation);
        client.SetFacet(contact, PersonalInformation.DefaultFacetKey, personalInformation);

        client.Submit();
        contactFacetsProvider.UpdateTracker();
    }
}

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.