Shoora
4/6/2019 - 11:50 PM

GA-select-and-copy.js

GA-select-and-copy.js

// Declare function to get selected text from document
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}

// Declare function on copy event
var div = document.getElementById('main_content');
div.addEventListener('copy', function(e){
var textselect = getSelectionText();
var textselectlength = getSelectionText().length;
ga('send', 'event', 'SelectCopy', textselect,textselectlength);
});