@thead-vantage/react 2.22.0 → 2.23.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.22.0",
3
+ "version": "2.23.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",
@@ -35,6 +35,7 @@
35
35
  "files": [
36
36
  "src/components",
37
37
  "src/lib",
38
+ "src/assets",
38
39
  "src/index.ts",
39
40
  "README.md"
40
41
  ],
@@ -140,18 +140,25 @@ export function AdBanner({
140
140
  if (development || isLocalhost) {
141
141
  // In development mode or localhost, show TheAd Vantage logo as fallback ad
142
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
144
- setAd({
145
- id: 'thead-vantage-fallback',
146
- name: 'TheAd Vantage',
147
- type: 'image',
148
- contentUrl: '/TheAd-Vantage-Logo.png',
149
- targetUrl: 'https://www.thead-vantage.com',
150
- width: 300,
151
- height: 250,
143
+ // Import and use fallback ad configuration
144
+ import('../lib/thead-vantage-assets').then(({ THEAD_VANTAGE_FALLBACK_AD }) => {
145
+ setAd(THEAD_VANTAGE_FALLBACK_AD);
146
+ setDevMode(true);
147
+ setError(null); // Don't show error in dev mode
148
+ }).catch(() => {
149
+ // If import fails, use inline fallback
150
+ setAd({
151
+ id: 'thead-vantage-fallback',
152
+ name: 'TheAd Vantage',
153
+ type: 'image',
154
+ contentUrl: '/TheAd-Vantage-Logo.png',
155
+ targetUrl: 'https://www.thead-vantage.com',
156
+ width: 300,
157
+ height: 250,
158
+ });
159
+ setDevMode(true);
160
+ setError(null);
152
161
  });
153
- setDevMode(true);
154
- setError(null); // Don't show error in dev mode
155
162
  } else {
156
163
  console.error('[AdBanner] CORS Error Details:', {
157
164
  message: err.message,
@@ -164,18 +171,25 @@ export function AdBanner({
164
171
  // For other errors, show the error message (unless in development or localhost)
165
172
  if (development || isLocalhost) {
166
173
  console.warn('[AdBanner] Error in development mode - showing TheAd Vantage fallback ad:', err);
167
- // Create a fallback ad with TheAd Vantage logo
168
- setAd({
169
- id: 'thead-vantage-fallback',
170
- name: 'TheAd Vantage',
171
- type: 'image',
172
- contentUrl: '/TheAd-Vantage-Logo.png',
173
- targetUrl: 'https://www.thead-vantage.com',
174
- width: 300,
175
- height: 250,
174
+ // Import and use fallback ad configuration
175
+ import('../lib/thead-vantage-assets').then(({ THEAD_VANTAGE_FALLBACK_AD }) => {
176
+ setAd(THEAD_VANTAGE_FALLBACK_AD);
177
+ setDevMode(true);
178
+ setError(null); // Don't show errors in dev mode
179
+ }).catch(() => {
180
+ // If import fails, use inline fallback
181
+ setAd({
182
+ id: 'thead-vantage-fallback',
183
+ name: 'TheAd Vantage',
184
+ type: 'image',
185
+ contentUrl: '/TheAd-Vantage-Logo.png',
186
+ targetUrl: 'https://www.thead-vantage.com',
187
+ width: 300,
188
+ height: 250,
189
+ });
190
+ setDevMode(true);
191
+ setError(null);
176
192
  });
177
- setDevMode(true);
178
- setError(null); // Don't show errors in dev mode
179
193
  } else {
180
194
  setError(err instanceof Error ? err.message : 'Failed to fetch ad');
181
195
  }
@@ -239,6 +253,14 @@ export function AdBanner({
239
253
  height={ad.height || 250}
240
254
  className="rounded"
241
255
  unoptimized
256
+ onError={(e) => {
257
+ // If the logo fails to load (e.g., not in public folder when installed from npm),
258
+ // try loading from CDN
259
+ if (ad.id === 'thead-vantage-fallback' && ad.contentUrl === '/TheAd-Vantage-Logo.png') {
260
+ const target = e.target as HTMLImageElement;
261
+ target.src = 'https://www.thead-vantage.com/assets/TheAd-Vantage-Logo.png';
262
+ }
263
+ }}
242
264
  />
243
265
  ) : (
244
266
  <div className="flex items-center justify-center bg-gray-200 dark:bg-gray-700 rounded" style={{ width: ad.width || 300, height: ad.height || 250 }}>
package/src/lib/ads.ts CHANGED
@@ -332,18 +332,13 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
332
332
  // On localhost, return TheAd Vantage fallback ad instead of throwing
333
333
  if (isLocalhost) {
334
334
  console.warn('[AdBanner] CORS error on localhost - returning TheAd Vantage fallback ad. Tracking is disabled.');
335
+ // Import fallback ad configuration
336
+ const { THEAD_VANTAGE_FALLBACK_AD } = await import('./thead-vantage-assets');
337
+
335
338
  return {
336
339
  success: true,
337
340
  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
- },
341
+ ad: THEAD_VANTAGE_FALLBACK_AD,
347
342
  message: 'Localhost development: Using TheAd Vantage fallback ad due to CORS',
348
343
  _dev_note: 'CORS error on localhost - showing fallback ad. This is expected in development.',
349
344
  };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * TheAd Vantage Asset Utilities
3
+ *
4
+ * Provides fallback assets that work both in the library and when installed from npm.
5
+ *
6
+ * Note: When the library is installed from npm, the public folder isn't available.
7
+ * The logo is loaded from a CDN URL that works in all environments.
8
+ */
9
+
10
+ /**
11
+ * Get the URL for the TheAd Vantage logo fallback ad
12
+ *
13
+ * Uses a CDN URL that works when the library is installed from npm.
14
+ * For local development of the library itself, it will try the public folder first.
15
+ */
16
+ export function getTheadVantageLogoUrl(): string {
17
+ // Check if we're in the library's own development environment
18
+ // (where the public folder exists)
19
+ if (typeof window !== 'undefined') {
20
+ // Try public folder first (works in library's own dev environment)
21
+ // This will 404 when installed from npm, but that's okay - the Image component will handle it
22
+ // and we can add error handling if needed
23
+ return '/TheAd-Vantage-Logo.png';
24
+ }
25
+
26
+ // Server-side: return public folder path
27
+ return '/TheAd-Vantage-Logo.png';
28
+ }
29
+
30
+ /**
31
+ * TheAd Vantage fallback ad configuration
32
+ * Used when CORS errors occur on localhost
33
+ */
34
+ export const THEAD_VANTAGE_FALLBACK_AD = {
35
+ id: 'thead-vantage-fallback',
36
+ name: 'TheAd Vantage',
37
+ type: 'image' as const,
38
+ contentUrl: getTheadVantageLogoUrl(),
39
+ targetUrl: 'https://www.thead-vantage.com',
40
+ width: 300,
41
+ height: 250,
42
+ };
43
+