4

Sitecore: 9.0.2

I am trying to update xDB for contacts with the Outcome. The source of data is from third party, so I cannot go through Tracker.

I am using the following code snippet Code snippet:

Interaction webInteraction = new Interaction(existingContact, InteractionInitiator.Brand, new Guid(Constants.Analytics.ChannelId), "Website");
     Outcome outcome = new Outcome(new Guid(Constants.MarketingGoals.ProductPurchaseOutcome), date, currency, amount);
     webInteraction.Events.Add(outcome);
     client.AddInteraction(webInteraction);
     client.Submit();

But this is not getting updated against InteractionsCache facet. I do not see any error related to it.

What I am missing? Thanks for your help.

1
  • Can you add surrounding code to the code snippet that is currently in your question? Especially how you instantiate client... – Commented Nov 9, 2019 at 19:26

2 Answers 2

3

Is this in Sitecore Context or outside the context (aka a raw call to xConnect)

In Sitecore Context

Habitat has a good example of this https://github.com/Sitecore/Habitat/blob/2d3ee809fa4035a46a410d0438ed41e1c7f8a3b1/src/Foundation/SitecoreExtensions/code/Services/TrackerService.cs#L100

OutcomeDefinitionManager comes from DI IDefinitionManager<IOutcomeDefinition> outcomeDefinitionManager

public void TrackOutcome(Guid outComeDefinitionId)
{
    Assert.ArgumentNotNull(outComeDefinitionId, nameof(outComeDefinitionId));

    if (!this.IsActive || Tracker.Current.Contact == null)
    {
        return;
    }

    var outcomeDefinition = this.OutcomeDefinitionManager.Get(outComeDefinitionId, CultureInfo.InvariantCulture);
    if (outcomeDefinition == null)
    {
        Log.Warn($"Cannot find outcome: {outComeDefinitionId}", this);
        return;
    }
    Tracker.Current.CurrentPage.RegisterOutcome(outcomeDefinition, "USD", 0);
}

Raw xConnect

This Sitecore doco has the code you need. https://doc.sitecore.com/developers/90/sitecore-experience-platform/en/add-interaction-events.html

using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
    try
    {
        var contact = new Sitecore.XConnect.Contact();

        var channel = Guid.NewGuid(); // Use real channel ID from Sitecor

        var interaction = new Interaction(contact, InteractionInitiator.Brand, channel, "iTunes/9.0.3 (Macintosh; U; Intel Mac OS X 10_6_2; en-ca)"); // Agent is iTunes

        Guid outcomeId = Guid.Parse("{21EC2020-3AEA-4069-A2DD-08002B30309D}"); // ID of outcome item

        var outcome = new Sitecore.XConnect.Outcome(outcomeId, DateTime.UtcNow, "USD", 100.00m);

        interaction.Events.Add(outcome);

        client.AddContact(contact);
        client.AddInteraction(interaction);

        await client.SubmitAsync();
    }
    catch (XdbExecutionException ex)
    {
        // Handle exception
    }
}

Look in SQL

You can look in SQL to see your custom interaction with the custom outcome on the event. You just need the contact Id from the code.

SELECT TOP (1000) [InteractionId]
      ,[LastModified]
      ,[Created]
      ,[ConcurrencyToken]
      ,[ContactId]
      ,[StartDateTime]
      ,[EndDateTime]
      ,[Initiator]
      ,[DeviceProfileId]
      ,[ChannelId]
      ,[VenueId]
      ,[CampaignId]
      ,[Events]
      ,[UserAgent]
      ,[EngagementValue]
      ,[Percentile]
  FROM [Xdb.Collection.Shard0].[xdb_collection].[Interactions]
  WHERE ContactId = 'A86801E3-A35E-0000-0000-058CDEB592D7'
8
  • I am using the second way as you have mentioned. But it is not getting updated. Commented Nov 10, 2019 at 4:07
  • Can you log the contact ID when you process one and then query SQL to see if you can see it. I added the SQL to my answer above. I am wondering if it is working and you just can't see it in XP.
    – Chris Auer
    Commented Nov 10, 2019 at 4:16
  • I was checking in xDB only. Presently I am re-deploying all the marketing definitions. as I see 'Dimension could not be resolved for for dimension id: f81ef8cb-2662-491c-8f0f-da858dbddf54'. Not sure if they are related. Let's see. Commented Nov 10, 2019 at 6:43
  • Sorry, this didn't work. Commented Nov 10, 2019 at 8:40
  • I know you are using the 2nd snippet of code, but are you running this in your sitecore website. Or from a remote site, like a console app?
    – Chris Auer
    Commented Nov 10, 2019 at 12:32
2

Thanks to the Sitecore Support team for helping.

In case someone else also gets into this issue:

xConnect has the following configuration:

<ICalculatedFacetHandler.InteractionsCacheHandler>
<Type>Sitecore.XConnect.Collection.Model.Plugins.InteractionsCacheHandler, Sitecore.XConnect.Collection.Model.Plugins</Type>
<As>Sitecore.XConnect.Service.ICalculatedFacetHandler, Sitecore.XConnect.Service</As>
<LifeTime>Singleton</LifeTime>
<Options>
<MaximumInteractionCount>42</MaximumInteractionCount>
<MaximumCacheEntryCount>50</MaximumCacheEntryCount>
<MaximumInteractionPeriod>30.00:00:00</MaximumInteractionPeriod>
</Options>
</ICalculatedFacetHandler.InteractionsCacheHandler>

The interaction I was trying to insert was of 2015, which was quite older than 30 days. Hence I had this issue.

Your Answer

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

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