mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
Moved code into src folder. Added build for component library.
This commit is contained in:
parent
7a7233ead4
commit
ede658771e
490 changed files with 749 additions and 442 deletions
27
src/queries/analytics/getRealtimeData.ts
Normal file
27
src/queries/analytics/getRealtimeData.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { md5 } from 'next-basics';
|
||||
import { getSessions, getEvents } from 'queries/index';
|
||||
import { EVENT_TYPE } from 'lib/constants';
|
||||
|
||||
export async function getRealtimeData(websiteId, time) {
|
||||
const [pageviews, sessions, events] = await Promise.all([
|
||||
getEvents(websiteId, time, EVENT_TYPE.pageView),
|
||||
getSessions(websiteId, time),
|
||||
getEvents(websiteId, time, EVENT_TYPE.customEvent),
|
||||
]);
|
||||
|
||||
const decorate = (id, data) => {
|
||||
return data.map(props => ({
|
||||
...props,
|
||||
__id: md5(id, ...Object.values(props)),
|
||||
__type: id,
|
||||
timestamp: props.timestamp ? props.timestamp * 1000 : new Date(props.createdAt).getTime(),
|
||||
}));
|
||||
};
|
||||
|
||||
return {
|
||||
pageviews: decorate('pageview', pageviews),
|
||||
sessions: decorate('session', sessions),
|
||||
events: decorate('event', events),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue