Skip to content

Instantly share code, notes, and snippets.

@islaytitans
Last active August 29, 2015 14:23
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 islaytitans/521ba76a21344a1d2cf8 to your computer and use it in GitHub Desktop.
Save islaytitans/521ba76a21344a1d2cf8 to your computer and use it in GitHub Desktop.
Creating updating tags on button click event
private void CheckinButton_OnClick(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null)
return;
string location = button.CommandArgument;
// Retrieve the visitor from Sitecore Analytics
var visitor = Sitecore.Analytics.Tracker.Visitor;
if (visitor == null)
return;
// Get the Tag named LocationsCheckedIn
var visitorTags = visitor.Tags.Find("LocationsCheckedIn");
if (visitorTags == null)
{
// If the tag is not present we add one with the name LocationsCheckedIn
// and pass in the TagValue, in this case the location
visitor.Tags.Add("LocationsCheckedIn", location + "|");
}
else
{
// If the tag does exist we retrieve and append to the value creating a
// pipe separated list of locations the user has checked in
StringBuilder tagValue = new StringBuilder(visitorTags.TagValue);
if (!visitorTags.TagValue.EndsWith("|"))
tagValue.Append("|");
tagValue.Append(location + "|");
}
//Any subsequent code to complete Checkin event
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment