@chordcommerce/analytics 1.17.0 → 1.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +40 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -110,6 +110,46 @@ export const cartFormatter: CartFormatter<StorefrontCart> = (props) => {
110
110
  }
111
111
  ```
112
112
 
113
+ addSourceMiddleware(func: AnalyticsMiddleware)
114
+
115
+ Registers a middleware function to modify event properties before they are
116
+ sent to analytics providers. Middleware functions are executed
117
+ synchronously in the order they were added during event tracking.
118
+
119
+ Parameters
120
+
121
+ - func (AnalyticsMiddleware) - A middleware function that receives event
122
+ data and can return additional properties to merge into the event payload.
123
+
124
+ Return Value
125
+
126
+ The middleware function can return:
127
+
128
+ - Partial<EventProperties> - Properties to merge into the event payload
129
+ - void - No additional properties to add
130
+
131
+ Useage Example
132
+
133
+ ```
134
+ analytics.addSourceMiddleware(({ payload }) => {
135
+ const { searchParams } = payload.obj.context.page;
136
+
137
+ return {
138
+ utm_source: searchParams.utm_source,
139
+ utm_medium: searchParams.utm_medium,
140
+ utm_campaign: searchParams.utm_campaign
141
+ };
142
+ });
143
+
144
+ analytics.addSourceMiddleware(({ payload }) => {
145
+ return {
146
+ session_id: getSessionId(),
147
+ user_agent: navigator.userAgent,
148
+ timestamp: Date.now()
149
+ };
150
+ });
151
+ ```
152
+
113
153
  ## API Reference
114
154
 
115
155
  See [Chord’s documentation](https://docs.chord.co/api-reference) for a full API reference.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chordcommerce/analytics",
3
3
  "description": "Chord Commerce event tracking",
4
- "version": "1.17.0",
4
+ "version": "1.17.1",
5
5
  "author": "Chord Commerce <help@chord.co> (https://www.chord.co)",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",