Skip to content

Commit

Permalink
move back to segment (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 authored Feb 6, 2021
1 parent 291ff70 commit 20517b0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@sentry/node": "^6.0.0",
"analytics-node": "^3.5.0",
"async-sema": "^3.1.0",
"bad-words": "^3.0.4",
"bee-queue": "^1.3.1",
Expand Down
10 changes: 5 additions & 5 deletions src/analytics.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const Windsor = require('windsor-node')
const Analytics = require('analytics-node')

if (
process.env.NODE_ENV === 'test' ||
(process.env.NODE_ENV === 'production' && process.env.WINDSOR_KEY)
(process.env.NODE_ENV === 'production' && process.env.SEGMENT_WRITE_KEY)
) {
let analytics = new Windsor(process.env.WINDSOR_KEY)
let analytics = new Analytics(process.env.SEGMENT_WRITE_KEY)
module.exports = {
identify: analytics.user.bind(analytics),
identify: analytics.identify.bind(analytics),
track: (x) => {
try {
return analytics.event.call(analytics, typeof x === 'function' ? x() : x)
return analytics.track.call(analytics, typeof x === 'function' ? x() : x)
} catch (error) {
console.error(error)
}
Expand Down
8 changes: 3 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ jest.mock(
)

jest.mock(
'windsor-node',
'analytics-node',
() =>
class {
constructor() {
// this.track = jest.fn()
// this.identify = jest.fn()
this.user = jest.fn()
this.event = jest.fn()
this.track = jest.fn()
this.identify = jest.fn()
}
}
)
Expand Down
44 changes: 41 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@
readable-stream "^3.6.0"
split2 "^3.2.2"

"@segment/[email protected]":
"@segment/[email protected]", "@segment/loosely-validate-event@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@segment/loosely-validate-event/-/loosely-validate-event-2.0.0.tgz#87dfc979e5b4e7b82c5f1d8b722dfd5d77644681"
integrity sha512-ZMCSfztDBqwotkl848ODgVcAmN4OItEWDCkshcKz0/W6gGSQayuuCtWV/MlodFivAZD793d6UgANd6wCXUfrIw==
Expand Down Expand Up @@ -1214,6 +1214,20 @@ ajv@^7.0.2:
require-from-string "^2.0.2"
uri-js "^4.2.2"

analytics-node@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/analytics-node/-/analytics-node-3.5.0.tgz#b33ff92195f006b20f1c4e28af86d975c98e4636"
integrity sha512-XgQq6ejZHCehUSnZS4V7QJPLIP7S9OAWwQDYl4WTLtsRvc5fCxIwzK/yihzmIW51v9PnyBmrl9dMcqvwfOE8WA==
dependencies:
"@segment/loosely-validate-event" "^2.0.0"
axios "^0.21.1"
axios-retry "^3.0.2"
lodash.isstring "^4.0.1"
md5 "^2.2.1"
ms "^2.0.0"
remove-trailing-slash "^0.1.0"
uuid "^3.2.1"

ansi-align@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.0.tgz#b536b371cf687caaef236c18d3e21fe3797467cb"
Expand Down Expand Up @@ -1408,13 +1422,27 @@ [email protected]:
dependencies:
is-retry-allowed "^1.1.0"

axios-retry@^3.0.2:
version "3.1.9"
resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.1.9.tgz#6c30fc9aeb4519aebaec758b90ef56fa03fe72e8"
integrity sha512-NFCoNIHq8lYkJa6ku4m+V1837TP6lCa7n79Iuf8/AqATAHYB0ISaAS1eyIenDOfHOLtym34W65Sjke2xjg2fsA==
dependencies:
is-retry-allowed "^1.1.0"

[email protected]:
version "0.19.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
dependencies:
follow-redirects "1.5.10"

axios@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
dependencies:
follow-redirects "^1.10.0"

babel-jest@^26.6.3:
version "26.6.3"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-26.6.3.tgz#d87d25cb0037577a0c89f82e5755c5d293c01056"
Expand Down Expand Up @@ -2944,6 +2972,11 @@ [email protected]:
dependencies:
debug "=3.1.0"

follow-redirects@^1.10.0:
version "1.13.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147"
integrity sha512-6mPTgLxYm3r6Bkkg0vNM0HTjfGrOEtsfbhagQvbxDEsEkpNhw582upBaoRZylzen6krEmxXJgt9Ju6HiI4O7BA==

for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand Down Expand Up @@ -4825,7 +4858,7 @@ [email protected], ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

ms@^2.1.3:
ms@^2.0.0, ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
Expand Down Expand Up @@ -5837,6 +5870,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/remove-trailing-slash/-/remove-trailing-slash-0.1.0.tgz#1498e5df0984c27e49b76ebf06887ca2d01150d2"
integrity sha1-FJjl3wmEwn5Jt26/Boh8otARUNI=

remove-trailing-slash@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/remove-trailing-slash/-/remove-trailing-slash-0.1.1.tgz#be2285a59f39c74d1bce4f825950061915e3780d"
integrity sha512-o4S4Qh6L2jpnCy83ysZDau+VORNvnFw07CKSAymkd6ICNVEPisMyzlc00KlvvicsxKck94SEwhDnMNdICzO+tA==

repeat-element@^1.1.2:
version "1.1.3"
resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.3.tgz#782e0d825c0c5a3bb39731f84efee6b742e6b1ce"
Expand Down Expand Up @@ -6938,7 +6976,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.2.0.tgz#cb10dd6b118e2dada7d0cd9730ba7417c93d920e"
integrity sha512-CYpGiFTUrmI6OBMkAdjSDM0k5h8SkkiTP4WAjQgDgNB1S3Ou9VBEvr6q0Kv2H1mMk7IWfxYGpMH5sd5AvcIV2Q==

uuid@^3.0.0, uuid@^3.3.2:
uuid@^3.0.0, uuid@^3.2.1, uuid@^3.3.2:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
Expand Down

0 comments on commit 20517b0

Please sign in to comment.