You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Batching means that your message might not get sent right away. But every method call takes an optional callback, which you can use to know when a particular message is flushed from the queue, like so:
1. Double check that you’ve followed all the steps in the Quick Start.
184
189
185
190
2. Make sure that you’re calling a Segment API method once the library is successfully installed: identify, track, etc.
186
191
187
-
3. Log events and errors the event emitter:
192
+
3. Log events.
188
193
```js
189
194
['initialize', 'call_after_close',
190
195
'screen', 'identify', 'group',
@@ -194,6 +199,20 @@ const appAnalytics = new Analytics('APP_WRITE_KEY');
194
199
```
195
200
196
201
202
+
## Development: Disabling Analytics for Tests
203
+
- If you want to intercept / disable analytics for integration tests, you can use something like [nock](https://github.com/nock/nock)
204
+
205
+
```ts
206
+
// Note: nock will _not_ work if polyfill fetch with something like undici, as nock uses the http module. Undici has its own interception method.
207
+
importnockfrom'nock'
208
+
209
+
nock('https://api.segment.io')
210
+
.post('/v1/batch')
211
+
.reply(201)
212
+
.persist()
213
+
```
214
+
215
+
197
216
## Differences from legacy analytics-node / Migration Guide
198
217
199
218
@@ -206,15 +225,13 @@ import Analytics from 'analytics-node'
- If you want to disable analytics for unit tests, you can use something like [nock](https://github.com/nock/nock) or [jest mocks](https://jestjs.io/docs/manual-mocks).
263
-
264
-
You should prefer mocking. However, if you need to intercept the request, you can do:
265
-
266
-
```ts
267
-
// Note: nock will _not_ work if polyfill fetch with something like undici, as nock uses the http module. Undici has its own interception method.
268
-
importnockfrom'nock'
269
-
270
-
const mockApiHost ='https://foo.bar'
271
-
const mockPath ='/foo'
272
-
273
-
nock(mockApiHost) // using regex matching in nock changes the perf profile quite a bit
0 commit comments