blob: 7123965d5b96a9f9d020373c098aeb9676c0cb4e [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001/* Copyright 2018 The Chromium Authors. All Rights Reserved.
2 *
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
5 */
6
7// This counts copy and paste events.
8
9function labelForElement(el) {
10 let label = el.localName;
11 if (el.id) {
12 label = label + '#' + el.id;
13 }
14 return label;
15}
16
17window.addEventListener('copy', function(evt) {
18 const label = labelForElement(evt.srcElement);
19 const len = window.getSelection().toString().length;
20 ga('send', 'event', window.location.pathname, 'copy', label, len);
21});
22
23window.addEventListener('paste', function(evt) {
24 const label = labelForElement(evt.srcElement);
25 const text = evt.clipboardData.getData('text/plain');
26 const len = text ? text.length : 0;
27 ga('send', 'event', window.location.pathname, 'paste', label, len);
28});