@thead-vantage/react 2.12.0 → 2.13.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/package.json +1 -1
- package/src/lib/ads.ts +34 -2
package/package.json
CHANGED
package/src/lib/ads.ts
CHANGED
|
@@ -378,6 +378,15 @@ export async function trackImpression(adId: string): Promise<void> {
|
|
|
378
378
|
trackingUrl = trackingUrl.replace(/\/$/, '') + '/api/ads/track';
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
// Normalize URL to HTTPS and ensure www (avoid 308 redirects)
|
|
382
|
+
if (trackingUrl.startsWith('http://')) {
|
|
383
|
+
trackingUrl = trackingUrl.replace('http://', 'https://');
|
|
384
|
+
}
|
|
385
|
+
// Ensure www to avoid redirects
|
|
386
|
+
if (trackingUrl.includes('thead-vantage.com') && !trackingUrl.includes('www.')) {
|
|
387
|
+
trackingUrl = trackingUrl.replace('thead-vantage.com', 'www.thead-vantage.com');
|
|
388
|
+
}
|
|
389
|
+
|
|
381
390
|
// Check if we should skip tracking (dev mode)
|
|
382
391
|
const useDevFlags = shouldUseDevFlags();
|
|
383
392
|
if (useDevFlags) {
|
|
@@ -387,6 +396,8 @@ export async function trackImpression(adId: string): Promise<void> {
|
|
|
387
396
|
|
|
388
397
|
const response = await fetch(trackingUrl, {
|
|
389
398
|
method: 'POST',
|
|
399
|
+
mode: 'cors', // Explicitly enable CORS
|
|
400
|
+
credentials: 'omit', // Don't send cookies
|
|
390
401
|
headers: {
|
|
391
402
|
'Content-Type': 'application/json',
|
|
392
403
|
'Accept': 'application/json',
|
|
@@ -407,7 +418,12 @@ export async function trackImpression(adId: string): Promise<void> {
|
|
|
407
418
|
console.log(`[DEV] Impression tracking skipped for ad: ${adId}`);
|
|
408
419
|
}
|
|
409
420
|
} catch (error) {
|
|
410
|
-
|
|
421
|
+
// Handle CORS errors silently (tracking failures shouldn't break the app)
|
|
422
|
+
if (error instanceof TypeError && (error.message.includes('CORS') || error.message.includes('Failed to fetch'))) {
|
|
423
|
+
console.warn(`[AdBanner] CORS error tracking impression for ad: ${adId}. The tracking endpoint needs CORS headers configured.`);
|
|
424
|
+
} else {
|
|
425
|
+
console.error('Error tracking impression:', error);
|
|
426
|
+
}
|
|
411
427
|
// Don't throw - tracking failures shouldn't break the app
|
|
412
428
|
}
|
|
413
429
|
}
|
|
@@ -430,6 +446,15 @@ export async function trackClick(adId: string): Promise<void> {
|
|
|
430
446
|
trackingUrl = trackingUrl.replace(/\/$/, '') + '/api/ads/track';
|
|
431
447
|
}
|
|
432
448
|
|
|
449
|
+
// Normalize URL to HTTPS and ensure www (avoid 308 redirects)
|
|
450
|
+
if (trackingUrl.startsWith('http://')) {
|
|
451
|
+
trackingUrl = trackingUrl.replace('http://', 'https://');
|
|
452
|
+
}
|
|
453
|
+
// Ensure www to avoid redirects
|
|
454
|
+
if (trackingUrl.includes('thead-vantage.com') && !trackingUrl.includes('www.')) {
|
|
455
|
+
trackingUrl = trackingUrl.replace('thead-vantage.com', 'www.thead-vantage.com');
|
|
456
|
+
}
|
|
457
|
+
|
|
433
458
|
// Check if we should skip tracking (dev mode)
|
|
434
459
|
const useDevFlags = shouldUseDevFlags();
|
|
435
460
|
if (useDevFlags) {
|
|
@@ -439,6 +464,8 @@ export async function trackClick(adId: string): Promise<void> {
|
|
|
439
464
|
|
|
440
465
|
const response = await fetch(trackingUrl, {
|
|
441
466
|
method: 'POST',
|
|
467
|
+
mode: 'cors', // Explicitly enable CORS
|
|
468
|
+
credentials: 'omit', // Don't send cookies
|
|
442
469
|
headers: {
|
|
443
470
|
'Content-Type': 'application/json',
|
|
444
471
|
'Accept': 'application/json',
|
|
@@ -459,7 +486,12 @@ export async function trackClick(adId: string): Promise<void> {
|
|
|
459
486
|
console.log(`[DEV] Click tracking skipped for ad: ${adId}`);
|
|
460
487
|
}
|
|
461
488
|
} catch (error) {
|
|
462
|
-
|
|
489
|
+
// Handle CORS errors silently (tracking failures shouldn't break the app)
|
|
490
|
+
if (error instanceof TypeError && (error.message.includes('CORS') || error.message.includes('Failed to fetch'))) {
|
|
491
|
+
console.warn(`[AdBanner] CORS error tracking click for ad: ${adId}. The tracking endpoint needs CORS headers configured.`);
|
|
492
|
+
} else {
|
|
493
|
+
console.error('Error tracking click:', error);
|
|
494
|
+
}
|
|
463
495
|
// Don't throw - tracking failures shouldn't break the app
|
|
464
496
|
}
|
|
465
497
|
}
|