Quantcast
Viewing all articles
Browse latest Browse all 31

How to Track if Visitors are Copying Text from Your Website in Google Analytics with jQuery

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.
Google Analytics Clipboard Report - Which pages were text copied from?

Image may be NSFW.
Clik here to view.
Google Analytics Clipboard Report - Which text were copied?

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.

Remove formatting from Code

  1. <script type="text/javascript">
  2. // 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!
  3. // Script from Motyar
  4. function getSelected() {
  5. if(window.getSelection) {return window.getSelection();}
  6. else if(document.getSelection) {return document.getSelection();}
  7. else {
  8. var selection = document.selection && document.selection.createRange();
  9. if(selection.text) { return selection.text; }
  10. return false;
  11. }
  12. return false;
  13. }
  14. // End script from Motyar
  15. $(document).ready(function() {
  16. $('body').on('copy cut paste', function(ccp) { // Track cut, copy or paste with jQuery.
  17. var selection = getSelected();
  18. 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.
  19. if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
  20. var textLength = selection.length; // How many characters was copied/cutted/pasted.
  21. if (selection.length > maxLength) {
  22. selection = selection.substr(0, maxLength) + "..."} // If the text is longer than maxLength, add ... to the end of the text
  23. else {
  24. selection = selection; // If the text is shorter than maxLength, just track the text as it is.
  25. }
  26. _gaq.push(['_trackEvent', 'Clipboard', ccp.type, selection,textLength]);
    // Track copied/cutted/pasted data in Google Analytics as Events
  27. }
  28. });
  29. });
  30. </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.

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 31

Trending Articles