Track Your Visitors Copied Text With SiteCatalyst Plug-in
To me Web Analytics is the science of analyzing visitor behavior in order to improve the Web Site for the purpose of increasing conversion. Anytime I can use web analytics to help the visitor find what they are looking for, I feel I’m doing my job. But lets say your visitors are finding what they are looking for, but it is just not as easy as it could be? How would I know?
One thing I have been playing with is to monitor what content my visitors are selecting and copying from the site. If I see a lot of visitors copying my email address, maybe I should make the contact form a little easier to be found. If I see a lot of copying of some sample code, maybe I should make it easier to download it, or include a pdf copy. But how do I find out how to capture what my visitors copy? Here you go.
This is all done by adding a plug-in and a bit of code to the s_code file. This code looks for any time some text is copied and sets it in a prop and fires an event. This will work if the visitor highlights text and goes the right click/copy route, or by hitting Control/Command + C. You will need either 1 eVar and 1 event, or a 1 prop to use. If you want to go the eVar and event route, take this code and place it some where BEFORE the function s_doPlugins(s) call:
var eventAttached=false;
if(!eventAttached){eventAttached = true;
function trackCopy(){
var overrides = {'events':'event8','eVar18':getCopiedText()};
s.templtv=s.linkTrackVars;
s.templte=s.linkTrackEvents;
s.linkTrackVars='eVar18,events';
s.linkTrackEvents=s.events='event8';
s.tl(true, 'o', 'Text Copied', overrides);
if(s.templtv) s.linkTrackVars=s.templtv;
if(s.templte) s.linkTrackEvents=s.templte;
}
Insert the eVar and event you are going to use where you see them in the code. If you decide to just use a single prop instead, then use this bit of code, again before the function s_doPlugins(s) call:
var eventAttached=false;
if(!eventAttached){eventAttached = true;
function trackCopy(){
var overrides = {'prop49':getCopiedText()};
s.templtv=s.linkTrackVars;
s.linkTrackVars='prop49';
s.tl(true, 'o', 'Text Copied', overrides);
if(s.templtv) s.linkTrackVars=s.templtv;
}
Insert the prop you want to use where you see it set. Next take this code and put it in the plug-in’s section of the s_code file:
function getCopiedText() {
if (document.selection){return document.selection.createRange().text;}
else if (window.getSelection){return window.getSelection();}return '';}
if(document.body && document.body.attachEvent){
document.body.attachEvent("oncopy", trackCopy);}
else if (document.body && document.body.addEventListener){
document.body.addEventListener('copy',trackCopy, false);}}
What are we going to end up with? You will get a report that looks like this:

It’s pretty interesting to see what your visitors are choosing to copy. Now do I expect to find huge some game changing incite that will lead me to make a change to the Web Site that will increase my conversion rate 100% with this report? Probably not. Do I expect to find one more place that allows me to make another 1% improvement? I sure do. Remember, all those 1% improvements add up.
Big thanks to kgs/ksmith in the Omniture Developer Connection for the original idea to do this.
Enjoy!
Popularity: 6% [?]
This is awesome. But wanted to make sure the code is correct before I copy and paste it on my site.
Do you have an answer to the previous comment?
You can check my s_code file to see it live in action, and it is working fine here on the site. You can see my s_code.js file here.

Hi Kevin,
Good posting, but I think the code is mixed up. Could it be that the lines
if(document.body && document.body.attachEvent){
document.body.attachEvent(“oncopy”, trackCopy);}
else if (document.body && document.body.addEventListener){
document.body.addEventListener(‘copy’,trackCopy, false);}}
should be part of the first part of the code?
Cheers,
Jan