diff --git a/components/settings/ProfileSettings.js b/components/settings/ProfileSettings.js index 69bc34e9..10386318 100644 --- a/components/settings/ProfileSettings.js +++ b/components/settings/ProfileSettings.js @@ -30,7 +30,8 @@ export default function ProfileSettings() { } function handleDateChange(values) { - setItem(`umami.date-range`, values); + const { value } = values; + setItem(`umami.date-range`, value === 'custom' ? values : value); dispatch(setDateRange(0, values)); } diff --git a/hooks/useDateRange.js b/hooks/useDateRange.js index e6ad6808..9a88a5a1 100644 --- a/hooks/useDateRange.js +++ b/hooks/useDateRange.js @@ -5,14 +5,20 @@ import { getItem } from 'lib/web'; export default function useDateRange(websiteId, defaultDateRange = '24hour') { const globalDefault = getItem('umami.date-range'); + let globalDateRange; - if (globalDefault) { - globalDefault.startDate = parseISO(globalDefault.startDate); - globalDefault.endDate = parseISO(globalDefault.endDate); + if (typeof globalDefault === 'string') { + globalDateRange = getDateRange(globalDefault); + } else { + globalDateRange = { + ...globalDefault, + startDate: parseISO(globalDefault.startDate), + endDate: parseISO(globalDefault.endDate), + }; } return useSelector( state => - state.websites[websiteId]?.dateRange || globalDefault || getDateRange(defaultDateRange), + state.websites[websiteId]?.dateRange || globalDateRange || getDateRange(defaultDateRange), ); } diff --git a/lib/constants.js b/lib/constants.js index 27fa2461..e9641c68 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -23,7 +23,7 @@ export const FILTER_DOMAIN_ONLY = 0; export const FILTER_COMBINED = 1; export const FILTER_RAW = 2; -export const DOMAIN_REGEX = /((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}/; +export const DOMAIN_REGEX = /localhost(:\d{1,5})?|((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}/; export const DESKTOP_SCREEN_WIDTH = 1920; export const LAPTOP_SCREEN_WIDTH = 1024; diff --git a/tracker/index.js b/tracker/index.js index 38aadeb3..12119298 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -64,7 +64,7 @@ import { removeTrailingSlash } from '../lib/url'; }); }; - const pageView = (url = currentUrl, referrer = currentRef, uuid = website) => + const trackView = (url = currentUrl, referrer = currentRef, uuid = website) => collect( 'pageview', { @@ -74,7 +74,7 @@ import { removeTrailingSlash } from '../lib/url'; uuid, ); - const pageEvent = (event_value, event_type = 'custom', url = currentUrl, uuid = website) => + const trackEvent = (event_value, event_type = 'custom', url = currentUrl, uuid = website) => collect( 'event', { @@ -87,12 +87,12 @@ import { removeTrailingSlash } from '../lib/url'; /* Handle events */ - const loadEvents = () => { + const addEvents = () => { document.querySelectorAll("[class*='umami--']").forEach(element => { element.className.split(' ').forEach(className => { if (/^umami--([a-z]+)--([a-z0-9_]+[a-z0-9-_]+)$/.test(className)) { const [, type, value] = className.split('--'); - const listener = () => pageEvent(value, type); + const listener = () => trackEvent(value, type); listeners.push([element, type, listener]); element.addEventListener(type, listener, true); @@ -123,17 +123,17 @@ import { removeTrailingSlash } from '../lib/url'; currentUrl = newUrl; } - pageView(currentUrl, currentRef); + trackView(currentUrl, currentRef); - setTimeout(loadEvents, 300); + setTimeout(addEvents, 300); }; /* Global */ if (!window.umami) { - const umami = event_value => pageEvent(event_value); - umami.pageView = pageView; - umami.pageEvent = pageEvent; + const umami = event_value => trackEvent(event_value); + umami.trackView = trackView; + umami.trackEvent = trackEvent; window.umami = umami; } @@ -144,8 +144,8 @@ import { removeTrailingSlash } from '../lib/url'; history.pushState = hook(history, 'pushState', handlePush); history.replaceState = hook(history, 'replaceState', handlePush); - pageView(currentUrl, currentRef); + trackView(currentUrl, currentRef); - loadEvents(); + addEvents(); } })(window);