Created
April 24, 2017 13:05
-
-
Save trnktms/dcf06d978cbc10b8994a8e4d7c66d78e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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