Skip to content

Commit

Permalink
fix: ensure analytics logs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebolam committed Jan 27, 2019
1 parent 107a603 commit 8caf67b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
22 changes: 11 additions & 11 deletions src/utils/Analytics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const uuid = require('uuid')
const nodeFetch = require('node-fetch')
const { URLSearchParams } = require('url')

class Analytics {
constructor({ user, repo, owner, apiKey, log, funnelId }) {
Expand All @@ -26,27 +27,26 @@ class Analytics {
},
}

const payload = {
api_key: this.apiKey,
event: [
// TODO batch up to 10 events at a time
event,
],
}
const events = [
// TODO batch up to 10 events at a time
event,
]

const log = this.log

const params = new URLSearchParams()
params.append('api_key', this.apiKey)
params.append('event', JSON.stringify(events))

const newEventPromise = nodeFetch('https://api.amplitude.com/httpapi', {
method: 'post',
body: JSON.stringify(payload),
headers: { 'Content-Type': 'application/json' },
method: 'POST',
body: params,
timeout: 5000,
redirect: 'error',
follow: 0,
})
.then(response => {
if (!response.ok) {
// TODO: error handling
log.error(response)
}
return response
Expand Down
14 changes: 1 addition & 13 deletions test/utils/__snapshots__/Analytics.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
exports[`Analytics Analytics 1`] = `
Object {
"api_key": "mock api key",
"event": Array [
Object {
"event_properties": Object {
"funnel_id": "mockFunnelId",
},
"event_type": "my-event",
"user_id": "mockusername",
"user_properties": Object {
"owner": "all-contributors",
"repo": "all-contributors-bot",
},
},
],
"event": "[{\\"user_id\\":\\"mockusername\\",\\"event_type\\":\\"my-event\\",\\"user_properties\\":{\\"repo\\":\\"all-contributors-bot\\",\\"owner\\":\\"all-contributors\\"},\\"event_properties\\":{\\"funnel_id\\":\\"mockFunnelId\\"}}]",
}
`;

0 comments on commit 8caf67b

Please # to comment.