@thead-vantage/react 2.3.0 → 2.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 +114 -31
- package/package.json +1 -1
- package/src/components/AdBanner.tsx +1 -1
- package/src/components/AdDisplay.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/lib/ads.ts +20 -6
- package/src/lib/thead-vantage-config.ts +57 -10
package/README.md
CHANGED
|
@@ -22,20 +22,20 @@ This project uses [`next/font`](https://nextjs.org/docs/app/building-your-applic
|
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
25
|
-
## TheAd Vantage Integration -
|
|
25
|
+
## TheAd Vantage Integration - Development Modes
|
|
26
26
|
|
|
27
|
-
The TheAd Vantage integration supports
|
|
27
|
+
The TheAd Vantage integration supports multiple modes of operation to accommodate different development and production scenarios:
|
|
28
28
|
|
|
29
29
|
### 1. Production Mode (Default)
|
|
30
30
|
|
|
31
|
-
**Use Case**: Platform developers using the component in production
|
|
31
|
+
**Use Case**: Platform developers using the component in production deployments.
|
|
32
32
|
|
|
33
33
|
**Behavior**:
|
|
34
|
-
- Connects to `https://thead-vantage.com/api/ads`
|
|
34
|
+
- Connects to `https://thead-vantage.com/api/ads`
|
|
35
35
|
- Full tracking enabled (impressions and clicks are recorded)
|
|
36
36
|
- No configuration required
|
|
37
37
|
|
|
38
|
-
**Configuration**: None needed - this is the default behavior.
|
|
38
|
+
**Configuration**: None needed - this is the default behavior for production deployments.
|
|
39
39
|
|
|
40
40
|
**Example Usage**:
|
|
41
41
|
```tsx
|
|
@@ -52,9 +52,26 @@ export default function MyPage() {
|
|
|
52
52
|
}
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
### 2.
|
|
55
|
+
### 2. Localhost Development Mode (Automatic)
|
|
56
56
|
|
|
57
|
-
**Use Case**: Platform developers testing locally
|
|
57
|
+
**Use Case**: Platform developers testing locally on `localhost` (any port).
|
|
58
|
+
|
|
59
|
+
**Behavior**:
|
|
60
|
+
- **Automatically detected** when running on `localhost` (e.g., `localhost:3000`, `localhost:3001`, etc.)
|
|
61
|
+
- Connects to `https://thead-vantage.com/api/ads` (production API)
|
|
62
|
+
- **Dev flags automatically added**: `dev_mode=true`, `no_track=true`, `no_click_track=true`
|
|
63
|
+
- **No tracking**: Impressions and clicks are NOT recorded (prevents polluting production data)
|
|
64
|
+
- Perfect for platform developers testing locally without affecting production metrics
|
|
65
|
+
|
|
66
|
+
**Configuration**: **No configuration needed!** The library automatically detects localhost and adds dev flags.
|
|
67
|
+
|
|
68
|
+
**Note**: This mode is automatically used when:
|
|
69
|
+
- Running on `localhost` or `127.0.0.1` (any port)
|
|
70
|
+
- AND `NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE` is NOT set to `true`
|
|
71
|
+
|
|
72
|
+
### 3. Platform Developer Custom API Mode
|
|
73
|
+
|
|
74
|
+
**Use Case**: Platform developers testing with their own custom platform instance.
|
|
58
75
|
|
|
59
76
|
**Behavior**:
|
|
60
77
|
- Connects to a custom API URL (your platform's API endpoint)
|
|
@@ -86,12 +103,12 @@ NEXT_PUBLIC_THEAD_VANTAGE_API_URL=https://your-platform.com/api/ads
|
|
|
86
103
|
/>
|
|
87
104
|
```
|
|
88
105
|
|
|
89
|
-
###
|
|
106
|
+
### 4. TheAd Vantage Dev Mode
|
|
90
107
|
|
|
91
|
-
**Use Case**: TheAd Vantage developers testing the component with a local platform instance
|
|
108
|
+
**Use Case**: TheAd Vantage developers testing the component with a local platform instance running on `localhost:3001`.
|
|
92
109
|
|
|
93
110
|
**Behavior**:
|
|
94
|
-
- Connects to `http://localhost:3001/api/ads`
|
|
111
|
+
- Connects to `http://localhost:3001/api/ads` (local TheAd Vantage platform)
|
|
95
112
|
- Tracking disabled (impressions and clicks are NOT recorded)
|
|
96
113
|
- Returns mock data if local platform is unavailable
|
|
97
114
|
- Shows dev mode indicators in the UI
|
|
@@ -113,6 +130,8 @@ NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true
|
|
|
113
130
|
/>
|
|
114
131
|
```
|
|
115
132
|
|
|
133
|
+
**Important**: This mode **overrides** localhost detection. When `NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true`, the library will always use `localhost:3001` instead of the production API, even if you're running on localhost.
|
|
134
|
+
|
|
116
135
|
---
|
|
117
136
|
|
|
118
137
|
## Component API
|
|
@@ -187,9 +206,13 @@ trackClick(adId);
|
|
|
187
206
|
|
|
188
207
|
### For Platform Developers
|
|
189
208
|
|
|
209
|
+
**No environment variables needed for localhost development!** The library automatically detects localhost and uses the production API with dev flags (no tracking).
|
|
210
|
+
|
|
211
|
+
**Optional**: If you want to test with a custom platform instance:
|
|
212
|
+
|
|
190
213
|
```env
|
|
191
214
|
# .env.local
|
|
192
|
-
#
|
|
215
|
+
# Point to your own platform instance (full tracking enabled)
|
|
193
216
|
NEXT_PUBLIC_THEAD_VANTAGE_API_URL=https://your-platform.com/api/ads
|
|
194
217
|
```
|
|
195
218
|
|
|
@@ -198,14 +221,25 @@ NEXT_PUBLIC_THEAD_VANTAGE_API_URL=https://your-platform.com/api/ads
|
|
|
198
221
|
```env
|
|
199
222
|
# .env.local
|
|
200
223
|
# Enable TheAd Vantage dev mode (uses localhost:3001, disables tracking)
|
|
224
|
+
# This overrides localhost detection and always uses localhost:3001
|
|
201
225
|
NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true
|
|
202
226
|
```
|
|
203
227
|
|
|
228
|
+
### Summary Table
|
|
229
|
+
|
|
230
|
+
| Scenario | API Endpoint | Tracking | Configuration |
|
|
231
|
+
|----------|-------------|----------|--------------|
|
|
232
|
+
| Production deployment | `https://thead-vantage.com/api/ads` | ✅ Enabled | None (default) |
|
|
233
|
+
| Platform dev on localhost | `https://thead-vantage.com/api/ads` | ❌ Disabled (dev flags) | None (auto-detected) |
|
|
234
|
+
| Custom platform URL | Custom URL | ✅ Enabled | `NEXT_PUBLIC_THEAD_VANTAGE_API_URL` |
|
|
235
|
+
| TheAd Vantage dev | `localhost:3001/api/ads` | ❌ Disabled | `NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true` |
|
|
236
|
+
|
|
204
237
|
**Priority Order** (highest to lowest):
|
|
205
|
-
1. Explicit `apiUrl` prop in component
|
|
206
|
-
2.
|
|
207
|
-
3.
|
|
208
|
-
4.
|
|
238
|
+
1. **Explicit `apiUrl` prop** in component (highest priority)
|
|
239
|
+
2. **`NEXT_PUBLIC_THEAD_VANTAGE_API_URL`** environment variable (custom platform)
|
|
240
|
+
3. **`NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true`** → uses `localhost:3001` (TheAd Vantage developers)
|
|
241
|
+
4. **Localhost detection** → uses `https://thead-vantage.com/api/ads` with dev flags (platform developers on localhost)
|
|
242
|
+
5. **Production mode** (default: `https://thead-vantage.com/api/ads` with full tracking)
|
|
209
243
|
|
|
210
244
|
---
|
|
211
245
|
|
|
@@ -226,8 +260,20 @@ The integration includes Next.js API routes that proxy requests to TheAd Vantage
|
|
|
226
260
|
|
|
227
261
|
## Development Mode Features
|
|
228
262
|
|
|
229
|
-
|
|
263
|
+
### Localhost Development (Automatic)
|
|
264
|
+
|
|
265
|
+
When running on **localhost** (any port, without `NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true`):
|
|
266
|
+
|
|
267
|
+
- ✅ **Production API**: Connects to `https://thead-vantage.com/api/ads`
|
|
268
|
+
- ✅ **No Tracking**: Dev flags automatically added (`dev_mode=true`, `no_track=true`, `no_click_track=true`)
|
|
269
|
+
- ✅ **Real Ads**: Gets real ads from production (but doesn't record impressions/clicks)
|
|
270
|
+
- ✅ **No Configuration**: Automatically detected - no setup needed!
|
|
271
|
+
|
|
272
|
+
### TheAd Vantage Dev Mode
|
|
230
273
|
|
|
274
|
+
When **`NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true`**:
|
|
275
|
+
|
|
276
|
+
- ✅ **Local API**: Connects to `http://localhost:3001/api/ads`
|
|
231
277
|
- ✅ **No Tracking**: Impressions and clicks are NOT recorded
|
|
232
278
|
- ✅ **Mock Fallback**: If localhost:3001 is unavailable, uses mock ad data
|
|
233
279
|
- ✅ **Dev Indicators**: UI shows "[DEV] No tracking active" message
|
|
@@ -261,11 +307,12 @@ Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/bui
|
|
|
261
307
|
|
|
262
308
|
## System Architecture
|
|
263
309
|
|
|
264
|
-
The TheAd Vantage integration uses a
|
|
310
|
+
The TheAd Vantage integration uses a smart mode detection system to support different development scenarios:
|
|
265
311
|
|
|
266
|
-
1. **Production Mode**: Default behavior, connects to `https://thead-vantage.com/api/ads`
|
|
267
|
-
2. **
|
|
268
|
-
3. **
|
|
312
|
+
1. **Production Mode**: Default behavior, connects to `https://thead-vantage.com/api/ads` with full tracking
|
|
313
|
+
2. **Localhost Development**: Automatically detected, uses `https://thead-vantage.com/api/ads` with dev flags (no tracking)
|
|
314
|
+
3. **Custom Platform Mode**: Custom API URL via `NEXT_PUBLIC_THEAD_VANTAGE_API_URL` env var
|
|
315
|
+
4. **TheAd Vantage Dev Mode**: Local development via `NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true` env var → uses `localhost:3001`
|
|
269
316
|
|
|
270
317
|
## Key Files and Their Purposes
|
|
271
318
|
|
|
@@ -332,9 +379,16 @@ The TheAd Vantage integration uses a three-mode system to support different deve
|
|
|
332
379
|
The system uses this priority order to determine which API URL to use:
|
|
333
380
|
|
|
334
381
|
1. **Explicit `apiUrl` prop** (highest priority) - passed directly to component
|
|
335
|
-
2. **`NEXT_PUBLIC_THEAD_VANTAGE_API_URL` env var** - for platform developers
|
|
336
|
-
3. **`NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true`** - for TheAd Vantage developers (uses localhost:3001)
|
|
337
|
-
4. **
|
|
382
|
+
2. **`NEXT_PUBLIC_THEAD_VANTAGE_API_URL` env var** - for platform developers using custom platform
|
|
383
|
+
3. **`NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true`** - for TheAd Vantage developers (uses `localhost:3001`)
|
|
384
|
+
4. **Localhost detection** - automatically uses `https://thead-vantage.com/api/ads` with dev flags (no tracking)
|
|
385
|
+
5. **Production mode** (lowest priority) - default: `https://thead-vantage.com/api/ads` with full tracking
|
|
386
|
+
|
|
387
|
+
**Key Points for AI Agents**:
|
|
388
|
+
- Localhost is automatically detected by checking `window.location.hostname` (browser) or `NODE_ENV === 'development'` (server)
|
|
389
|
+
- When on localhost, dev flags (`dev_mode`, `no_track`, `no_click_track`) are automatically added to requests
|
|
390
|
+
- TheAd Vantage dev mode (`NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true`) **overrides** localhost detection
|
|
391
|
+
- Platform developers on localhost get real ads from production but don't pollute tracking data
|
|
338
392
|
|
|
339
393
|
### Common Patterns
|
|
340
394
|
|
|
@@ -384,11 +438,13 @@ const response = await fetchAdBanner({
|
|
|
384
438
|
|
|
385
439
|
When implementing or modifying TheAd Vantage integration:
|
|
386
440
|
|
|
387
|
-
- [ ] Verify production mode connects to https://thead-vantage.com/api/ads
|
|
441
|
+
- [ ] Verify production mode connects to `https://thead-vantage.com/api/ads` with full tracking
|
|
442
|
+
- [ ] Verify localhost detection automatically uses production API with dev flags (no tracking)
|
|
388
443
|
- [ ] Verify platform dev mode respects `NEXT_PUBLIC_THEAD_VANTAGE_API_URL`
|
|
389
|
-
- [ ] Verify TheAd Vantage dev mode uses localhost:3001 when flag is set
|
|
444
|
+
- [ ] Verify TheAd Vantage dev mode uses `localhost:3001` when flag is set (overrides localhost detection)
|
|
445
|
+
- [ ] Verify tracking is disabled when on localhost (dev flags added automatically)
|
|
390
446
|
- [ ] Verify tracking is disabled in TheAd Vantage dev mode
|
|
391
|
-
- [ ] Verify mock data is returned when platform is unavailable in dev mode
|
|
447
|
+
- [ ] Verify mock data is returned when platform is unavailable in TheAd Vantage dev mode
|
|
392
448
|
- [ ] Verify explicit `apiUrl` prop overrides all other settings
|
|
393
449
|
- [ ] Verify component handles loading states correctly
|
|
394
450
|
- [ ] Verify component handles error states gracefully
|
|
@@ -418,12 +474,39 @@ All types are exported from `@/lib/ads` and `@/components/AdBanner`.
|
|
|
418
474
|
|
|
419
475
|
## Quick Reference
|
|
420
476
|
|
|
421
|
-
|
|
477
|
+
### For Platform Developers
|
|
478
|
+
|
|
479
|
+
**Default Behavior**:
|
|
480
|
+
- Production: Connects to `https://thead-vantage.com/api/ads` with full tracking
|
|
481
|
+
- Localhost: Automatically uses `https://thead-vantage.com/api/ads` with dev flags (no tracking) - **no configuration needed!**
|
|
482
|
+
|
|
483
|
+
**Optional Custom Platform**: Add `NEXT_PUBLIC_THEAD_VANTAGE_API_URL` to `.env.local` if testing with custom platform
|
|
484
|
+
|
|
485
|
+
**Component Import**:
|
|
486
|
+
```tsx
|
|
487
|
+
import { AdBanner } from '@thead-vantage/react';
|
|
488
|
+
// or
|
|
489
|
+
import { AdBanner } from '@thead-vantage/react/components/AdBanner';
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
**Utility Import**:
|
|
493
|
+
```tsx
|
|
494
|
+
import { fetchAdBanner, trackImpression, trackClick } from '@thead-vantage/react';
|
|
495
|
+
// or
|
|
496
|
+
import { fetchAdBanner, trackImpression, trackClick } from '@thead-vantage/react/lib/ads';
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### For TheAd Vantage Developers
|
|
422
500
|
|
|
423
|
-
**
|
|
501
|
+
**Setup**: Add `NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true` to `.env.local`
|
|
424
502
|
|
|
425
|
-
**
|
|
503
|
+
**Behavior**: Uses `localhost:3001/api/ads` (overrides localhost detection)
|
|
426
504
|
|
|
427
|
-
|
|
505
|
+
### Common Scenarios
|
|
428
506
|
|
|
429
|
-
|
|
507
|
+
| You Are | Running On | API Used | Tracking | Config Needed |
|
|
508
|
+
|---------|-----------|----------|----------|---------------|
|
|
509
|
+
| Platform Developer | Production | `thead-vantage.com` | ✅ Yes | None |
|
|
510
|
+
| Platform Developer | `localhost:3000` | `thead-vantage.com` | ❌ No (dev flags) | None (auto) |
|
|
511
|
+
| Platform Developer | Custom platform | Custom URL | ✅ Yes | `NEXT_PUBLIC_THEAD_VANTAGE_API_URL` |
|
|
512
|
+
| TheAd Vantage Dev | `localhost:3000` | `localhost:3001` | ❌ No | `NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true` |
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import Image from 'next/image';
|
|
5
|
-
import { fetchAdBanner, trackImpression, trackClick, type Ad } from '
|
|
5
|
+
import { fetchAdBanner, trackImpression, trackClick, type Ad } from '../lib/ads';
|
|
6
6
|
|
|
7
7
|
export interface AdBannerProps {
|
|
8
8
|
platformId: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import Image from 'next/image';
|
|
5
|
-
import { fetchAds, trackImpression, trackClick, type AdData } from '
|
|
5
|
+
import { fetchAds, trackImpression, trackClick, type AdData } from '../lib/ads';
|
|
6
6
|
|
|
7
7
|
interface AdDisplayProps {
|
|
8
8
|
position?: string;
|
package/src/index.ts
CHANGED
package/src/lib/ads.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Automatically handles development mode to prevent tracking
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getApiBaseUrl } from './thead-vantage-config';
|
|
6
|
+
import { getApiBaseUrl, shouldUseDevFlags } from './thead-vantage-config';
|
|
7
7
|
|
|
8
8
|
export interface AdData {
|
|
9
9
|
id: string;
|
|
@@ -113,12 +113,25 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
113
113
|
searchParams.append('user_segment', params.userSegment);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
// Get the API base URL (handles dev mode, production, custom URLs)
|
|
117
|
+
const apiBaseUrl = getApiBaseUrl(params.apiUrl);
|
|
118
|
+
|
|
119
|
+
// Add dev flags if we're in development (localhost but not TheAd Vantage dev mode)
|
|
120
|
+
// This prevents tracking when platform developers test locally
|
|
121
|
+
if (shouldUseDevFlags()) {
|
|
122
|
+
searchParams.set('dev_mode', 'true');
|
|
123
|
+
searchParams.set('no_track', 'true'); // Prevent impression tracking
|
|
124
|
+
searchParams.set('no_click_track', 'true'); // Prevent click tracking
|
|
119
125
|
}
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
|
|
127
|
+
// Build the full URL - if apiBaseUrl already includes /api/ads, use it directly
|
|
128
|
+
// Otherwise append /api/ads
|
|
129
|
+
let fullApiUrl = apiBaseUrl;
|
|
130
|
+
if (!fullApiUrl.includes('/api/ads')) {
|
|
131
|
+
fullApiUrl = fullApiUrl.replace(/\/$/, '') + '/api/ads';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const url = `${fullApiUrl}?${searchParams.toString()}`;
|
|
122
135
|
|
|
123
136
|
// Log the request (without exposing the API key)
|
|
124
137
|
const logUrl = url.replace(new RegExp(`api_key=${params.apiKey}`, 'g'), 'api_key=***');
|
|
@@ -128,6 +141,7 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
128
141
|
method: 'GET',
|
|
129
142
|
headers: {
|
|
130
143
|
'Content-Type': 'application/json',
|
|
144
|
+
'Accept': 'application/json',
|
|
131
145
|
},
|
|
132
146
|
});
|
|
133
147
|
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TheAd Vantage Configuration Utility
|
|
3
3
|
*
|
|
4
|
-
* Handles
|
|
5
|
-
* 1. Production Mode (default) - hits https://thead-vantage.com/api/ads
|
|
4
|
+
* Handles distinct modes of operation:
|
|
5
|
+
* 1. Production Mode (default) - hits https://thead-vantage.com/api/ads with full tracking
|
|
6
6
|
* 2. Platform Developer Dev Mode - custom API URL via env var or prop
|
|
7
|
-
* 3. TheAd Vantage Dev Mode - localhost:3001 for TheAd Vantage developers
|
|
7
|
+
* 3. TheAd Vantage Dev Mode - localhost:3001 for TheAd Vantage developers (NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true)
|
|
8
|
+
* 4. Localhost Development - hits https://thead-vantage.com/api/ads but with dev flags (no tracking)
|
|
8
9
|
*/
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Check if we're running on localhost (any port)
|
|
13
|
+
*/
|
|
14
|
+
function isLocalhost(): boolean {
|
|
15
|
+
if (typeof window !== 'undefined') {
|
|
16
|
+
const hostname = window.location.hostname;
|
|
17
|
+
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
|
|
18
|
+
}
|
|
19
|
+
// Server-side: check if we're in development mode
|
|
20
|
+
return process.env.NODE_ENV === 'development';
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
/**
|
|
11
24
|
* Get the base API URL based on the current configuration
|
|
12
25
|
*
|
|
13
26
|
* Priority order:
|
|
14
27
|
* 1. Explicit API URL override (passed as parameter)
|
|
15
28
|
* 2. NEXT_PUBLIC_THEAD_VANTAGE_API_URL environment variable
|
|
16
|
-
* 3. TheAd Vantage dev mode (NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true)
|
|
17
|
-
* 4.
|
|
29
|
+
* 3. TheAd Vantage dev mode (NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE=true) → localhost:3001
|
|
30
|
+
* 4. Localhost detection → https://thead-vantage.com (with dev flags, no tracking)
|
|
31
|
+
* 5. Production mode (default) → https://thead-vantage.com (full tracking)
|
|
18
32
|
*/
|
|
19
33
|
export function getApiBaseUrl(explicitApiUrl?: string): string {
|
|
20
34
|
// Priority 1: Explicit API URL override (highest priority)
|
|
@@ -39,18 +53,24 @@ export function getApiBaseUrl(explicitApiUrl?: string): string {
|
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
// Priority 3: TheAd Vantage dev mode
|
|
42
|
-
// Only for TheAd Vantage developers testing locally
|
|
43
|
-
const
|
|
56
|
+
// Only for TheAd Vantage developers testing locally with localhost:3001
|
|
57
|
+
const isTheadVantageDevMode = typeof window !== 'undefined'
|
|
44
58
|
? (window as any).__THEAD_VANTAGE_DEV_MODE__ === true ||
|
|
45
59
|
process.env.NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE === 'true'
|
|
46
60
|
: process.env.NEXT_PUBLIC_THEAD_VANTAGE_DEV_MODE === 'true';
|
|
47
61
|
|
|
48
|
-
if (
|
|
62
|
+
if (isTheadVantageDevMode) {
|
|
49
63
|
return 'http://localhost:3001/api/ads';
|
|
50
64
|
}
|
|
51
65
|
|
|
52
|
-
// Priority 4:
|
|
53
|
-
//
|
|
66
|
+
// Priority 4: Localhost development (platform developers on localhost)
|
|
67
|
+
// Use production API but will add dev flags to prevent tracking
|
|
68
|
+
if (isLocalhost()) {
|
|
69
|
+
return 'https://thead-vantage.com/api/ads';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Priority 5: Production mode (default)
|
|
73
|
+
// Platform developers use this by default in production
|
|
54
74
|
return 'https://thead-vantage.com/api/ads';
|
|
55
75
|
}
|
|
56
76
|
|
|
@@ -72,6 +92,33 @@ export function isDevelopmentMode(): boolean {
|
|
|
72
92
|
return process.env.NODE_ENV === 'development';
|
|
73
93
|
}
|
|
74
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Check if we should use dev flags (no tracking) even when hitting production API
|
|
97
|
+
* This is true when:
|
|
98
|
+
* - Running on localhost (platform developers testing locally)
|
|
99
|
+
* - OR in TheAd Vantage dev mode
|
|
100
|
+
* - OR in general development mode
|
|
101
|
+
*/
|
|
102
|
+
export function shouldUseDevFlags(): boolean {
|
|
103
|
+
// TheAd Vantage dev mode always uses dev flags
|
|
104
|
+
if (isTheadVantageDevMode()) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// If on localhost (but not TheAd Vantage dev mode), use dev flags
|
|
109
|
+
// This means platform developers testing locally won't record impressions
|
|
110
|
+
if (isLocalhost()) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// General development mode
|
|
115
|
+
if (isDevelopmentMode()) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
75
122
|
/**
|
|
76
123
|
* Runtime configuration interface
|
|
77
124
|
*/
|