MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / trackScreenViews

Method trackScreenViews

packages/sdks/web/src/index.ts:232–264  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

230 }
231
232 public trackScreenViews() {
233 if (this.isServer()) {
234 return;
235 }
236
237 const oldPushState = history.pushState;
238 history.pushState = function pushState(...args) {
239 const ret = oldPushState.apply(this, args);
240 window.dispatchEvent(new Event('pushstate'));
241 window.dispatchEvent(new Event('locationchange'));
242 return ret;
243 };
244
245 const oldReplaceState = history.replaceState;
246 history.replaceState = function replaceState(...args) {
247 const ret = oldReplaceState.apply(this, args);
248 window.dispatchEvent(new Event('replacestate'));
249 window.dispatchEvent(new Event('locationchange'));
250 return ret;
251 };
252
253 window.addEventListener('popstate', () => {
254 window.dispatchEvent(new Event('locationchange'));
255 });
256
257 const eventHandler = () => this.debounce(() => this.screenView(), 50);
258
259 if (this.options.trackHashChanges) {
260 window.addEventListener('hashchange', eventHandler);
261 } else {
262 window.addEventListener('locationchange', eventHandler);
263 }
264 }
265
266 public trackAttributes() {
267 if (this.isServer()) {

Callers 1

constructorMethod · 0.95

Calls 2

isServerMethod · 0.95
addEventListenerMethod · 0.80

Tested by

no test coverage detected