@thead-vantage/react 2.15.0 → 2.16.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 +12 -5
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/lib/ads.ts +55 -0
package/README.md
CHANGED
|
@@ -184,7 +184,7 @@ export default function ArticlePage() {
|
|
|
184
184
|
You can also use the utility functions directly:
|
|
185
185
|
|
|
186
186
|
```tsx
|
|
187
|
-
import { fetchAdBanner, trackImpression, trackClick } from '@/lib/ads';
|
|
187
|
+
import { fetchAdBanner, trackImpression, trackClick, collectFingerprint } from '@/lib/ads';
|
|
188
188
|
|
|
189
189
|
// Fetch an ad
|
|
190
190
|
const response = await fetchAdBanner({
|
|
@@ -196,8 +196,14 @@ const response = await fetchAdBanner({
|
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
// Track events (automatically skipped in TheAd Vantage dev mode)
|
|
199
|
-
trackImpression
|
|
200
|
-
|
|
199
|
+
// Note: trackImpression and trackClick now require apiKey parameter
|
|
200
|
+
// They automatically include client fingerprinting data for fraud detection
|
|
201
|
+
trackImpression(adId, apiKey);
|
|
202
|
+
trackClick(adId, apiKey);
|
|
203
|
+
|
|
204
|
+
// You can also collect fingerprint data manually if needed
|
|
205
|
+
const fingerprint = collectFingerprint();
|
|
206
|
+
console.log('Client fingerprint:', fingerprint);
|
|
201
207
|
```
|
|
202
208
|
|
|
203
209
|
---
|
|
@@ -335,8 +341,9 @@ The TheAd Vantage integration uses a smart mode detection system to support diff
|
|
|
335
341
|
### Utilities
|
|
336
342
|
- **`src/lib/ads.ts`**: Utility functions for fetching and tracking ads
|
|
337
343
|
- `fetchAdBanner(params)`: Fetches ads with full parameter support
|
|
338
|
-
- `trackImpression(adId)`: Tracks ad impressions (skipped in dev mode)
|
|
339
|
-
- `trackClick(adId)`: Tracks ad clicks (skipped in dev mode)
|
|
344
|
+
- `trackImpression(adId, apiKey, apiUrl?)`: Tracks ad impressions with fingerprinting (skipped in dev mode)
|
|
345
|
+
- `trackClick(adId, apiKey, apiUrl?)`: Tracks ad clicks with fingerprinting (skipped in dev mode)
|
|
346
|
+
- `collectFingerprint()`: Collects client fingerprinting data for fraud detection
|
|
340
347
|
|
|
341
348
|
## Implementation Instructions for AI Agents
|
|
342
349
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,11 +14,13 @@ export {
|
|
|
14
14
|
fetchAdBanner,
|
|
15
15
|
trackImpression,
|
|
16
16
|
trackClick,
|
|
17
|
+
collectFingerprint,
|
|
17
18
|
type Ad,
|
|
18
19
|
type AdData,
|
|
19
20
|
type AdsResponse,
|
|
20
21
|
type AdBannerResponse,
|
|
21
22
|
type FetchAdBannerParams,
|
|
23
|
+
type Fingerprint,
|
|
22
24
|
} from './lib/ads';
|
|
23
25
|
|
|
24
26
|
// Export configuration utilities
|
package/src/lib/ads.ts
CHANGED
|
@@ -360,9 +360,62 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Collect client fingerprinting data for fraud detection
|
|
365
|
+
* This data is used by the server to detect duplicate impressions, bot traffic, and fraudulent clicks
|
|
366
|
+
*/
|
|
367
|
+
export interface Fingerprint {
|
|
368
|
+
screenWidth: number | null;
|
|
369
|
+
screenHeight: number | null;
|
|
370
|
+
timezone: string | null;
|
|
371
|
+
language: string | null;
|
|
372
|
+
colorDepth: number | null;
|
|
373
|
+
platform: string | null;
|
|
374
|
+
cookiesEnabled: boolean | null;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function collectFingerprint(): Fingerprint {
|
|
378
|
+
// Only collect fingerprint in browser context
|
|
379
|
+
if (typeof window === 'undefined') {
|
|
380
|
+
return {
|
|
381
|
+
screenWidth: null,
|
|
382
|
+
screenHeight: null,
|
|
383
|
+
timezone: null,
|
|
384
|
+
language: null,
|
|
385
|
+
colorDepth: null,
|
|
386
|
+
platform: null,
|
|
387
|
+
cookiesEnabled: null,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
try {
|
|
392
|
+
return {
|
|
393
|
+
screenWidth: window.screen?.width ?? null,
|
|
394
|
+
screenHeight: window.screen?.height ?? null,
|
|
395
|
+
timezone: Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone ?? null,
|
|
396
|
+
language: navigator?.language ?? null,
|
|
397
|
+
colorDepth: window.screen?.colorDepth ?? null,
|
|
398
|
+
platform: navigator?.platform ?? null,
|
|
399
|
+
cookiesEnabled: navigator?.cookieEnabled ?? null,
|
|
400
|
+
};
|
|
401
|
+
} catch (error) {
|
|
402
|
+
console.warn('[AdBanner] Error collecting fingerprint:', error);
|
|
403
|
+
return {
|
|
404
|
+
screenWidth: null,
|
|
405
|
+
screenHeight: null,
|
|
406
|
+
timezone: null,
|
|
407
|
+
language: null,
|
|
408
|
+
colorDepth: null,
|
|
409
|
+
platform: null,
|
|
410
|
+
cookiesEnabled: null,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
363
415
|
/**
|
|
364
416
|
* Track an ad impression (when ad is viewed)
|
|
365
417
|
* Sends tracking directly to TheAd Vantage API (or skips in dev mode)
|
|
418
|
+
* Includes client fingerprinting data for fraud detection
|
|
366
419
|
*
|
|
367
420
|
* @param adId - The ID of the ad being tracked
|
|
368
421
|
* @param apiKey - The API key for the platform (required for CORS validation and platform identification)
|
|
@@ -418,6 +471,7 @@ export async function trackImpression(adId: string, apiKey: string, apiUrl?: str
|
|
|
418
471
|
body: JSON.stringify({
|
|
419
472
|
action: 'impression',
|
|
420
473
|
adId,
|
|
474
|
+
fingerprint: collectFingerprint(), // Include fingerprint data for fraud detection
|
|
421
475
|
}),
|
|
422
476
|
});
|
|
423
477
|
|
|
@@ -506,6 +560,7 @@ export async function trackClick(adId: string, apiKey: string, apiUrl?: string):
|
|
|
506
560
|
body: JSON.stringify({
|
|
507
561
|
action: 'click',
|
|
508
562
|
adId,
|
|
563
|
+
fingerprint: collectFingerprint(), // Include fingerprint data for fraud detection
|
|
509
564
|
}),
|
|
510
565
|
});
|
|
511
566
|
|