Sitecore 9.1
I have a super simple interaction facet that I am trying to push into xDB. Below are the facet, the model, the Json representation that I put into the xConnect Models folder and the client API call.
It does not error as long as I have any kind of an event (my goal) in the interaction. It runs, but it does not save my facet. If I remove the goal/event, it errors since I believe the interaction is empty. Seems like the facet just isn't being added to the interaction before I call the client.
I have gone over this code several times. I just can't see what I am missing.
The issue
When the code below runs, it runs successfully. But I only get the goal in the interaction. The facets are empty. No errors in the logs.
Additional error message for question SEO The type of this instance does not correspond to any type in the model. The type is Client.XdbModels.Facets.SwimEvent.
The facet
{
using System;
using Sitecore.XConnect;
[FacetKey(DefaultFacetKey)]
[Serializable]
public class SwimEvent : Facet
{
public SwimEvent()
{
}
public const string DefaultFacetKey = "SwimEvent";
public string PoolId { get; set; }
public DateTime EventDate { get; set; }
}
}
The Model
{
using Sitecore.XConnect;
using Sitecore.XConnect.Schema;
using Client.Integrations.Swim.Facets;
public class SwimEventModel
{
public static XdbModel Model { get; } = BuildModel();
private static XdbModel BuildModel()
{
var modelBuilder = new XdbModelBuilder("SwimEventModel", new XdbModelVersion(1, 0));
modelBuilder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
modelBuilder.DefineFacet<Interaction, SwimEvent>(SwimEvent.DefaultFacetKey);
return modelBuilder.BuildModel();
}
}
}
The model representation
{
"Name": "SwimEventModel",
"Version": "1.0",
"References": [
{
"Name": "XConnect",
"Version": "1.0"
},
{
"Name": "Sitecore.XConnect.Collection.Model",
"Version": "9.0"
}
],
"Types": {
"Usms.Integrations.Swim.Facets.SwimEvent": {
"Type": "Facet",
"BaseType": "Sitecore.XConnect.Facet",
"ClrType": "Client.Integrations.Swim.Facets.SwimEvent, Client.Integrations.Swim, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"Properties": {
"PoolId": {
"Type": "String"
},
"EventDate": {
"Type": "DateTime"
}
}
}
},
"Facets": [
{
"Target": "Interaction",
"Name": "SwimEvent",
"Type": "Client.Integrations.Swim.Facets.SwimEvent"
}
]
}
The client call
public async Task AddEvent(string email)
{
using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
{
try
{
var existingContactTask = client.GetAsync<Sitecore.XConnect.Contact>(new IdentifiedContactReference(Sitecore.Foundation.Accounts.Constants.Strings.UserLoginIdentifier, "[email protected]"), new Sitecore.XConnect.ContactExpandOptions());
var existingContact = await existingContactTask;
if (existingContact != null)
{
var channelId = Guid.Parse("7EAA9ED7-188F-40CA-80B9-4439C28386C9"); // Replace with real channel ID
var userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)";
var interaction = new Interaction(existingContact, InteractionInitiator.Contact, channelId, userAgent);
var goalID = Guid.Parse("{CFE46AAF-7ECF-456F-8823-A27DF80BDB82}"); // ID of goal item
var goal = new Goal(goalID, DateTime.UtcNow) {EngagementValue = 20};
interaction.Events.Add(goal);
client.SetFacet<SwimEvent>(interaction, SwimEvent.DefaultFacetKey, new SwimEvent() { PoolId = "123" });
client.AddInteraction(interaction);
await client.SubmitAsync();
}
}
catch (XdbExecutionException ex)
{
// Handle exception
}
}
}
}