mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 15:23:38 +01:00
Merge pull request #179 from mikecao/dev
Tracker updates and global date range fix
This commit is contained in:
commit
ce567131e0
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user