Skip to content

Commit 7b24b87

Browse files
authored
feat: adding in amplitude (#3791)
1 parent c9698b0 commit 7b24b87

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
"@influxdata/influxdb-templates": "0.9.0",
163163
"@influxdata/react-custom-scrollbars": "4.3.8",
164164
"abortcontroller-polyfill": "^1.3.0",
165+
"amplitude-js": "^8.16.1",
165166
"auth0-js": "^9.13.2",
166167
"babel-polyfill": "^6.26.0",
167168
"chroma-js": "^1.3.6",

src/cloud/utils/reporting.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {useState, useEffect} from 'react'
22
import {isEmpty} from 'lodash'
3+
import amplitude from 'amplitude-js'
34

45
import {
56
reportPoints as reportPointsAPI,
@@ -9,10 +10,10 @@ import {
910
} from 'src/cloud/apis/reporting'
1011

1112
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
12-
import {CLOUD, GIT_SHA} from 'src/shared/constants'
13+
import {CLOUD, GIT_SHA, AMPLITUDE_KEY} from 'src/shared/constants'
1314
export {Point, PointTags, PointFields} from 'src/cloud/apis/reporting'
1415

15-
let reportingTags = {}
16+
let reportingTags: KeyValue = {}
1617
let reportingPoints = []
1718
let reportDecayTimeout = null
1819
let reportMaxTimeout = null
@@ -28,6 +29,21 @@ interface KeyValue {
2829

2930
export const updateReportingContext = (properties: KeyValue) => {
3031
reportingTags = {...reportingTags, ...properties}
32+
33+
if (AMPLITUDE_KEY && isFlagEnabled('amplitude')) {
34+
const inst = amplitude.getInstance()
35+
36+
if (!inst._isInitialized) {
37+
inst.init(AMPLITUDE_KEY)
38+
}
39+
40+
if (properties.hasOwnProperty('userID')) {
41+
delete reportingTags.userID
42+
inst.setUserId(properties.userID)
43+
}
44+
45+
inst.setUserProperties(reportingTags)
46+
}
3147
}
3248

3349
export const toNano = (ms: number) => Math.round(ms * 1000000)
@@ -180,6 +196,16 @@ export const event = (
180196

181197
gaEvent(measurement, {...values, ...meta})
182198

199+
if (AMPLITUDE_KEY && isFlagEnabled('amplitude')) {
200+
const inst = amplitude.getInstance()
201+
202+
if (!inst._isInitialized) {
203+
inst.init(AMPLITUDE_KEY)
204+
}
205+
206+
inst.logEvent(measurement, {...values, ...meta})
207+
}
208+
183209
pooledEvent({
184210
timestamp: toNano(time),
185211
measurement,

src/shared/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const BASE_PATH = formatConstant(process.env.STATIC_PREFIX)
8686
export const API_BASE_PATH = formatConstant(process.env.API_PREFIX)
8787
export const HONEYBADGER_KEY = formatConstant(process.env.HONEYBADGER_KEY)
8888
export const HONEYBADGER_ENV = formatConstant(process.env.HONEYBADGER_ENV)
89+
export const AMPLITUDE_KEY = formatConstant(process.env.AMPLITUDE_KEY)
8990

9091
export const RUDDERSTACK_DATA_PLANE_URL = formatConstant(
9192
process.env.RUDDERSTACK_DATA_PLANE_URL

yarn.lock

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@
125125
"@algolia/logger-common" "4.11.0"
126126
"@algolia/requester-common" "4.11.0"
127127

128+
"@amplitude/types@^1.9.2":
129+
version "1.9.2"
130+
resolved "https://registry.yarnpkg.com/@amplitude/types/-/types-1.9.2.tgz#d664c70562317b189f4ba9b33681bad2105df101"
131+
integrity sha512-s+Q/O8kNfocZiyGvVdtM5T4JGPwLRZ4Q26wtEF5xJhyCtJglGMe0ixe6u/6iW9s4JHIq+LlPlUu5095pVsdtNA==
132+
133+
"@amplitude/ua-parser-js@0.7.26":
134+
version "0.7.26"
135+
resolved "https://registry.yarnpkg.com/@amplitude/ua-parser-js/-/ua-parser-js-0.7.26.tgz#18d889d84d2ba90c248ab6fcd7e3dd07f1c9c86e"
136+
integrity sha512-62/Rid6YQ7F2KT/5vTre41Y26ivrEoFC8lbrsJZqBKaiXMJWG0YpNv9RgxNSaZS2jPLVQgoB/FFeWxihOLfIcg==
137+
138+
"@amplitude/utils@^1.0.5":
139+
version "1.9.2"
140+
resolved "https://registry.yarnpkg.com/@amplitude/utils/-/utils-1.9.2.tgz#a9e1a71341f6301096bd71c2df7bcdefec3fdf31"
141+
integrity sha512-hGOIoIjmZ0pq/3b2gBrr17TaEarlR+qzFGu5npm76+scd/51F0eNvjd0vgV6WbJT1cxhyH/5Z8kihGWOU3vS3Q==
142+
dependencies:
143+
"@amplitude/types" "^1.9.2"
144+
tslib "^1.9.3"
145+
128146
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.0", "@babel/code-frame@^7.8.3":
129147
version "7.16.0"
130148
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.0.tgz#0dfc80309beec8411e65e706461c408b0bb9b431"
@@ -995,6 +1013,13 @@
9951013
dependencies:
9961014
regenerator-runtime "^0.13.4"
9971015

1016+
"@babel/runtime@^7.3.4":
1017+
version "7.17.0"
1018+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.0.tgz#b8d142fc0f7664fb3d9b5833fd40dcbab89276c0"
1019+
integrity sha512-etcO/ohMNaNA2UBdaXBBSX/3aEzFMRrVfaPv8Ptc0k+cWpWW0QFiGZ2XnVqQZI1Cf734LbPGmqBKWESfW4x/dQ==
1020+
dependencies:
1021+
regenerator-runtime "^0.13.4"
1022+
9981023
"@babel/template@^7.16.0", "@babel/template@^7.3.3":
9991024
version "7.16.0"
10001025
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.0.tgz#d16a35ebf4cd74e202083356fab21dd89363ddd6"
@@ -2339,6 +2364,17 @@ amdefine@>=0.0.4:
23392364
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
23402365
integrity sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=
23412366

2367+
amplitude-js@^8.16.1:
2368+
version "8.16.1"
2369+
resolved "https://registry.yarnpkg.com/amplitude-js/-/amplitude-js-8.16.1.tgz#6c8c603237f861685e04c8669e562664749b5065"
2370+
integrity sha512-1X9xvxmWIK1DlVluuk2QXziYcgSiZE4d4DLhMzY9yUP+KauCbFy37lW4m3dixp6Y8AIGU+WUAfAsCLqXYlF0rw==
2371+
dependencies:
2372+
"@amplitude/ua-parser-js" "0.7.26"
2373+
"@amplitude/utils" "^1.0.5"
2374+
"@babel/runtime" "^7.3.4"
2375+
blueimp-md5 "^2.10.0"
2376+
query-string "5"
2377+
23422378
ansi-colors@^4.1.1:
23432379
version "4.1.1"
23442380
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
@@ -2841,6 +2877,11 @@ bluebird@^3.5.5, bluebird@^3.7.2:
28412877
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
28422878
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
28432879

2880+
blueimp-md5@^2.10.0:
2881+
version "2.19.0"
2882+
resolved "https://registry.yarnpkg.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz#b53feea5498dcb53dc6ec4b823adb84b729c4af0"
2883+
integrity sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w==
2884+
28442885
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.9:
28452886
version "4.12.0"
28462887
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
@@ -9310,6 +9351,15 @@ qs@~6.5.2:
93109351
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
93119352
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
93129353

9354+
query-string@5:
9355+
version "5.1.1"
9356+
resolved "https://registry.yarnpkg.com/query-string/-/query-string-5.1.1.tgz#a78c012b71c17e05f2e3fa2319dd330682efb3cb"
9357+
integrity sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==
9358+
dependencies:
9359+
decode-uri-component "^0.2.0"
9360+
object-assign "^4.1.0"
9361+
strict-uri-encode "^1.0.0"
9362+
93139363
query-string@^4.1.0:
93149364
version "4.3.4"
93159365
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
@@ -11174,7 +11224,7 @@ ts-node@^8.3.0:
1117411224
source-map-support "^0.5.17"
1117511225
yn "3.1.1"
1117611226

11177-
tslib@^1.8.1, tslib@^1.9.0:
11227+
tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
1117811228
version "1.14.1"
1117911229
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
1118011230
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

0 commit comments

Comments
 (0)