diff --git a/src/modules/request.js b/src/modules/request.js index 038e715..1e50d5d 100644 --- a/src/modules/request.js +++ b/src/modules/request.js @@ -1,7 +1,16 @@ export const sendRequest = (endpoint, payload, mode = 'browser', opts = {}) => { - const qs = new URLSearchParams( - JSON.parse(JSON.stringify(payload)) - ).toString() + const payloadParsed = JSON.parse(JSON.stringify(payload)) + let qs = '' + if (opts.encode_search_params) { + // Ensure spaces are not replaced with + + qs = Object.entries(payloadParsed) + .map(([key, value]) => `${key}=${encodeURIComponent(value)}`) + .join('&') + } else { + qs = new URLSearchParams( + payloadParsed + ).toString() + } if (mode === 'browser') { navigator?.sendBeacon([endpoint, qs].join('?')) } else {