@walkeros/web-destination-api 0.4.1 → 0.5.0
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.
- package/README.md +119 -75
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/examples/index.js +23 -17
- package/dist/examples/index.mjs +23 -17
- package/dist/index.browser.js +1 -1
- package/dist/index.es5.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="left">
|
|
2
|
-
<a href="https://
|
|
3
|
-
<img title="elbwalker" src="https://www.
|
|
2
|
+
<a href="https://www.walkeros.io">
|
|
3
|
+
<img title="elbwalker" src="https://www.walkeros.io/img/elbwalker_logo.png" width="256px"/>
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
@@ -35,50 +35,83 @@ npm install @walkeros/web-destination-api
|
|
|
35
35
|
| `transform` | `function` | Function to transform event data before sending | No | `(data, config, mapping) => JSON.stringify(data)` |
|
|
36
36
|
| `transport` | `'fetch' \| 'xhr' \| 'beacon'` | Transport method for sending requests | No | `'fetch'` |
|
|
37
37
|
|
|
38
|
-
##
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
Configure in your Flow JSON:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"version": 1,
|
|
45
|
+
"flows": {
|
|
46
|
+
"default": {
|
|
47
|
+
"web": {},
|
|
48
|
+
"destinations": {
|
|
49
|
+
"api": {
|
|
50
|
+
"package": "@walkeros/web-destination-api",
|
|
51
|
+
"config": {
|
|
52
|
+
"settings": {
|
|
53
|
+
"url": "https://api.example.com/events",
|
|
54
|
+
"method": "POST",
|
|
55
|
+
"headers": { "Authorization": "Bearer your-token" }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
39
64
|
|
|
40
|
-
|
|
65
|
+
Or programmatically:
|
|
41
66
|
|
|
42
67
|
```typescript
|
|
43
68
|
import { startFlow } from '@walkeros/collector';
|
|
44
69
|
import { destinationAPI } from '@walkeros/web-destination-api';
|
|
45
70
|
|
|
46
|
-
const { elb } = await startFlow(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
const { elb } = await startFlow({
|
|
72
|
+
destinations: [
|
|
73
|
+
{
|
|
74
|
+
destination: destinationAPI,
|
|
75
|
+
config: {
|
|
76
|
+
settings: {
|
|
77
|
+
url: 'https://api.example.com/events',
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: { Authorization: 'Bearer your-token' },
|
|
80
|
+
},
|
|
81
|
+
},
|
|
55
82
|
},
|
|
56
|
-
|
|
83
|
+
],
|
|
57
84
|
});
|
|
58
85
|
```
|
|
59
86
|
|
|
87
|
+
## Usage
|
|
88
|
+
|
|
60
89
|
### Advanced Usage with Transform
|
|
61
90
|
|
|
62
91
|
```typescript
|
|
63
92
|
import { startFlow } from '@walkeros/collector';
|
|
64
93
|
import { destinationAPI } from '@walkeros/web-destination-api';
|
|
65
94
|
|
|
66
|
-
const { elb } = await startFlow(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
95
|
+
const { elb } = await startFlow({
|
|
96
|
+
destinations: [
|
|
97
|
+
{
|
|
98
|
+
destination: destinationAPI,
|
|
99
|
+
config: {
|
|
100
|
+
settings: {
|
|
101
|
+
url: 'https://api.example.com/events',
|
|
102
|
+
transport: 'fetch',
|
|
103
|
+
transform: (event, config, mapping) => {
|
|
104
|
+
return JSON.stringify({
|
|
105
|
+
timestamp: Date.now(),
|
|
106
|
+
event_name: `${event.entity}_${event.action}`,
|
|
107
|
+
properties: event.data,
|
|
108
|
+
context: event.context,
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
80
113
|
},
|
|
81
|
-
|
|
114
|
+
],
|
|
82
115
|
});
|
|
83
116
|
```
|
|
84
117
|
|
|
@@ -86,64 +119,66 @@ elb('walker destination', destinationAPI, {
|
|
|
86
119
|
|
|
87
120
|
### Sending to Analytics API
|
|
88
121
|
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
user_id: event.user?.id,
|
|
108
|
-
session_id: event.user?.session,
|
|
109
|
-
properties: event.data,
|
|
110
|
-
timestamp: event.timing,
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
});
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"destinations": {
|
|
125
|
+
"analytics": {
|
|
126
|
+
"package": "@walkeros/web-destination-api",
|
|
127
|
+
"config": {
|
|
128
|
+
"settings": {
|
|
129
|
+
"url": "https://analytics.example.com/track",
|
|
130
|
+
"method": "POST",
|
|
131
|
+
"headers": {
|
|
132
|
+
"Content-Type": "application/json",
|
|
133
|
+
"X-API-Key": "your-api-key"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
115
140
|
```
|
|
116
141
|
|
|
117
142
|
### Using Beacon Transport
|
|
118
143
|
|
|
119
144
|
For critical events that need to be sent even when the page is unloading:
|
|
120
145
|
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"destinations": {
|
|
149
|
+
"critical": {
|
|
150
|
+
"package": "@walkeros/web-destination-api",
|
|
151
|
+
"config": {
|
|
152
|
+
"settings": {
|
|
153
|
+
"url": "https://api.example.com/critical-events",
|
|
154
|
+
"transport": "beacon"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
128
160
|
```
|
|
129
161
|
|
|
130
162
|
### Custom Data Mapping
|
|
131
163
|
|
|
132
164
|
Use mapping rules to control which events are sent:
|
|
133
165
|
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"destinations": {
|
|
169
|
+
"api": {
|
|
170
|
+
"package": "@walkeros/web-destination-api",
|
|
171
|
+
"config": {
|
|
172
|
+
"settings": { "url": "https://api.example.com/events" },
|
|
173
|
+
"mapping": {
|
|
174
|
+
"entity": {
|
|
175
|
+
"action": { "data": "data" }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
147
182
|
```
|
|
148
183
|
|
|
149
184
|
## Transport Methods
|
|
@@ -153,6 +188,15 @@ elb('walker destination', destinationAPI, {
|
|
|
153
188
|
- **beacon**: Uses Navigator.sendBeacon() for reliable data transmission during
|
|
154
189
|
page unload
|
|
155
190
|
|
|
191
|
+
## Type Definitions
|
|
192
|
+
|
|
193
|
+
See [src/types/](./src/types/) for TypeScript interfaces.
|
|
194
|
+
|
|
195
|
+
## Related
|
|
196
|
+
|
|
197
|
+
- [Website Documentation](https://www.walkeros.io/docs/destinations/web/api/)
|
|
198
|
+
- [Destination Interface](../../../core/src/types/destination.ts)
|
|
199
|
+
|
|
156
200
|
## Contribute
|
|
157
201
|
|
|
158
202
|
Feel free to contribute by submitting an
|