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 encoding logic in tracker and send.
Mike Cao91f49ba5068a
diff --git a/src/pages/api/send.ts b/src/pages/api/send.tsindex 1ca23a41b..bf6fc2137 100644--- a/src/pages/api/send.ts+++ b/src/pages/api/send.ts@@ -6,7 +6,15 @@ import { getIpAddress } from 'lib/detect';import { useCors, useSession, useValidate } from 'lib/middleware';import { CollectionType, YupRequest } from 'lib/types';import { NextApiRequest, NextApiResponse } from 'next';-import { badRequest, createToken, forbidden, methodNotAllowed, ok, send } from 'next-basics';+import {+ badRequest,+ createToken,+ forbidden,+ methodNotAllowed,+ ok,+ safeDecodeURI,+ send,+} from 'next-basics';import { saveEvent, saveSessionData } from 'queries';import * as yup from 'yup';@@ -88,8 +96,8 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {}const { type, payload } = req.body;-- const { url, referrer, name: eventName, data: eventData, title: pageTitle } = payload;+ const { url, referrer, name: eventName, data: eventData, title } = payload;+ const pageTitle = safeDecodeURI(title);await useSession(req, res);@@ -105,8 +113,8 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {if (type === COLLECTION_TYPE.event) {// eslint-disable-next-line prefer-const- let [urlPath, urlQuery] = url?.split('?') || [];- let [referrerPath, referrerQuery] = referrer?.split('?') || [];+ let [urlPath, urlQuery] = safeDecodeURI(url)?.split('?') || [];+ let [referrerPath, referrerQuery] = safeDecodeURI(referrer)?.split('?') || [];let referrerDomain = '';if (!urlPath) {diff --git a/src/tracker/index.js b/src/tracker/index.jsindex d16b2a9ae..ace1d7c23 100644--- a/src/tracker/index.js+++ b/src/tracker/index.js@@ -32,6 +32,20 @@/* Helper functions */+ const encode = str => {+ try {+ const result = decodeURI(str);++ if (result !== str) {+ return result;+ }+ } catch {+ return str;+ }++ return encodeURI(str);+ };+const parseURL = url => {return excludeSearch ? url.split('?')[0] : url;};@@ -41,9 +55,9 @@hostname,screen,language,- title: encodeURIComponent(title),- url: encodeURI(currentUrl),- referrer: encodeURI(currentRef),+ title: encode(title),+ url: encode(currentUrl),+ referrer: encode(currentRef),});/* Event handlers */