Project import generated by Copybara.
GitOrigin-RevId: d9e9e3fb4e31372ec1fb43b178994ca78fa8fe70
diff --git a/static_src/monitoring/track-copy.js b/static_src/monitoring/track-copy.js
new file mode 100644
index 0000000..7123965
--- /dev/null
+++ b/static_src/monitoring/track-copy.js
@@ -0,0 +1,28 @@
+/* Copyright 2018 The Chromium Authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file.
+ */
+
+// This counts copy and paste events.
+
+function labelForElement(el) {
+ let label = el.localName;
+ if (el.id) {
+ label = label + '#' + el.id;
+ }
+ return label;
+}
+
+window.addEventListener('copy', function(evt) {
+ const label = labelForElement(evt.srcElement);
+ const len = window.getSelection().toString().length;
+ ga('send', 'event', window.location.pathname, 'copy', label, len);
+});
+
+window.addEventListener('paste', function(evt) {
+ const label = labelForElement(evt.srcElement);
+ const text = evt.clipboardData.getData('text/plain');
+ const len = text ? text.length : 0;
+ ga('send', 'event', window.location.pathname, 'paste', label, len);
+});