@mixpeek/prebid 1.0.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/CHANGELOG.md +153 -0
- package/ENDPOINTS.md +308 -0
- package/LICENSE +68 -0
- package/QUICKSTART.md +234 -0
- package/README.md +439 -0
- package/TESTING.md +341 -0
- package/dist/mixpeekContextAdapter.js +3 -0
- package/dist/mixpeekContextAdapter.js.LICENSE.txt +1 -0
- package/dist/mixpeekContextAdapter.js.map +1 -0
- package/docs/MIGRATION_V2.md +519 -0
- package/docs/api-reference.md +455 -0
- package/docs/health-check.md +348 -0
- package/docs/integration-guide.md +577 -0
- package/examples/publisher-demo/README.md +65 -0
- package/examples/publisher-demo/index.html +331 -0
- package/examples/publisher-demo/package.json +11 -0
- package/package.json +82 -0
- package/src/api/mixpeekClient.js +303 -0
- package/src/cache/cacheManager.js +245 -0
- package/src/config/constants.js +125 -0
- package/src/extractors/imageExtractor.js +142 -0
- package/src/extractors/pageExtractor.js +196 -0
- package/src/extractors/videoExtractor.js +228 -0
- package/src/modules/mixpeekContextAdapter.js +833 -0
- package/src/modules/mixpeekRtdProvider.js +305 -0
- package/src/prebid/prebidIntegration.js +117 -0
- package/src/utils/helpers.js +261 -0
- package/src/utils/iabMapping.js +367 -0
- package/src/utils/logger.js +64 -0
- package/src/utils/previousAdTracker.js +95 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
# Health Check Configuration
|
|
2
|
+
|
|
3
|
+
The Mixpeek Context Adapter includes configurable health check functionality to validate API connectivity and credentials.
|
|
4
|
+
|
|
5
|
+
## Health Check Modes
|
|
6
|
+
|
|
7
|
+
### 1. Lazy Health Check (Default - Recommended)
|
|
8
|
+
|
|
9
|
+
Performs health check on the **first context request** rather than initialization.
|
|
10
|
+
|
|
11
|
+
**Pros:**
|
|
12
|
+
- ✅ No page load impact
|
|
13
|
+
- ✅ Validates API before first real use
|
|
14
|
+
- ✅ Catches issues early but not too early
|
|
15
|
+
- ✅ Best for production
|
|
16
|
+
|
|
17
|
+
**Configuration:**
|
|
18
|
+
```javascript
|
|
19
|
+
pbjs.setConfig({
|
|
20
|
+
mixpeek: {
|
|
21
|
+
apiKey: 'YOUR_API_KEY',
|
|
22
|
+
collectionId: 'YOUR_COLLECTION_ID',
|
|
23
|
+
healthCheck: 'lazy' // Default
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Behavior:**
|
|
29
|
+
```
|
|
30
|
+
Page Load
|
|
31
|
+
↓
|
|
32
|
+
Prebid Init
|
|
33
|
+
↓
|
|
34
|
+
Mixpeek Init (fast, no API call)
|
|
35
|
+
↓
|
|
36
|
+
First Bid Request
|
|
37
|
+
↓
|
|
38
|
+
Health Check → Context Request → Enriched Bid
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. Eager Health Check
|
|
42
|
+
|
|
43
|
+
Performs health check **immediately during initialization**.
|
|
44
|
+
|
|
45
|
+
**Pros:**
|
|
46
|
+
- ✅ Validates connectivity early
|
|
47
|
+
- ✅ Fail fast if API is down
|
|
48
|
+
- ✅ Good for debugging
|
|
49
|
+
|
|
50
|
+
**Cons:**
|
|
51
|
+
- ⚠️ Adds ~200-500ms to initialization
|
|
52
|
+
- ⚠️ Extra HTTP request on every page load
|
|
53
|
+
- ⚠️ May impact page load metrics
|
|
54
|
+
|
|
55
|
+
**Configuration:**
|
|
56
|
+
```javascript
|
|
57
|
+
pbjs.setConfig({
|
|
58
|
+
mixpeek: {
|
|
59
|
+
apiKey: 'YOUR_API_KEY',
|
|
60
|
+
collectionId: 'YOUR_COLLECTION_ID',
|
|
61
|
+
healthCheck: 'eager'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Use When:**
|
|
67
|
+
- Testing and debugging
|
|
68
|
+
- Development environment
|
|
69
|
+
- You need immediate validation
|
|
70
|
+
|
|
71
|
+
### 3. No Health Check
|
|
72
|
+
|
|
73
|
+
Skips health check entirely.
|
|
74
|
+
|
|
75
|
+
**Pros:**
|
|
76
|
+
- ✅ Minimal overhead
|
|
77
|
+
- ✅ Fastest initialization
|
|
78
|
+
|
|
79
|
+
**Cons:**
|
|
80
|
+
- ⚠️ No early warning of API issues
|
|
81
|
+
- ⚠️ Errors only caught during enrichment
|
|
82
|
+
|
|
83
|
+
**Configuration:**
|
|
84
|
+
```javascript
|
|
85
|
+
pbjs.setConfig({
|
|
86
|
+
mixpeek: {
|
|
87
|
+
apiKey: 'YOUR_API_KEY',
|
|
88
|
+
collectionId: 'YOUR_COLLECTION_ID',
|
|
89
|
+
healthCheck: false
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Use When:**
|
|
95
|
+
- Maximum performance is critical
|
|
96
|
+
- You have external monitoring
|
|
97
|
+
- API reliability is guaranteed
|
|
98
|
+
|
|
99
|
+
## Health Check Response
|
|
100
|
+
|
|
101
|
+
### Success
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
{
|
|
105
|
+
healthy: true,
|
|
106
|
+
status: 'ok',
|
|
107
|
+
version: '0.81',
|
|
108
|
+
latency: 234, // milliseconds
|
|
109
|
+
message: 'API responding in 234ms'
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Failure
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
{
|
|
117
|
+
healthy: false,
|
|
118
|
+
error: 'Network error: ECONNREFUSED',
|
|
119
|
+
message: 'API health check failed'
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Monitoring Health Checks
|
|
124
|
+
|
|
125
|
+
### Listen to Health Check Events
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
pbjs.onEvent('mixpeekHealthCheck', function(result) {
|
|
129
|
+
if (result.healthy) {
|
|
130
|
+
console.log('✅ Mixpeek API healthy:', result.latency + 'ms');
|
|
131
|
+
|
|
132
|
+
// Send to analytics
|
|
133
|
+
gtag('event', 'mixpeek_health', {
|
|
134
|
+
status: 'healthy',
|
|
135
|
+
latency: result.latency,
|
|
136
|
+
version: result.version
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
console.error('❌ Mixpeek API unhealthy:', result.error);
|
|
140
|
+
|
|
141
|
+
// Alert monitoring system
|
|
142
|
+
reportError('mixpeek_health_failed', result.error);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Check Health Status Manually
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
// After initialization
|
|
151
|
+
const health = await window.MixpeekContextAdapter.healthCheck();
|
|
152
|
+
|
|
153
|
+
if (health.status === 'ok') {
|
|
154
|
+
console.log('API is healthy');
|
|
155
|
+
} else {
|
|
156
|
+
console.error('API is unhealthy:', health);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Recommended Configuration by Environment
|
|
161
|
+
|
|
162
|
+
### Development
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
pbjs.setConfig({
|
|
166
|
+
mixpeek: {
|
|
167
|
+
endpoint: 'https://server-xb24.onrender.com',
|
|
168
|
+
healthCheck: 'eager', // Validate immediately
|
|
169
|
+
debug: true,
|
|
170
|
+
timeout: 5000
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Staging
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
pbjs.setConfig({
|
|
179
|
+
mixpeek: {
|
|
180
|
+
endpoint: 'https://server-xb24.onrender.com',
|
|
181
|
+
healthCheck: 'lazy', // Balance validation & performance
|
|
182
|
+
debug: true,
|
|
183
|
+
timeout: 3000
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Production
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
pbjs.setConfig({
|
|
192
|
+
mixpeek: {
|
|
193
|
+
endpoint: 'https://api.mixpeek.com',
|
|
194
|
+
healthCheck: 'lazy', // Recommended
|
|
195
|
+
debug: false,
|
|
196
|
+
timeout: 250
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### High-Performance Production
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
pbjs.setConfig({
|
|
205
|
+
mixpeek: {
|
|
206
|
+
endpoint: 'https://api.mixpeek.com',
|
|
207
|
+
healthCheck: false, // Skip for max performance
|
|
208
|
+
debug: false,
|
|
209
|
+
timeout: 250
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Performance Impact
|
|
215
|
+
|
|
216
|
+
| Mode | Init Time | First Request | Subsequent Requests |
|
|
217
|
+
|------|-----------|---------------|---------------------|
|
|
218
|
+
| `false` | +0ms | +0ms | +0ms |
|
|
219
|
+
| `lazy` | +0ms | +200-500ms (once) | +0ms |
|
|
220
|
+
| `eager` | +200-500ms | +0ms | +0ms |
|
|
221
|
+
|
|
222
|
+
**Note:** Health check latency varies by endpoint:
|
|
223
|
+
- Production API: ~200-300ms
|
|
224
|
+
- Development server: ~400-800ms
|
|
225
|
+
- Local server: ~10-50ms
|
|
226
|
+
|
|
227
|
+
## Error Handling
|
|
228
|
+
|
|
229
|
+
Health check failures **do not block** the adapter:
|
|
230
|
+
|
|
231
|
+
```javascript
|
|
232
|
+
// Even if health check fails, adapter continues
|
|
233
|
+
pbjs.setConfig({
|
|
234
|
+
mixpeek: {
|
|
235
|
+
healthCheck: 'eager'
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// If API is down:
|
|
240
|
+
// 1. Health check logs warning
|
|
241
|
+
// 2. Initialization completes successfully
|
|
242
|
+
// 3. First context request will fail gracefully
|
|
243
|
+
// 4. Ad auction proceeds without enrichment
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
This ensures **resilient behavior** where API issues never break your ads.
|
|
247
|
+
|
|
248
|
+
## Debugging Health Issues
|
|
249
|
+
|
|
250
|
+
### Check Network
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# Test endpoint manually
|
|
254
|
+
curl https://server-xb24.onrender.com/v1/health
|
|
255
|
+
|
|
256
|
+
# With authentication
|
|
257
|
+
curl -H "Authorization: Bearer YOUR_API_KEY" \
|
|
258
|
+
https://server-xb24.onrender.com/v1/health
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Enable Debug Logging
|
|
262
|
+
|
|
263
|
+
```javascript
|
|
264
|
+
pbjs.setConfig({
|
|
265
|
+
mixpeek: {
|
|
266
|
+
healthCheck: 'eager',
|
|
267
|
+
debug: true // Shows detailed health check logs
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Console output:
|
|
273
|
+
```
|
|
274
|
+
[mixpeek] Performing health check...
|
|
275
|
+
[mixpeek] API Request: GET https://server-xb24.onrender.com/v1/health
|
|
276
|
+
[mixpeek] API Response: { status: 200, ... }
|
|
277
|
+
[mixpeek] Health check passed: API responding in 234ms
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Monitor in Production
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
// Track health check metrics
|
|
284
|
+
let healthChecks = {
|
|
285
|
+
passed: 0,
|
|
286
|
+
failed: 0,
|
|
287
|
+
totalLatency: 0
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
pbjs.onEvent('mixpeekHealthCheck', function(result) {
|
|
291
|
+
if (result.healthy) {
|
|
292
|
+
healthChecks.passed++;
|
|
293
|
+
healthChecks.totalLatency += result.latency;
|
|
294
|
+
} else {
|
|
295
|
+
healthChecks.failed++;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// Report to analytics every 100 checks
|
|
299
|
+
if ((healthChecks.passed + healthChecks.failed) % 100 === 0) {
|
|
300
|
+
const avgLatency = healthChecks.totalLatency / healthChecks.passed;
|
|
301
|
+
const successRate = healthChecks.passed / (healthChecks.passed + healthChecks.failed);
|
|
302
|
+
|
|
303
|
+
analytics.track('mixpeek_health_stats', {
|
|
304
|
+
success_rate: successRate,
|
|
305
|
+
avg_latency: avgLatency,
|
|
306
|
+
total_checks: healthChecks.passed + healthChecks.failed
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Best Practices
|
|
313
|
+
|
|
314
|
+
1. **Use `lazy` in production** - Best balance of validation and performance
|
|
315
|
+
2. **Use `eager` in development** - Immediate feedback on configuration issues
|
|
316
|
+
3. **Monitor health events** - Track API reliability in production
|
|
317
|
+
4. **Set appropriate timeouts** - Higher for dev servers, lower for production
|
|
318
|
+
5. **Have fallback behavior** - Never let health checks block your ads
|
|
319
|
+
|
|
320
|
+
## FAQ
|
|
321
|
+
|
|
322
|
+
### Q: Will health checks slow down my page?
|
|
323
|
+
|
|
324
|
+
**A:** With `lazy` mode (default), health checks add **0ms to page load** and ~200-500ms to the first bid request only. Subsequent requests use cache.
|
|
325
|
+
|
|
326
|
+
### Q: What if the health check fails?
|
|
327
|
+
|
|
328
|
+
**A:** The adapter continues to work. The first context enrichment will fail gracefully, and your ad auction proceeds without contextual data. The adapter will retry on subsequent requests.
|
|
329
|
+
|
|
330
|
+
### Q: Should I use health checks in production?
|
|
331
|
+
|
|
332
|
+
**A:** Yes, use `lazy` mode. It provides early warning of API issues with minimal performance impact.
|
|
333
|
+
|
|
334
|
+
### Q: Can I disable health checks completely?
|
|
335
|
+
|
|
336
|
+
**A:** Yes, set `healthCheck: false`. This is safe if you have external monitoring and prioritize maximum performance.
|
|
337
|
+
|
|
338
|
+
### Q: How do I test if health checks are working?
|
|
339
|
+
|
|
340
|
+
**A:** Enable debug mode and check console logs, or listen to `mixpeekHealthCheck` events.
|
|
341
|
+
|
|
342
|
+
## Related
|
|
343
|
+
|
|
344
|
+
- [Configuration Options](../README.md#configuration-options)
|
|
345
|
+
- [API Reference](api-reference.md)
|
|
346
|
+
- [Error Handling](integration-guide.md#error-handling)
|
|
347
|
+
- [Performance Optimization](integration-guide.md#performance)
|
|
348
|
+
|