Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Updated send logic.
Mike Caoc0a67dadd5fc
diff --git a/next-env.d.ts b/next-env.d.tsindex 725dd6f24..3cd7048ed 100644--- a/next-env.d.ts+++ b/next-env.d.ts@@ -3,4 +3,4 @@/// <reference types="next/navigation-types/compat/navigation" />// NOTE: This file should not be edited-// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.+// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/package.json b/package.jsonindex 932eb300b..d61146cd9 100644--- a/package.json+++ b/package.json@@ -102,7 +102,7 @@"kafkajs": "^2.1.0","maxmind": "^4.3.6","md5": "^2.3.0",- "next": "15.0.4",+ "next": "15.1.4","next-basics": "^0.39.0","node-fetch": "^3.2.8","npm-run-all": "^4.1.5",@@ -118,6 +118,7 @@"react-window": "^1.8.6","request-ip": "^3.3.0","semver": "^7.5.4",+ "serialize-error": "^12.0.0","thenby": "^1.3.4","uuid": "^9.0.0","yup": "^0.32.11",diff --git a/src/lib/detect.ts b/src/lib/detect.tsindex c3ce6feed..0bea44033 100644--- a/src/lib/detect.ts+++ b/src/lib/detect.ts@@ -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;diff --git a/src/lib/session.ts b/src/lib/session.tsindex 5311e3fda..d43712d23 100644--- a/src/lib/session.ts+++ b/src/lib/session.ts@@ -42,6 +42,24 @@ export async function getSession(req: NextApiRequestCollect): Promise<SessionDatconst 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 lookupif (clickhouse.enabled) {return {diff --git a/src/pages/api/send.ts b/src/pages/api/send.tsindex cbcacae51..8e73463c3 100644--- a/src/pages/api/send.ts+++ b/src/pages/api/send.ts@@ -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,diff --git a/src/tracker/index.js b/src/tracker/index.jsindex 14a5cb684..73e8e5afe 100644--- a/src/tracker/index.js+++ b/src/tracker/index.js@@ -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 */}diff --git a/yarn.lock b/yarn.lockindex dd9b5d291..c1d0793a4 100644--- a/yarn.lock+++ b/yarn.lock@@ -2323,10 +2323,10 @@resolved "https://registry.yarnpkg.com/@netlify/plugin-nextjs/-/plugin-nextjs-5.8.1.tgz#9da15bb4a13c5644e9b58b968c7da51939206ee4"integrity sha512-WB1N0FslhWZ1yAVYTcB6CcFrFOUSQ0O2LfavYZrbAypeNxu2I+oO+cgmhfDgZ8Eoq1g4EMeoIGMkNoZ4ogZTsg==-"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/env/-/env-15.0.4.tgz#97da0fe3bae2f2b2968c4c925d7936660f5b3836"- integrity sha512-WNRvtgnRVDD4oM8gbUcRc27IAhaL4eXQ/2ovGbgLnPGUvdyDr8UdXP4Q/IBDdAdojnD2eScryIDirv0YUCjUVw==+"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/env/-/env-15.1.4.tgz#f727cc4f46527a5223ae894f9476466db9132e21"+ integrity sha512-2fZ5YZjedi5AGaeoaC0B20zGntEHRhi2SdWcu61i48BllODcAmmtj8n7YarSPt4DaTsJaBFdxQAVEVzgmx2Zpw=="@next/[email protected]":version "14.2.18"@@ -2335,45 +2335,45 @@dependencies:glob "10.3.10"-"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.0.4.tgz#66087f397564d6ece4c5493536d30bc2b158a80e"- integrity sha512-QecQXPD0yRHxSXWL5Ff80nD+A56sUXZG9koUsjWJwA2Z0ZgVQfuy7gd0/otjxoOovPVHR2eVEvPMHbtZP+pf9w==--"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-15.0.4.tgz#6eb098e183dfed72d8f3c4b281a323ad17d72446"- integrity sha512-pb7Bye3y1Og3PlCtnz2oO4z+/b3pH2/HSYkLbL0hbVuTGil7fPen8/3pyyLjdiTLcFJ+ymeU3bck5hd4IPFFCA==--"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.0.4.tgz#3c082ad1a4c8060a5c56127fdefb82a149d3b94e"- integrity sha512-12oSaBFjGpB227VHzoXF3gJoK2SlVGmFJMaBJSu5rbpaoT5OjP5OuCLuR9/jnyBF1BAWMs/boa6mLMoJPRriMA==--"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.0.4.tgz#c4e18c89ea4dab6b150b889643ec19896aebc1eb"- integrity sha512-QARO88fR/a+wg+OFC3dGytJVVviiYFEyjc/Zzkjn/HevUuJ7qGUUAUYy5PGVWY1YgTzeRYz78akQrVQ8r+sMjw==--"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.0.4.tgz#f81c3952a60f3075b48e0b5a862f4deecd550c2d"- integrity sha512-Z50b0gvYiUU1vLzfAMiChV8Y+6u/T2mdfpXPHraqpypP7yIT2UV9YBBhcwYkxujmCvGEcRTVWOj3EP7XW/wUnw==--"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.0.4.tgz#f14c9730599985538d4d01d6da825b4e41fea0c1"- integrity sha512-7H9C4FAsrTAbA/ENzvFWsVytqRYhaJYKa2B3fyQcv96TkOGVMcvyS6s+sj4jZlacxxTcn7ygaMXUPkEk7b78zw==--"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.0.4.tgz#14297572feedcd5b14388be8a7ea8c50accb4c96"- integrity sha512-Z/v3WV5xRaeWlgJzN9r4PydWD8sXV35ywc28W63i37G2jnUgScA4OOgS8hQdiXLxE3gqfSuHTicUhr7931OXPQ==--"@next/[email protected]":- version "15.0.4"- resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.0.4.tgz#d25953baffb92721f0fb96c8be71d7efb37a57b7"- integrity sha512-NGLchGruagh8lQpDr98bHLyWJXOBSmkEAfK980OiNBa7vNm6PsNoPvzTfstT78WyOeMRQphEQ455rggd7Eo+Dw==+"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.1.4.tgz#49faf320d44d1a813e09501abfd952b0315385c9"+ integrity sha512-wBEMBs+np+R5ozN1F8Y8d/Dycns2COhRnkxRc+rvnbXke5uZBHkUGFgWxfTXn5rx7OLijuUhyfB+gC/ap58dDw==++"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-15.1.4.tgz#3c234986481e7db8957562b8dfeab2d44fe4c0a7"+ integrity sha512-7sgf5rM7Z81V9w48F02Zz6DgEJulavC0jadab4ZsJ+K2sxMNK0/BtF8J8J3CxnsJN3DGcIdC260wEKssKTukUw==++"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.1.4.tgz#d71c5a55106327b50ff194dd40e11c3ca7f744a7"+ integrity sha512-JaZlIMNaJenfd55kjaLWMfok+vWBlcRxqnRoZrhFQrhM1uAehP3R0+Aoe+bZOogqlZvAz53nY/k3ZyuKDtT2zQ==++"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.1.4.tgz#c6b4cef0f5b943d6308fdb429ecb43be79afce31"+ integrity sha512-7EBBjNoyTO2ipMDgCiORpwwOf5tIueFntKjcN3NK+GAQD7OzFJe84p7a2eQUeWdpzZvhVXuAtIen8QcH71ZCOQ==++"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.1.4.tgz#2b15f959ac6653800c0df8247489d54982926786"+ integrity sha512-9TGEgOycqZFuADyFqwmK/9g6S0FYZ3tphR4ebcmCwhL8Y12FW8pIBKJvSwV+UBjMkokstGNH+9F8F031JZKpHw==++"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.1.4.tgz#2b9d3ca3c3f506e3515b13c00e19d3031535bb44"+ integrity sha512-0578bLRVDJOh+LdIoKvgNDz77+Bd85c5JrFgnlbI1SM3WmEQvsjxTA8ATu9Z9FCiIS/AliVAW2DV/BDwpXbtiQ==++"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.1.4.tgz#74928a6e824b258a071d30872c00417ee79d4ee7"+ integrity sha512-JgFCiV4libQavwII+kncMCl30st0JVxpPOtzWcAI2jtum4HjYaclobKhj+JsRu5tFqMtA5CJIa0MvYyuu9xjjQ==++"@next/[email protected]":+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.1.4.tgz#188bce4c231f5ab0e7eaca55170764f7e8229db2"+ integrity sha512-xxsJy9wzq7FR5SqPCUqdgSXiNXrMuidgckBa8nH9HtjjxsilgcN6VgXF6tZ3uEWuVEadotQJI8/9EQ6guTC4Yw=="@nodelib/[email protected]":version "2.1.5"@@ -2756,12 +2756,12 @@resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.3.tgz#cc7463bd02949611c6329596fccd2b0ec782b0e9"integrity sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==-"@swc/[email protected]":- version "0.5.13"- resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.13.tgz#33e63ff3cd0cade557672bd7888a39ce7d115a8c"- integrity sha512-UoKGxQ3r5kYI9dALKJapMmuK+1zWM/H17Z1+iwnNmzcJRnfFuevZs375TA5rW31pu4BS4NoSy1fRsexDXfWn5w==+"@swc/[email protected]":+ version "0.5.15"+ resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.15.tgz#79efab344c5819ecf83a43f3f9f811fc84b516d7"+ integrity sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==dependencies:- tslib "^2.4.0"+ tslib "^2.8.0""@tanstack/[email protected]":version "5.60.6"@@ -7980,27 +7980,27 @@ next-basics@^0.39.0:jsonwebtoken "^9.0.0"pure-rand "^6.0.2"- version "15.0.4"- resolved "https://registry.yarnpkg.com/next/-/next-15.0.4.tgz#7ddad7299204f16c132d7e524cf903f1a513588e"- integrity sha512-nuy8FH6M1FG0lktGotamQDCXhh5hZ19Vo0ht1AOIQWrYJLP598TIUagKtvJrfJ5AGwB/WmDqkKaKhMpVifvGPA==+ version "15.1.4"+ resolved "https://registry.yarnpkg.com/next/-/next-15.1.4.tgz#cb2aee3fbb772e20b98ccc2f0806249c09f780a2"+ integrity sha512-mTaq9dwaSuwwOrcu3ebjDYObekkxRnXpuVL21zotM8qE2W0HBOdVIdg2Li9QjMEZrj73LN96LcWcz62V19FjAg==dependencies:- "@next/env" "15.0.4"+ "@next/env" "15.1.4""@swc/counter" "0.1.3"- "@swc/helpers" "0.5.13"+ "@swc/helpers" "0.5.15"busboy "1.6.0"caniuse-lite "^1.0.30001579"postcss "8.4.31"styled-jsx "5.1.6"optionalDependencies:- "@next/swc-darwin-arm64" "15.0.4"- "@next/swc-darwin-x64" "15.0.4"- "@next/swc-linux-arm64-gnu" "15.0.4"- "@next/swc-linux-arm64-musl" "15.0.4"- "@next/swc-linux-x64-gnu" "15.0.4"- "@next/swc-linux-x64-musl" "15.0.4"- "@next/swc-win32-arm64-msvc" "15.0.4"- "@next/swc-win32-x64-msvc" "15.0.4"+ "@next/swc-darwin-arm64" "15.1.4"+ "@next/swc-darwin-x64" "15.1.4"+ "@next/swc-linux-arm64-gnu" "15.1.4"+ "@next/swc-linux-arm64-musl" "15.1.4"+ "@next/swc-linux-x64-gnu" "15.1.4"+ "@next/swc-linux-x64-musl" "15.1.4"+ "@next/swc-win32-arm64-msvc" "15.1.4"+ "@next/swc-win32-x64-msvc" "15.1.4"sharp "^0.33.5"nice-try@^1.0.4:@@ -9690,6 +9690,13 @@ semver@^7.3.4, semver@^7.3.7, semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semveresolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==+serialize-error@^12.0.0:+ version "12.0.0"+ resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-12.0.0.tgz#aed3d5abff192c855707513929bf8bf48d712194"+ integrity sha512-ZYkZLAvKTKQXWuh5XpBw7CdbSzagarX39WyZ2H07CDLC5/KfsRGlIXV8d4+tfqX1M7916mRqR1QfNHSij+c9Pw==+ dependencies:+ type-fest "^4.31.0"+serialize-javascript@^4.0.0:version "4.0.0"resolved "https://registry.yarnpkg.com/serialize-javascript/-/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa"@@ -10477,7 +10484,7 @@ tsconfig-paths@^3.15.0:minimist "^1.2.6"strip-bom "^3.0.0"-tslib@2, tslib@^2.1.0, tslib@^2.4.0:+tslib@2, tslib@^2.1.0, tslib@^2.4.0, tslib@^2.8.0:version "2.8.1"resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==@@ -10553,6 +10560,11 @@ type-fest@^1.0.1, type-fest@^1.0.2, type-fest@^1.2.1, type-fest@^1.2.2:resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1"integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==+type-fest@^4.31.0:+ version "4.31.0"+ resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.31.0.tgz#a3de630c96eb77c281b6ba2affa5dae5fb3c326c"+ integrity sha512-yCxltHW07Nkhv/1F6wWBr8kz+5BGMfP+RbRSYFnegVb0qV/UMT0G0ElBloPVerqn4M2ZV80Ir1FtCcYv1cT6vQ==+typed-array-buffer@^1.0.2:version "1.0.2"resolved "https://registry.yarnpkg.com/typed-array-buffer/-/typed-array-buffer-1.0.2.tgz#1867c5d83b20fcb5ccf32649e5e2fc7424474ff3"