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
Copy file name to clipboardExpand all lines: packages/browser/architecture/ARCHITECTURE.md
+31-9Lines changed: 31 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,35 +42,40 @@ graph TD
42
42
### Plugin Types Explanation
43
43
[This information is also available in the Segment documentation](https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#plugins-and-source-middleware)
44
44
45
-
1.**Before Plugins** (see [Example](#example-plugin-implementation))
45
+
-**Source Middleware** (see [Example](#example-source-middleware-implementation))
46
+
-**Source Middleware is just a light API wrapper around a "Before" type plugin Plugin**
47
+
- Source Middleware is the legacy API (pre-analytics next). It's less verbose than the full plugin API, but a bit less powerful. It is functionally equivalent to a "Before" type plugin.
48
+
49
+
-**Before Plugins** (see [Example](#example-plugin-implementation))
46
50
- Run before any other plugins
47
51
- Critical priority - block event pipeline until `.load()` resolves
48
52
- Use cases: Event validation, data transformation
49
53
- Example: Event validation before passing to other plugins)
50
-
51
-
A. **Source Middleware** (see [Example](#example-source-middleware-implementation))
52
-
-**Source Middleware is just a light API wrapper around a "Before" type plugin Plugin**
53
-
- Source Middleware is the legacy API (pre-analytics next). It's less verbose than the full plugin API, but a bit less powerful. It is functionally equivalent to a "Before" type plugin.
54
54
55
-
2.**Enrichment Plugins**
55
+
56
+
-**Enrichment Plugins**
56
57
- Functionally Identitical to "before" plugins, but run after them. Before plugins are typically used internally (e.g adding page info), but there's no hard and fast rule.
57
58
58
-
3.**Destination Plugins**
59
+
-**Destination Plugins**
59
60
- Run after enrichment
60
61
- Cannot modify the event
61
62
- Execute in parallel
62
63
- Failures do not halt pipeline
63
64
- Example: Segment.io, Google Analytics, Mixpanel
64
65
65
-
4.**After Plugins (uncommon)**
66
+
-**After Plugins (uncommon)**
66
67
- Run after all other plugins complete
67
68
- Use cases: Metrics, logging
68
69
- Example: segment.io plugin for observability metrics
69
70
70
-
5.**Utility Plugins**
71
+
-**Utility Plugins**
71
72
- Executes only once during the analytics.js bootstrap. Gives you access to the analytics instance using the plugin's load() method. This doesn't allow you to modify events.
72
73
- Do not directly process events
73
74
- Example: some plugin that registers a bunch of analytics event listeners (e.g. analytics.on('track', ...) and reports them to an external system)
75
+
76
+
-**Add Destination Middleware** (See [Example](#example-destination-middleware-implementation))
77
+
- A special type of plugin that allows you to add a plugin that only affects a specific (device mode) destination plugin.
78
+
74
79
75
80
### Example: Plugin Implementation
76
81
```ts
@@ -109,6 +114,23 @@ analytics.addSourceMiddleware(({ payload, next }) => {
0 commit comments