Skip to content

Commit 3af83bf

Browse files
committed
wip
1 parent 58341c1 commit 3af83bf

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/browser/architecture/ARCHITECTURE.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ graph TD
3939
end
4040
```
4141

42-
### Plugin Types Explanation
42+
### Plugin Types and Middleware
4343
[This information is also available in the Segment documentation](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#plugins-and-source-middleware)
4444

4545
- **Source Middleware** (see [Example](#example-source-middleware-implementation))
@@ -73,7 +73,7 @@ graph TD
7373
- Do not directly process events
7474
- Example: some plugin that registers a bunch of analytics event listeners (e.g. analytics.on('track', ...) and reports them to an external system)
7575

76-
- **Add Destination Middleware** (See [Example](#example-destination-middleware-implementation))
76+
- **Destination Middleware** (See [Example](#example-destination-middleware-implementation))
7777
- A special type of plugin that allows you to add a plugin that only affects a specific (device mode) destination plugin.
7878

7979

@@ -116,7 +116,7 @@ analytics.addSourceMiddleware(({ payload, next }) => {
116116

117117
### Example: Destination Middleware Implementation
118118
> [!NOTE]
119-
> It is not currently possible to add a destination middleware JUST to the segment.io destination plugin.
119+
> It is not currently possible to add a destination middleware to the Segment.io destination.
120120
```ts
121121
analytics.addDestinationMiddleware('amplitude', ({ next, payload }) => {
122122
payload.obj.properties!.hello = 'from the other side'
@@ -126,6 +126,7 @@ analytics.addDestinationMiddleware('amplitude', ({ next, payload }) => {
126126
or, to apply to all destinations
127127
```ts
128128
analytics.addDestinationMiddleware('*', (ctx) => {
129+
// This does not apply to the segment.io destination plugin, only device mode destinations.
129130
ctx.event.properties!.hello = 'from the other side'
130131
return ctx
131132
})
@@ -137,10 +138,10 @@ When `analytics.track()` is called:
137138

138139
1. Event is created via Event Factory
139140
2. Event enters the queue
140-
3. Before plugins validate/transform
141-
4. Enrichment plugins add data in parallel
142-
5. Destination plugins receive the event in parallel (including Segment.io plugin)
143-
6. Any after plugins handle post-processing (e.g. metrics collection)
141+
3. Before plugins run, in order of registration
142+
3. Enrichment plugins run, in order of registration
143+
4. Destination plugins receive the event in parallel (including Segment.io plugin)
144+
5. Any after plugins handle post-processing (e.g. metrics collection)
144145

145146
### Plugin Priorities
146147

0 commit comments

Comments
 (0)