Skip to content

Commit d15de2b

Browse files
committed
remove AnalyticsNode from browser
1 parent 151a58f commit d15de2b

File tree

12 files changed

+28
-224
lines changed

12 files changed

+28
-224
lines changed

.changeset/plenty-peaches-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': patch
3+
---
4+
5+
Remove experimental/undocumented AnalyticsNode library from browser. @segment/analytics-node should be used.

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"editor.defaultFormatter": "esbenp.prettier-vscode"
2525
},
2626
"[typescript]": {
27-
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
27+
"editor.defaultFormatter": "esbenp.prettier-vscode"
2828
},
2929
"[typescriptreact]": {
3030
"editor.defaultFormatter": "esbenp.prettier-vscode"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@changesets/cli": "^2.23.2",
3838
"@internal/config": "workspace:^",
3939
"@npmcli/promise-spawn": "^3.0.0",
40+
"@segment/analytics-node": "workspace:^",
4041
"@types/express": "4",
4142
"@types/jest": "^28.1.1",
4243
"@types/lodash": "^4",

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"@segment/tsub": "1.0.1",
5555
"dset": "^3.1.2",
5656
"js-cookie": "3.0.1",
57-
"node-fetch": "^2.6.7",
5857
"spark-md5": "^3.0.1",
5958
"tslib": "^2.4.1",
6059
"unfetch": "^4.1.0"
@@ -88,6 +87,7 @@
8887
"log-update": "^4.0.0",
8988
"micro-memoize": "^4.0.9",
9089
"mime": "^2.4.6",
90+
"node-fetch": "^2.6.7",
9191
"node-gyp": "^9.0.0",
9292
"playwright": "^1.28.1",
9393
"serve-handler": "^6.1.3",

packages/browser/qa/lib/stats.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,44 @@
1-
import { Analytics } from '../../src/index'
2-
import { Context } from '../../src/core/context'
3-
import { AnalyticsNode } from '../../src/node'
1+
import { Analytics, Context } from '@segment/analytics-node'
42
import ex from 'execa'
53

6-
let analytics!: Analytics
7-
8-
94
const getBranch = async () =>
105
(await ex('git', ['branch', '--show-current'])).stdout
116

12-
async function client(): Promise<Analytics> {
13-
7+
function client(): Analytics {
148
if (!process.env.STATS_WRITEKEY) {
159
throw new Error('no process.env.STATS_WRITEKEY')
1610
}
1711

18-
if (analytics) {
19-
return analytics
20-
}
21-
22-
const [nodeAnalytics] = await AnalyticsNode.load({
12+
const analytics = new Analytics({
2313
writeKey: process.env.STATS_WRITEKEY,
14+
maxEventsInBatch: 1,
2415
})
2516

26-
analytics = nodeAnalytics
2717
return analytics
2818
}
2919

3020
export async function gauge(
3121
metric: string,
3222
value: number = 0,
3323
tags: string[] = []
34-
): Promise<Context> {
35-
const ajs = await client()
24+
) {
25+
const ajs = client()
3626

3727
const branch = process.env.BUILDKITE_BRANCH || (await getBranch())
3828

39-
const ctx = await ajs.track(
40-
metric,
41-
{
42-
value,
43-
tags: [...tags, `branch:${branch}`],
44-
type: 'gauge',
45-
},
46-
{
47-
userId: 'system',
48-
}
29+
const ctx = await new Promise<Context>((resolve, reject) =>
30+
ajs.track(
31+
{
32+
event: metric,
33+
properties: {
34+
value,
35+
tags: [...tags, `branch:${branch}`],
36+
type: 'gauge',
37+
},
38+
userId: 'system',
39+
},
40+
(err, res) => (err ? reject(err) : resolve(res!))
41+
)
4942
)
5043

5144
return ctx

packages/browser/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './core/analytics'
22
export * from './browser'
3-
export * from './node'
43

54
export * from './core/context'
65
export * from './core/events'

packages/browser/src/node/__tests__/node-integration.test.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/browser/src/node/index.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

packages/browser/src/node/node.browser.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/browser/src/plugins/analytics-node/__tests__/index.test.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)