@thead-vantage/react 2.1.3 → 2.3.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 +30 -1
- package/src/lib/ads.ts +32 -3
package/package.json
CHANGED
|
@@ -43,14 +43,43 @@ export function AdBanner({
|
|
|
43
43
|
userSegment,
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
console.log('[AdBanner] Processed response:', {
|
|
47
|
+
success: response.success,
|
|
48
|
+
hasAd: !!response.ad,
|
|
49
|
+
devMode: response.dev_mode,
|
|
50
|
+
message: response.message,
|
|
51
|
+
_dev_note: response._dev_note,
|
|
52
|
+
fullResponse: response,
|
|
53
|
+
});
|
|
54
|
+
|
|
46
55
|
if (response.success && response.ad) {
|
|
56
|
+
console.log('[AdBanner] Setting ad:', response.ad);
|
|
47
57
|
setAd(response.ad);
|
|
48
58
|
setDevMode(response.dev_mode || false);
|
|
49
59
|
|
|
50
60
|
// Track impression (will be skipped in dev mode)
|
|
51
61
|
trackImpression(response.ad.id);
|
|
52
62
|
} else {
|
|
53
|
-
|
|
63
|
+
// Create a more detailed error message
|
|
64
|
+
const errorDetails = [];
|
|
65
|
+
if (!response.success) errorDetails.push('API returned success=false');
|
|
66
|
+
if (!response.ad) errorDetails.push('No ad object in response');
|
|
67
|
+
if (response.message) errorDetails.push(`Message: ${response.message}`);
|
|
68
|
+
if (response._dev_note) errorDetails.push(`Note: ${response._dev_note}`);
|
|
69
|
+
|
|
70
|
+
const errorMsg = errorDetails.length > 0
|
|
71
|
+
? `No ads available: ${errorDetails.join(', ')}`
|
|
72
|
+
: 'No ads available';
|
|
73
|
+
|
|
74
|
+
console.error('[AdBanner] No ad available - Full details:', {
|
|
75
|
+
success: response.success,
|
|
76
|
+
hasAd: !!response.ad,
|
|
77
|
+
message: response.message,
|
|
78
|
+
_dev_note: response._dev_note,
|
|
79
|
+
fullResponse: response,
|
|
80
|
+
errorDetails,
|
|
81
|
+
});
|
|
82
|
+
setError(errorMsg);
|
|
54
83
|
}
|
|
55
84
|
} catch (err) {
|
|
56
85
|
console.error('[AdBanner] Error fetching ad:', err);
|
package/src/lib/ads.ts
CHANGED
|
@@ -137,6 +137,19 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
137
137
|
|
|
138
138
|
const data: AdsResponse = await response.json();
|
|
139
139
|
|
|
140
|
+
// Debug logging - log the FULL response to see exactly what we're getting
|
|
141
|
+
console.log('[AdBanner] Full API Response:', JSON.stringify(data, null, 2));
|
|
142
|
+
console.log('[AdBanner] API Response Summary:', {
|
|
143
|
+
success: data.success,
|
|
144
|
+
hasAd: !!data.ad,
|
|
145
|
+
hasAds: !!(data.ads && Array.isArray(data.ads)),
|
|
146
|
+
adsLength: Array.isArray(data.ads) ? data.ads.length : 0,
|
|
147
|
+
message: data.message,
|
|
148
|
+
dataKeys: Object.keys(data),
|
|
149
|
+
adType: data.ad ? typeof data.ad : 'none',
|
|
150
|
+
adsType: data.ads ? (Array.isArray(data.ads) ? 'array' : typeof data.ads) : 'none',
|
|
151
|
+
});
|
|
152
|
+
|
|
140
153
|
// Type guard to check if an object is Ad type (for arrays that might contain either)
|
|
141
154
|
const isAd = (obj: unknown): obj is Ad => {
|
|
142
155
|
if (typeof obj !== 'object' || obj === null) return false;
|
|
@@ -160,11 +173,15 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
160
173
|
if (data.ads && Array.isArray(data.ads) && data.ads.length > 0) {
|
|
161
174
|
// If we get an array, use the first ad and ensure it's Ad type
|
|
162
175
|
const firstAd = data.ads[0];
|
|
176
|
+
console.log('[AdBanner] Processing ads array, first ad:', JSON.stringify(firstAd, null, 2));
|
|
177
|
+
|
|
163
178
|
// Check if it's already an Ad, otherwise convert from AdData
|
|
164
179
|
const ad: Ad = isAd(firstAd)
|
|
165
180
|
? firstAd
|
|
166
181
|
: convertToAd(firstAd as AdData);
|
|
167
182
|
|
|
183
|
+
console.log('[AdBanner] Converted ad:', JSON.stringify(ad, null, 2));
|
|
184
|
+
|
|
168
185
|
return {
|
|
169
186
|
success: data.success,
|
|
170
187
|
ad,
|
|
@@ -177,7 +194,9 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
177
194
|
// Handle single ad response - convert AdData to Ad
|
|
178
195
|
// Since data.ad is typed as AdData, we always convert it
|
|
179
196
|
if (data.ad) {
|
|
197
|
+
console.log('[AdBanner] Processing single ad:', JSON.stringify(data.ad, null, 2));
|
|
180
198
|
const ad: Ad = convertToAd(data.ad);
|
|
199
|
+
console.log('[AdBanner] Converted ad:', JSON.stringify(ad, null, 2));
|
|
181
200
|
|
|
182
201
|
return {
|
|
183
202
|
success: data.success,
|
|
@@ -188,11 +207,21 @@ export async function fetchAdBanner(params: FetchAdBannerParams): Promise<AdBann
|
|
|
188
207
|
};
|
|
189
208
|
}
|
|
190
209
|
|
|
191
|
-
|
|
210
|
+
// No ad found - log detailed info
|
|
211
|
+
console.warn('[AdBanner] No ad found in response:', {
|
|
192
212
|
success: data.success,
|
|
193
|
-
|
|
194
|
-
|
|
213
|
+
hasAd: !!data.ad,
|
|
214
|
+
hasAds: !!(data.ads && Array.isArray(data.ads)),
|
|
215
|
+
adsLength: Array.isArray(data.ads) ? data.ads.length : 0,
|
|
195
216
|
message: data.message,
|
|
217
|
+
fullData: data,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
success: data.success || false,
|
|
222
|
+
dev_mode: data.dev_mode,
|
|
223
|
+
_dev_note: data._dev_note || 'No ad data in response',
|
|
224
|
+
message: data.message || 'No ads available in response',
|
|
196
225
|
};
|
|
197
226
|
} catch (error) {
|
|
198
227
|
console.error('[AdBanner] Error fetching ad:', error);
|