()
| 234 | } |
| 235 | |
| 236 | function initPageAndExitEvent() { |
| 237 | sendPage() // Initial page hit |
| 238 | |
| 239 | // Regular page exits |
| 240 | window.addEventListener('scroll', trackScroll) |
| 241 | document.addEventListener('visibilitychange', () => { |
| 242 | if (document.visibilityState === 'hidden') { |
| 243 | sendExit() |
| 244 | } |
| 245 | }) |
| 246 | |
| 247 | // Client-side routing |
| 248 | const pushState = history.pushState |
| 249 | history.pushState = function (state, title, url) { |
| 250 | // Don't trigger page events on query string or hash changes |
| 251 | const newPath = url?.toString().replace(location.origin, '').split('?')[0] |
| 252 | const shouldSendEvents = newPath !== location.pathname |
| 253 | if (shouldSendEvents) { |
| 254 | sendExit() |
| 255 | } |
| 256 | const result = pushState.call(history, state, title, url) |
| 257 | if (shouldSendEvents) { |
| 258 | sendPage() |
| 259 | resetPageParams() |
| 260 | } |
| 261 | return result |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | function initClipboardEvent() { |
| 266 | ;['copy', 'cut', 'paste'].forEach((verb) => { |
no test coverage detected