Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. // Declare function to get selected text from document
  3. function getSelectionText() {
  4. var text = "";
  5. if (window.getSelection) {
  6. text = window.getSelection().toString();
  7. } else if (document.selection && document.selection.type != "Control") {
  8. text = document.selection.createRange().text;
  9. }
  10. return text;
  11. }
  12.  
  13. // Declare function on copy event
  14. document.addEventListener('copy', function(e){
  15. dataLayer.push({
  16. 'event': 'textCopied',
  17. 'clipboardText': getSelectionText(),
  18. 'clipboardLength': getSelectionText().length
  19. });
  20. });
  21. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement