In my website I have "contact us form" and 1 goal is trigger after custom-save-action executes.
When a contact fill the form I am saving its details into XDB by using email-id as identity, if record already exists by that email then I am updating his record (facets).I can see newly added or updated contact in Experience Profile . Ref:- https://doc.sitecore.com/developers/93/sitecore-experience-platform/en/add-contacts.html
Now suppose , I came first time to site and visit the site and fill the form by name as "a" and email as "[email protected]" then in experience profile user should be display with triggered goal but User is created In XP but it not displaying goals, now suppose we refill the form with old session and name as "b" and email "[email protected]" then "[email protected]" session should be end and "[email protected]" session should start and after submitting the form triggered goal must be assign to "b".
The problem is : Goal is not attaching with newly added or updated contact .. It attached at the time we refill the contact-form with old session.
means if "b" fill the form then its goal assigning to "a".
Code :-
using (XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
//XDBGenerateJsonSchema.JSONSchema(); //Uncomment this line if new schema needs to generate
string phoneAsChannel = contactus.telephone;
Contact getContact = client.Get<Contact>(new IdentifiedContactReference(phoneAsChannel, contactus.email), new ContactExpandOptions(CustomFacetInformation.DefaultFacetKey));
if (getContact != null)
{
//update contact
var facet = getContact.GetFacet<CustomFacetInformation>(CustomFacetInformation.DefaultFacetKey);
if (facet != null)
{
facet.Company = contactus.companyname;
facet.Market = contactus.market;
facet.Interest = contactus.intrestedinText;
facet.LeadSource = contactus.LeadSource;
facet.SignUpForNewsLetter = contactus.SignUpForNewsLetter;
facet.SourceURL = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
facet.Field1 = string.Empty;
facet.Field2 = string.Empty;
facet.Field3 = string.Empty;
client.SetFacet(getContact, CustomFacetInformation.DefaultFacetKey, facet);
}
else
{
CustomFacetInformation customFacetInformation = new CustomFacetInformation()
{
Company = contactus.companyname,
Market = contactus.market,
Interest = contactus.intrestedinText,
LeadSource = contactus.LeadSource,
SignUpForNewsLetter = contactus.SignUpForNewsLetter,
SourceURL = System.Web.HttpContext.Current.Request.Url.AbsolutePath,
Field1 = string.Empty,
Field2 = string.Empty,
Field3 = string.Empty
};
client.SetFacet(getContact, CustomFacetInformation.DefaultFacetKey, customFacetInformation);
}
}
else
{
Contact contact = new Sitecore.XConnect.Contact(new ContactIdentifier(phoneAsChannel, contactus.email, ContactIdentifierType.Known));
client.AddContact(contact);
PersonalInformation personalInfoFacet = new PersonalInformation()
{
FirstName = contactus.customername
};
FacetReference reference = new FacetReference(contact, PersonalInformation.DefaultFacetKey);
client.SetFacet(reference, personalInfoFacet);
EmailAddressList emails = new EmailAddressList(new EmailAddress(contactus.email, true), "Email");
client.SetFacet(contact, emails);
PhoneNumberList phones = new PhoneNumberList(new PhoneNumber("", contactus.telephone), "Phone");
client.SetFacet(contact, phones);
//Custom Facet
CustomFacetInformation customFacetInformation = new CustomFacetInformation()
{
Company = contactus.companyname,
Market = contactus.market,
Interest = contactus.intrestedinText,
LeadSource = contactus.LeadSource,
SignUpForNewsLetter = contactus.SignUpForNewsLetter,
SourceURL = System.Web.HttpContext.Current.Request.Url.AbsolutePath,
Field1 = string.Empty,
Field2 = string.Empty,
Field3 = string.Empty
};
client.SetFacet(contact, CustomFacetInformation.DefaultFacetKey, customFacetInformation);
}
client.Submit();
}