People are copying my content, and I think it's great. I have even done some extra work to make it easier to copy codes/scripts I have published on this blog based on feedback from some visitors. The Remove formatting from Code that you find below is the result of that.
But I have also blog posts that don't include any scripts. My question was therefore, did visitors find something interesting in those blog posts, and if yes, so interesting that they would copy some of the content?
Since I didn't find any solution that suited my needs, I did put together my own cut/copy/paste tracking script using jQuery and a script from Motyar that detects selected/highlighted text.
For demonstration purposes, below I will show you the data that are sent to Google Analytics if you copy any text on this page.
Google Analytics Report for Copied Text
The report in Google Analytics will show you:
- Category: Clipboard
- Action: Copy, cut or paste.
- Label: The text copied/cutted/pasted.
- Value: How many characters were copied/cutted/pasted.
If you select Pages from the Event report, or Pages as a secondary dimension, you can drill down to the page the text was copied/cutted/pasted from/on. Or even better, create a Custom Report.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Script for Tracking Text Copied using jQuery
Below is the script for tracking text copied/cutted or pasted using jQuery. If you want to track more (or less) text, change the code in red.
I would also add a "warning" regarding this script. Don't use it on pages that can contain PII (Personally Identifiable Information), just in case some people copy their own PII info from the page. This type of data is not allowed in Google Analytics.
- <script type="text/javascript">
- // This script for tracking cut/copy/paste in Google Analytics is provided as it is, and was put together by Eivind Savio January 2013. Happy tracking!
- // Script from Motyar
- function getSelected() {
- if(window.getSelection) {return window.getSelection();}
- else if(document.getSelection) {return document.getSelection();}
- else {
- var selection = document.selection && document.selection.createRange();
- if(selection.text) { return selection.text; }
- return false;
- }
- return false;
- }
- // End script from Motyar
- $(document).ready(function() {
- $('body').on('copy cut paste', function(ccp) { // Track cut, copy or paste with jQuery.
- var selection = getSelected();
- var maxLength = 150; // Up to 150 Characters from your text will be tracked. Change this number if you want to track more or less text.
- if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
- var textLength = selection.length; // How many characters was copied/cutted/pasted.
- if (selection.length > maxLength) {
- selection = selection.substr(0, maxLength) + "..."} // If the text is longer than maxLength, add ... to the end of the text
- else {
- selection = selection; // If the text is shorter than maxLength, just track the text as it is.
- }
- _gaq.push(['_trackEvent', 'Clipboard', ccp.type, selection,textLength]);
// Track copied/cutted/pasted data in Google Analytics as Events - }
- });
- });
- </script>
Some final words
Except from "curiosity" for what visitors are copying, do you see any other valuable areas for this kind of tracking? Protecting your work? SEO? Other content you should write about? Intention of sharing (headline copied)?
If you think the code could be improved, feel free to comment (I'm not a programmer).
jQuery 1.7 or later is needed for this script to work.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.