Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
islaytitans
/
VisitorTagsExample.cs
Secret
Last active
Aug 29, 2015
Star
0
Fork
0
Star
Code
Revisions
9
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Creating updating tags on button click event
Raw
VisitorTagsExample.cs
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
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.