From 0aa6cc939a774db43eb16fad9b8e9ac05d4d6d01 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Thu, 3 Sep 2020 08:53:39 -0700 Subject: [PATCH] Allow custom events. --- tracker/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tracker/index.js b/tracker/index.js index 52e09514..9a5051b8 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -61,12 +61,13 @@ import { removeTrailingSlash } from '../lib/url'; const handlePush = (state, title, navigatedURL) => { removeEvents(); currentRef = currentUrl; + const newUrl = navigatedURL.toString(); - if (navigatedURL.toString().startsWith('http')) { - const url = new URL(navigatedURL.toString()); + if (newUrl.startsWith('http')) { + const url = new URL(newUrl); currentUrl = `${url.pathname}${url.search}`; } else { - currentUrl = navigatedURL.toString(); + currentUrl = newUrl; } pageView(); @@ -101,4 +102,8 @@ import { removeTrailingSlash } from '../lib/url'; /* Start */ pageView(); + + if (!window.umami) { + window.umami = event_value => collect('event', { event_type: 'custom', event_value }); + } })(window);