Skip to content

Instantly share code, notes, and snippets.

@islaytitans

islaytitans/VisitorTagsExample.cs Secret

Last active Aug 29, 2015
Embed
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)
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