Skip to content

Instantly share code, notes, and snippets.


islaytitans/VisitorTagsExample.cs Secret

Last active Aug 29, 2015
What would you like to do?
Creating updating tags on button click event
private void CheckinButton_OnClick(object sender, EventArgs e)
var button = sender as Button;
if (button == null)
string location = button.CommandArgument;
// Retrieve the visitor from Sitecore Analytics
var visitor = Sitecore.Analytics.Tracker.Visitor;
if (visitor == null)
// 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 + "|");
// 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(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