mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-24 11:01:38 +01:00
Updated encoding logic in tracker and send.
This commit is contained in:
parent
4ee7deafdd
commit
91f49ba506
@ -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) {
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user