From b19889638aa62ee088c9fe1cf5958d2da9d53d45 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Fri, 18 Sep 2020 14:16:57 -0700 Subject: [PATCH] Removed polyfills from tracker. Switched to XMLHttpRequest. --- lib/middleware.js | 1 + tracker/index.js | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 014b225d..c41e75d0 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -23,6 +23,7 @@ export const useSession = use(async (req, res, next) => { try { session = await getSession(req); } catch (e) { + console.error(e); return serverError(res, e.message); } diff --git a/tracker/index.js b/tracker/index.js index e3cb4fe4..38aadeb3 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -1,6 +1,4 @@ -import 'promise-polyfill/src/polyfill'; -import 'unfetch/polyfill'; -import { doNotTrack, hook, post } from '../lib/web'; +import { doNotTrack, hook } from '../lib/web'; import { removeTrailingSlash } from '../lib/url'; (window => { @@ -32,6 +30,20 @@ import { removeTrailingSlash } from '../lib/url'; /* Collect metrics */ + const post = (url, data, callback) => { + const req = new XMLHttpRequest(); + req.open('POST', url, true); + req.setRequestHeader('Content-Type', 'application/json'); + + req.onreadystatechange = () => { + if (req.readyState === 4) { + callback && callback(); + } + }; + + req.send(JSON.stringify(data)); + }; + const collect = (type, params, uuid) => { const payload = { website: uuid, @@ -133,5 +145,7 @@ import { removeTrailingSlash } from '../lib/url'; history.replaceState = hook(history, 'replaceState', handlePush); pageView(currentUrl, currentRef); + + loadEvents(); } })(window);