diff --git a/ghost/portal/src/utils/api.js b/ghost/portal/src/utils/api.js index 5de1dc8f29..e27fc8f8e5 100644 --- a/ghost/portal/src/utils/api.js +++ b/ghost/portal/src/utils/api.js @@ -7,7 +7,7 @@ function setupGhostApi({siteUrl = window.location.origin}) { } } - function makeRequest({url, method, headers = {}, credentials, body}) { + function makeRequest({url, method = 'GET', headers = {}, credentials = undefined, body = undefined}) { const options = { method, headers, @@ -18,6 +18,28 @@ function setupGhostApi({siteUrl = window.location.origin}) { } const api = {}; + api.analytics = { + pushEvent(event) { + const url = endpointFor({type: 'members', resource: 'events'}); + const body = { + events: [event] + }; + return makeRequest({ + url, + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(body) + }).then(function (res) { + if (!res.ok) { + return null; + } + return res.json(); + }); + } + }; + api.site = { read() { const url = endpointFor({type: 'members', resource: 'site'});