Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- // 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
- document.addEventListener('copy', function(e){
- dataLayer.push({
- 'event': 'textCopied',
- 'clipboardText': getSelectionText(),
- 'clipboardLength': getSelectionText().length
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement