@thead-vantage/react 2.21.0 → 2.22.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/components/AdBanner.tsx +23 -17
- package/src/lib/ads.ts +26 -0
package/package.json
CHANGED
|
@@ -129,18 +129,24 @@ export function AdBanner({
|
|
|
129
129
|
} catch (err) {
|
|
130
130
|
console.error('[AdBanner] Error fetching ad:', err);
|
|
131
131
|
|
|
132
|
-
//
|
|
132
|
+
// Check if we're on localhost
|
|
133
|
+
const isLocalhost = typeof window !== 'undefined' &&
|
|
134
|
+
(window.location.hostname === 'localhost' ||
|
|
135
|
+
window.location.hostname === '127.0.0.1' ||
|
|
136
|
+
window.location.hostname === '[::1]');
|
|
137
|
+
|
|
138
|
+
// For CORS errors, handle differently in development mode or localhost
|
|
133
139
|
if (err instanceof Error && err.message.includes('CORS error')) {
|
|
134
|
-
if (development) {
|
|
135
|
-
// In development mode,
|
|
136
|
-
console.warn('[AdBanner] CORS error in development mode -
|
|
137
|
-
// Create a
|
|
140
|
+
if (development || isLocalhost) {
|
|
141
|
+
// In development mode or localhost, show TheAd Vantage logo as fallback ad
|
|
142
|
+
console.warn('[AdBanner] CORS error in development mode - showing TheAd Vantage fallback ad. Tracking is disabled.');
|
|
143
|
+
// Create a fallback ad with TheAd Vantage logo
|
|
138
144
|
setAd({
|
|
139
|
-
id: '
|
|
140
|
-
name: '
|
|
145
|
+
id: 'thead-vantage-fallback',
|
|
146
|
+
name: 'TheAd Vantage',
|
|
141
147
|
type: 'image',
|
|
142
|
-
contentUrl: '/
|
|
143
|
-
targetUrl: '
|
|
148
|
+
contentUrl: '/TheAd-Vantage-Logo.png',
|
|
149
|
+
targetUrl: 'https://www.thead-vantage.com',
|
|
144
150
|
width: 300,
|
|
145
151
|
height: 250,
|
|
146
152
|
});
|
|
@@ -155,16 +161,16 @@ export function AdBanner({
|
|
|
155
161
|
setError('Ad unavailable');
|
|
156
162
|
}
|
|
157
163
|
} else {
|
|
158
|
-
// For other errors, show the error message (unless in development)
|
|
159
|
-
if (development) {
|
|
160
|
-
console.warn('[AdBanner] Error in development mode:', err);
|
|
161
|
-
// Create a
|
|
164
|
+
// For other errors, show the error message (unless in development or localhost)
|
|
165
|
+
if (development || isLocalhost) {
|
|
166
|
+
console.warn('[AdBanner] Error in development mode - showing TheAd Vantage fallback ad:', err);
|
|
167
|
+
// Create a fallback ad with TheAd Vantage logo
|
|
162
168
|
setAd({
|
|
163
|
-
id: '
|
|
164
|
-
name: '
|
|
169
|
+
id: 'thead-vantage-fallback',
|
|
170
|
+
name: 'TheAd Vantage',
|
|
165
171
|
type: 'image',
|
|
166
|
-
contentUrl: '/
|
|
167
|
-
targetUrl: '
|
|
172
|
+
contentUrl: '/TheAd-Vantage-Logo.png',
|
|
173
|
+
targetUrl: 'https://www.thead-vantage.com',
|
|
168
174
|
width: 300,
|
|
169
175
|
height: 250,
|
|
170
176
|
});
|
package/src/lib/ads.ts
CHANGED
|
@@ -321,8 +321,34 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
321
321
|
message: data.message || 'No ads available in response',
|
|
322
322
|
};
|
|
323
323
|
} catch (error) {
|
|
324
|
+
// Check if we're on localhost (client-side only)
|
|
325
|
+
const isLocalhost = typeof window !== 'undefined' &&
|
|
326
|
+
(window.location.hostname === 'localhost' ||
|
|
327
|
+
window.location.hostname === '127.0.0.1' ||
|
|
328
|
+
window.location.hostname === '[::1]');
|
|
329
|
+
|
|
324
330
|
// Handle CORS errors specifically
|
|
325
331
|
if (error instanceof TypeError && (error.message.includes('CORS') || error.message.includes('Failed to fetch'))) {
|
|
332
|
+
// On localhost, return TheAd Vantage fallback ad instead of throwing
|
|
333
|
+
if (isLocalhost) {
|
|
334
|
+
console.warn('[AdBanner] CORS error on localhost - returning TheAd Vantage fallback ad. Tracking is disabled.');
|
|
335
|
+
return {
|
|
336
|
+
success: true,
|
|
337
|
+
dev_mode: true,
|
|
338
|
+
ad: {
|
|
339
|
+
id: 'thead-vantage-fallback',
|
|
340
|
+
name: 'TheAd Vantage',
|
|
341
|
+
type: 'image',
|
|
342
|
+
contentUrl: '/TheAd-Vantage-Logo.png',
|
|
343
|
+
targetUrl: 'https://www.thead-vantage.com',
|
|
344
|
+
width: 300,
|
|
345
|
+
height: 250,
|
|
346
|
+
},
|
|
347
|
+
message: 'Localhost development: Using TheAd Vantage fallback ad due to CORS',
|
|
348
|
+
_dev_note: 'CORS error on localhost - showing fallback ad. This is expected in development.',
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
326
352
|
// Check if this might be a 308 redirect issue
|
|
327
353
|
// Vercel redirects thead-vantage.com → www.thead-vantage.com at edge level
|
|
328
354
|
// This breaks CORS preflight because browsers don't allow redirects on OPTIONS requests
|