Skip to content

Instantly share code, notes, and snippets.

@trnktms

trnktms/XdbHelper.cs

Created Apr 24, 2017
Embed
What would you like to do?
using Sitecore.Analytics;
using Sitecore.Analytics.Tracking;
using System.Collections.Generic;
namespace MyProject.Foundation.Xdb.Utils
{
public static class XdbHelper
{
public static void TriggerProfileKey(string profileName, string profileKey, int value)
{
if (!Tracker.Enabled)
{
return;
}
if (!Tracker.IsActive)
{
Tracker.StartTracking();
}
Profile profile;
if (Tracker.Current.Interaction.Profiles.ContainsProfile(profileName))
{
profile = Tracker.Current.Interaction.Profiles[profileName];
}
else
{
var profiles = new List<Sitecore.Analytics.Model.ProfileData>
{
new Sitecore.Analytics.Model.ProfileData(profileName)
};
Tracker.Current.Interaction.Profiles.Initialize(profiles);
profile = Tracker.Current.Interaction.Profiles[profileName];
}
var scores = new Dictionary<string, float> { { profileKey, value } };
profile.Score(scores);
profile.UpdatePattern();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment