Я создаю контакт в XDB при отправке формы «ContactUS», а затем программно запускаю цель, как показано ниже, код, я вижу контакт в профиле опыта, но не вижу цели, вызванной новым добавленным контактом.
ContactIdentifierType.Known имеет значение true.
public class XDBHelper
{
public void CreateContactinXDB(ContactusForm contactus)
{
using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
{
string channel = (DateTime.Now).ToString("yyyyMMddHHmmss");
Contact contact = new Sitecore.XConnect.Contact(new ContactIdentifier(channel, contactus.email, ContactIdentifierType.Known));
client.AddContact(contact);
PersonalInformation personalInfoFacet = new PersonalInformation()
{
FirstName = contactus.customername
};
EmailAddressList emails = new EmailAddressList(new EmailAddress(contactus.email, true), "Email");
client.SetFacet(contact, EmailAddressList.DefaultFacetKey, emails);
client.Submit();
Sitecore.Analytics.Tracker.Current.Session.IdentifyAs(channel, contactus.email);
Sitecore.Analytics.Tracker.Current.Interaction.Value = 10;
TriggerGoal("contact-us");
}
}
public void TriggerGoal(string goalType)
{
if (!Sitecore.Analytics.Tracker.IsActive)
{
Sitecore.Analytics.Tracker.StartTracking();
}
string goalId = "Goal ID here";
if (!string.IsNullOrEmpty(goalId))
{
Sitecore.Data.Items.Item goalItem = Sitecore.Context.Database.GetItem(new Sitecore.Data.ID(goalId));
if (goalItem != null)
{
//Check if tracker is active or not
if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Tracker.Current.CurrentPage != null)
{
var goalTrigger = Sitecore.Analytics.Tracker.MarketingDefinitions.Goals[goalItem.ID.ToGuid()];
var goalEventData = Sitecore.Analytics.Tracker.Current.CurrentPage.RegisterGoal(goalTrigger);
goalEventData.Data = goalItem["Name"];
goalEventData.ItemId = goalItem.ID.ToGuid();
goalEventData.DataKey = goalItem.Paths.Path;
goalEventData.Text = goalType;
Sitecore.Analytics.Tracker.Current.Interaction.AcceptModifications();
}
}
}
}
}