Last active
August 29, 2015 14:07
-
-
Save chrisblakley/5084dc14524cddbba130 to your computer and use it in GitHub Desktop.
Detect copied text using Google Analytics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).on('cut copy', function(){ | |
var currentPage = jQuery(document).attr('title'); | |
var words = []; | |
var selection = window.getSelection() + ''; | |
words = selection.split(' '); | |
wordsLength = words.length; | |
if (words.length > 8) { | |
words = words.slice(0, 8).join(' '); | |
ga('send', 'event', 'Copied Text', currentPage, words + '... [' + wordsLength + ' words]'); | |
} else { | |
if ( selection == '' || selection == ' ' ) { | |
ga('send', 'event', 'Copied Text', currentPage, '[0 words]'); | |
} else { | |
ga('send', 'event', 'Copied Text', currentPage, selection); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment