2

I would like to get check whether certain goal was triggered through xConnect for certain contact programmatically. We are using Sitecore 9.0.1.

I have found this article: https://doc.sitecore.net/developers/xp/xconnect/xconnect-client-api/interactions/get-interactions/get-events.html#get-events-by-definition-id

But it is unclear which ID I should use on this line:

Sitecore.XConnect.InteractionReference interactionRef = new Sitecore.XConnect.InteractionReference(contactRef, Guid.Parse("DA2DA5F0-4348-E611-82E7-34E6D7117DCB"));

Id DA2DA5F0-4348-E611-82E7-34E6D7117DCB is Id of what?

It is an Id of Interaction that is stored in DB?

How can I get it via xConnect API?

I just want to check whether goal what trigger for contact

  • Do we have any idea what DA2DA5F0-4348-E611-82E7-34E6D7117DCB is in reference to? – Chris Auer May 4 '19 at 0:05
  • If I remember correctly, it is coming from [xdb_collection].[Interactions] table from one of the shard dbs and it's [InteractionId] @ChrisAuer – Peter Procházka May 6 '19 at 5:51
3

Found answer after going through xConnect documentation more thoroughly.

Here is the code that you can use to get all goals for contact:

using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
        {
            try
            {
                var contactID = Guid.Parse("ea991dce-1f9b-443c-84a5-f83b46cbc0f8");

                // IMPORTANT: You cannot check facets for null; check a property of the facet instead, such as SiteName for WebVisit
                var queryable = client.Interactions
                    .Where(x => x.Contact.Id == contactID
                    && x.Events.OfType<Goal>().Any())
                    .WithExpandOptions(new InteractionExpandOptions(WebVisit.DefaultFacetKey) { Contact = new RelatedContactExpandOptions(PersonalInformation.DefaultFacetKey) });

                var enumerator = queryable.GetBatchEnumeratorSync(10);

                while (enumerator.MoveNext())
                {
                    foreach (var item in enumerator.Current)
                    {
                        var listOfGoals = item.Events.OfType<Goal>();
                    }
                }

            }
            catch (XdbExecutionException ex)
            {
                // Handle exception
            }
        }

Add these two nuget packages to your project to resolve all assembly conflicts:

<package id="System.Interactive.Async" version="3.1.1" targetFramework="net462" />
<package id="System.Interactive.Async.Providers" version="3.1.1" targetFramework="net462" />

More details here: https://doc.sitecore.net/developers/xp/xconnect//xconnect-client-api/contacts/get-contacts/get-contact-interactions.html#filtering-interactions

| improve this answer | |

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.