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