@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thead-vantage/react",
3
- "version": "2.21.0",
3
+ "version": "2.22.0",
4
4
  "description": "React components and utilities for TheAd Vantage ad platform integration",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -129,18 +129,24 @@ export function AdBanner({
129
129
  } catch (err) {
130
130
  console.error('[AdBanner] Error fetching ad:', err);
131
131
 
132
- // For CORS errors, handle differently in development mode
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, don't show error - just log it and show a placeholder ad
136
- console.warn('[AdBanner] CORS error in development mode - this is expected. Tracking is disabled.');
137
- // Create a placeholder ad for development so the component still renders
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: 'dev-placeholder',
140
- name: 'Development Placeholder Ad',
145
+ id: 'thead-vantage-fallback',
146
+ name: 'TheAd Vantage',
141
147
  type: 'image',
142
- contentUrl: '/placeholder-ad.png',
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 placeholder ad for development
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: 'dev-placeholder',
164
- name: 'Development Placeholder Ad',
169
+ id: 'thead-vantage-fallback',
170
+ name: 'TheAd Vantage',
165
171
  type: 'image',
166
- contentUrl: '/placeholder-ad.png',
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