Sha256: 3ded620cfa0578975333fbcd4c4cd2ef0d7b64b5849fcd79ec200b2418907f8b
Contents?: true
Size: 1.71 KB
Versions: 78
Compression:
Stored size: 1.71 KB
Contents
window.GOVUK = window.GOVUK || {} window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {} window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {}; (function (analyticsModules) { 'use strict' var Ga4CopyTracker = { init: function () { window.addEventListener('copy', this.trackCopy.bind(this)) }, trackCopy: function (event) { try { var text = this.getSelectedText() if (!text) { return // do nothing if no text has been selected } var target = event.target.tagName if (target === 'INPUT' || target === 'TEXTAREA') { return // do nothing if text is being copied from an input } var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover() text = window.GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(text) text = PIIRemover.stripPIIWithOverride(text, true, true) var length = text.length text = text.substring(0, 30) var data = { event_name: 'copy', type: 'copy', action: 'copy', method: 'browser copy', text: text, length: length } window.GOVUK.analyticsGa4.core.applySchemaAndSendData(data, 'event_data') } catch (e) { console.warn('GA4 copy tracker error: ' + e.message, window.location) } }, getSelectedText: function () { if (window.getSelection) { return window.getSelection().toString() } else if (document.selection) { return document.selection.createRange().text } return false } } analyticsModules.Ga4CopyTracker = Ga4CopyTracker })(window.GOVUK.analyticsGa4.analyticsModules)
Version data entries
78 entries across 78 versions & 1 rubygems