Skip to content

Commit 212aadc

Browse files
committed
wip
1 parent 8864a6a commit 212aadc

File tree

1 file changed

+5
-46
lines changed
  • src/connections/sources/catalog/libraries/server/node

1 file changed

+5
-46
lines changed

src/connections/sources/catalog/libraries/server/node/index.md

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -480,27 +480,27 @@ analytics.on('http_request', (event) => console.log(event))
480480
| `alias` | Emitted when an Alias call is made.
481481
| `flush` | Emitted after a batch is flushed.
482482
| `http_request` | Emitted when an HTTP request is made. |
483+
| `register` | Emitted when a plugin is registered
483484
| `call_after_close`| Emitted when an event is received after the flush with `{ close: true }`. |
484485
485486
These emitters allow you to hook into various stages of the event lifecycle and handle them accordingly.
486487
487488
488489
## Plugin architecture
489-
When you develop in [Analytics.js 2.0](/docs/connections/sources/catalog/libraries/website/javascript/), the plugins you write can improve functionality, enrich data, and control the flow and delivery of events. From modifying event payloads to changing analytics functionality, plugins help to speed up the process of getting things done.
490+
The plugins you write can improve functionality, enrich data, and control the flow and delivery of events. From modifying event payloads to changing analytics functionality, plugins help to speed up the process of getting things done.
490491
491-
Though middlewares function the same as plugins, it's best to use plugins as they are easier to implement and are more testable.
492492
493493
### Plugin categories
494494
495495
| Type | Details
496496
| ------------- | ------------- |
497-
| `before` | Executes before event processing begins. These are plugins that run before any other plugins run. Thrown errors here can block the event pipeline. Source middleware added via `addSourceMiddleware` is treated as a `before` plugin. |
498-
| `enrichment` | Executes as the first level of event processing. These plugins modify an event. Thrown errors here can block the event pipeline. |
497+
| `before` | Executes before event processing begins. These are plugins that run before any other plugins run. Thrown errors here can block the event pipeline. Source middleware added via `addSourceMiddleware` is treated as a `before` plugin. No events will be sent to destinations until `.load()` method is resolved. |
498+
| `enrichment` | Executes as the first level of event processing. These plugins modify an event. Thrown errors here can block the event pipeline. No events will be sent to destinations until `.load()` method is resolved. |
499499
| `destination` | Executes as events begin to pass off to destinations. Segment.io is implemented as a destination plugin. Thrown errors here will _not_ block the event pipeline. |
500500
| `after` | Executes after all event processing completes. You can use this to perform cleanup operations. |
501501
| `utility` | Executes _only once_ during the bootstrap. Gives you access to the analytics instance via the plugin's `load()` method. This doesn't allow you to modify events. |
502502
503-
### Example plugins
503+
### Example plugin
504504
Here's an example of a plugin that converts all track event names to lowercase before the event goes through the rest of the pipeline:
505505
506506
```js
@@ -517,49 +517,8 @@ export const lowercase: Plugin = {
517517
return ctx
518518
}
519519
}
520-
521-
const identityStitching = () => {
522-
let user
523-
524-
const identity = {
525-
// Identifies your plugin in the Plugins stack.
526-
// Access `window.analytics.queue.plugins` to see the full list of plugins
527-
name: 'Identity Stitching',
528-
// Defines where in the event timeline a plugin should run
529-
type: 'enrichment',
530-
version: '0.1.0',
531-
532-
// Used to signal that a plugin has been property loaded
533-
isLoaded: () => user !== undefined,
534-
535-
// Applies the plugin code to every `identify` call in Analytics.js
536-
// You can override any of the existing types in the Segment Spec.
537-
async identify(ctx) {
538-
// Request some extra info to enrich your `identify` events from
539-
// an external API.
540-
const req = await fetch(
541-
`https://jsonplaceholder.typicode.com/users/${ctx.event.userId}`
542-
)
543-
const userReq = await req.json()
544-
545-
// ctx.updateEvent can be used to update deeply nested properties
546-
// in your events. It's a safe way to change events as it'll
547-
// create any missing objects and properties you may require.
548-
ctx.updateEvent('traits.custom', userReq)
549-
user.traits(userReq)
550-
551-
// Every plugin must return a `ctx` object, so that the event
552-
// timeline can continue processing.
553-
return ctx
554-
},
555-
}
556-
557-
return identity
558-
}
559520
```
560521
561-
You can view Segment's [existing plugins](https://github.com/segmentio/analytics-next/tree/master/packages/browser/src/plugins){:target="_blank"} to see more examples.
562-
563522
### Register a plugin
564523
Registering plugins enable you to modify your analytics implementation to best fit your needs. You can register a plugin using this:
565524

0 commit comments

Comments
 (0)