mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Updated send logic.
This commit is contained in:
parent
b72232dcac
commit
c0a67dadd5
7 changed files with 101 additions and 67 deletions
|
|
@ -132,7 +132,7 @@ export async function getLocation(ip: string, req: NextApiRequestCollect) {
|
|||
}
|
||||
|
||||
export async function getClientInfo(req: NextApiRequestCollect) {
|
||||
const userAgent = req.headers['user-agent'];
|
||||
const userAgent = req.body?.payload?.userAgent || req.headers['user-agent'];
|
||||
const ip = req.body?.payload?.ip || getIpAddress(req);
|
||||
const location = await getLocation(ip, req);
|
||||
const country = location?.country;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,24 @@ export async function getSession(req: NextApiRequestCollect): Promise<SessionDat
|
|||
const sessionId = uuid(websiteId, hostname, ip, userAgent);
|
||||
const visitId = uuid(sessionId, visitSalt());
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('SESSION', {
|
||||
websiteId,
|
||||
sessionId,
|
||||
hostname,
|
||||
ip,
|
||||
userAgent,
|
||||
visitId,
|
||||
salt: visitSalt(),
|
||||
browser,
|
||||
os,
|
||||
country,
|
||||
subdivision1,
|
||||
subdivision2,
|
||||
city,
|
||||
device,
|
||||
});
|
||||
|
||||
// Clickhouse does not require session lookup
|
||||
if (clickhouse.enabled) {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ export interface CollectRequestBody {
|
|||
website: string;
|
||||
data?: { [key: string]: any };
|
||||
hostname?: string;
|
||||
ip?: string;
|
||||
language?: string;
|
||||
name?: string;
|
||||
referrer?: string;
|
||||
|
|
@ -29,6 +28,8 @@ export interface CollectRequestBody {
|
|||
tag?: string;
|
||||
title?: string;
|
||||
url: string;
|
||||
ip?: string;
|
||||
userAgent?: string;
|
||||
};
|
||||
type: CollectionType;
|
||||
}
|
||||
|
|
@ -62,7 +63,6 @@ const schema = {
|
|||
.shape({
|
||||
data: yup.object(),
|
||||
hostname: yup.string().matches(HOSTNAME_REGEX).max(100),
|
||||
ip: yup.string().matches(IP_REGEX),
|
||||
language: yup.string().max(35),
|
||||
referrer: yup.string(),
|
||||
screen: yup.string().max(11),
|
||||
|
|
@ -71,6 +71,8 @@ const schema = {
|
|||
website: yup.string().uuid().required(),
|
||||
name: yup.string().max(50),
|
||||
tag: yup.string().max(50).nullable(),
|
||||
ip: yup.string().matches(IP_REGEX),
|
||||
userAgent: yup.string(),
|
||||
})
|
||||
.required(),
|
||||
type: yup
|
||||
|
|
@ -95,8 +97,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
|||
}
|
||||
|
||||
const { type, payload } = req.body;
|
||||
const { url, referrer, name: eventName, data, title, tag } = payload;
|
||||
const pageTitle = safeDecodeURI(title);
|
||||
const { url, referrer, name, data, title, tag } = payload;
|
||||
|
||||
await useSession(req, res);
|
||||
|
||||
|
|
@ -142,8 +143,8 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
|
|||
referrerPath,
|
||||
referrerQuery,
|
||||
referrerDomain,
|
||||
pageTitle,
|
||||
eventName,
|
||||
pageTitle: title,
|
||||
eventName: name,
|
||||
eventData: data,
|
||||
...session,
|
||||
sessionId: session.id,
|
||||
|
|
|
|||
|
|
@ -219,8 +219,10 @@
|
|||
|
||||
const data = await res.json();
|
||||
|
||||
disabled = res.status === 429;
|
||||
cache = data?.cache;
|
||||
if (data) {
|
||||
disabled = !!data.disabled;
|
||||
cache = data.cache;
|
||||
}
|
||||
} catch (e) {
|
||||
/* empty */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue