Skip to content

Instantly share code, notes, and snippets.

@trnktms
Created April 24, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trnktms/dcf06d978cbc10b8994a8e4d7c66d78e to your computer and use it in GitHub Desktop.
Save trnktms/dcf06d978cbc10b8994a8e4d7c66d78e to your computer and use it in GitHub Desktop.
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