@upeex/ads-sdk 1.1.6 → 1.1.7
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/dist/index.js +65 -75
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40,98 +40,82 @@ async function getSignals() {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
async function fetchAd({ baseUrl, client, slot, display = 'BANNER', debug = false, }) {
|
|
43
|
+
const log = (...args) => {
|
|
44
|
+
if (debug)
|
|
45
|
+
console.log('[UPEEX ADS]', ...args);
|
|
46
|
+
};
|
|
43
47
|
const signals = await getSignals();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
// 1️⃣ chama o make
|
|
48
|
-
const res = await fetch(`${baseUrl}/make/mobile`, {
|
|
48
|
+
log('signals', signals);
|
|
49
|
+
// 1️⃣ MAKE
|
|
50
|
+
const makeRes = await fetch(`${baseUrl}/ad/make/mobile`, {
|
|
49
51
|
method: 'POST',
|
|
50
52
|
headers: { 'Content-Type': 'application/json' },
|
|
51
53
|
body: JSON.stringify({
|
|
52
54
|
client,
|
|
53
55
|
slot,
|
|
54
56
|
display,
|
|
55
|
-
isMobile: signals.platform !== 'web' ? 1 : 0,
|
|
56
57
|
...signals,
|
|
57
58
|
}),
|
|
58
59
|
});
|
|
59
|
-
if (!
|
|
60
|
-
|
|
61
|
-
console.error('[ADS] make error:', res.status);
|
|
60
|
+
if (!makeRes.ok) {
|
|
61
|
+
log('Erro no make', makeRes.status);
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
// 2️⃣ faz GET nessa URL
|
|
70
|
-
const adRes = await fetch(showUrl);
|
|
71
|
-
if (!adRes.ok) {
|
|
72
|
-
if (debug)
|
|
73
|
-
console.error('[ADS] show error:', adRes.status);
|
|
64
|
+
const makeData = await makeRes.json();
|
|
65
|
+
log('make response', makeData);
|
|
66
|
+
if (!makeData.url) {
|
|
67
|
+
log('make não retornou url');
|
|
74
68
|
return null;
|
|
75
69
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
// 2️⃣ SHOW
|
|
71
|
+
log('fazendo fetch do showUrl', makeData.url);
|
|
72
|
+
const showRes = await fetch(makeData.url);
|
|
73
|
+
if (!showRes.ok) {
|
|
74
|
+
log('Erro no show', showRes.status);
|
|
75
|
+
return null;
|
|
79
76
|
}
|
|
80
|
-
|
|
77
|
+
const ad = await showRes.json();
|
|
78
|
+
log('ad recebido', ad);
|
|
79
|
+
return ad;
|
|
81
80
|
}
|
|
82
81
|
|
|
83
|
-
function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br
|
|
82
|
+
function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br', theme = 'light', style = {}, debug = false, }) {
|
|
84
83
|
const [ad, setAd] = useState(null);
|
|
85
84
|
const [error, setError] = useState(null);
|
|
86
85
|
const log = (...args) => {
|
|
87
86
|
if (debug)
|
|
88
87
|
console.log('[UPEEX ADS]', ...args);
|
|
89
88
|
};
|
|
90
|
-
async function loadAd() {
|
|
91
|
-
try {
|
|
92
|
-
log('Carregando anúncio', { client, slot, baseUrl });
|
|
93
|
-
const data = await fetchAd({
|
|
94
|
-
baseUrl,
|
|
95
|
-
client,
|
|
96
|
-
slot,
|
|
97
|
-
debug,
|
|
98
|
-
});
|
|
99
|
-
log('Resposta do anúncio', data);
|
|
100
|
-
if (!(data === null || data === void 0 ? void 0 : data.image) || !(data === null || data === void 0 ? void 0 : data.clickUrl)) {
|
|
101
|
-
setError('Anúncio inválido ou vazio');
|
|
102
|
-
setAd(null);
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
setAd(data);
|
|
106
|
-
setError(null);
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
console.error('[UPEEX ADS] Erro ao carregar anúncio', err);
|
|
110
|
-
setError('Erro ao carregar anúncio');
|
|
111
|
-
setAd(null);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
89
|
useEffect(() => {
|
|
115
90
|
if (!client || !slot) {
|
|
116
91
|
log('client ou slot não informado');
|
|
117
92
|
return;
|
|
118
93
|
}
|
|
119
|
-
|
|
94
|
+
log('Carregando anúncio', { client, slot });
|
|
95
|
+
fetchAd({ baseUrl, client, slot, debug })
|
|
96
|
+
.then((data) => {
|
|
97
|
+
log('Anúncio recebido', data);
|
|
98
|
+
if (!data || !data.image) {
|
|
99
|
+
setError('Anúncio inválido');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
setAd(data);
|
|
103
|
+
})
|
|
104
|
+
.catch((err) => {
|
|
105
|
+
console.error('[UPEEX ADS] Erro', err);
|
|
106
|
+
setError('Erro ao carregar anúncio');
|
|
107
|
+
});
|
|
120
108
|
}, [client, slot, baseUrl]);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
log('Auto refresh em', ad.refresh, 'segundos');
|
|
126
|
-
const timer = setTimeout(loadAd, ad.refresh * 1000);
|
|
127
|
-
return () => clearTimeout(timer);
|
|
128
|
-
}, [ad === null || ad === void 0 ? void 0 : ad.refresh]);
|
|
129
|
-
// ❌ nada pra renderizar
|
|
109
|
+
if (error) {
|
|
110
|
+
return debug ? (jsx(View, { style: [styles.container, styles.debug], children: jsx(Text, { style: styles.debugText, children: error }) })) : null;
|
|
111
|
+
}
|
|
130
112
|
if (!ad) {
|
|
131
|
-
return debug ? (jsx(View, { style:
|
|
113
|
+
return debug ? (jsx(View, { style: styles.loading, children: jsx(Text, { style: styles.loadingText, children: "Carregando an\u00FAncio\u2026" }) })) : null;
|
|
132
114
|
}
|
|
133
115
|
const handlePress = () => {
|
|
134
116
|
log('Clique no anúncio', ad.clickUrl);
|
|
117
|
+
if (!ad.clickUrl)
|
|
118
|
+
return;
|
|
135
119
|
if (Platform.OS === 'web') {
|
|
136
120
|
window.open(ad.clickUrl, '_blank');
|
|
137
121
|
}
|
|
@@ -139,38 +123,44 @@ function AdBanner({ client, slot, baseUrl = 'https://app.upeex.com.br/ad', theme
|
|
|
139
123
|
Linking.openURL(ad.clickUrl);
|
|
140
124
|
}
|
|
141
125
|
};
|
|
142
|
-
return (jsxs(TouchableOpacity, { activeOpacity: 0.9, onPress: handlePress, style: [
|
|
143
|
-
styles.container,
|
|
144
|
-
theme === 'dark' && styles.dark,
|
|
145
|
-
style,
|
|
146
|
-
], children: [jsx(Image, { source: { uri: ad.image }, style: {
|
|
126
|
+
return (jsxs(TouchableOpacity, { activeOpacity: 0.9, onPress: handlePress, style: [styles.container, theme === 'dark' && styles.dark, style], children: [jsx(Text, { style: [styles.label, theme === 'dark' && styles.darkText], children: "Publicidade" }), jsx(Image, { source: { uri: ad.image }, style: {
|
|
147
127
|
width: ad.width || 320,
|
|
148
128
|
height: ad.height || 50,
|
|
149
|
-
|
|
129
|
+
resizeMode: 'contain',
|
|
130
|
+
} })] }));
|
|
150
131
|
}
|
|
151
132
|
const styles = StyleSheet.create({
|
|
152
133
|
container: {
|
|
153
134
|
alignItems: 'center',
|
|
154
|
-
|
|
135
|
+
paddingVertical: 6,
|
|
155
136
|
backgroundColor: '#f2f2f2',
|
|
156
|
-
paddingVertical: 4,
|
|
157
137
|
},
|
|
158
138
|
dark: {
|
|
159
139
|
backgroundColor: '#121212',
|
|
160
140
|
},
|
|
161
|
-
|
|
141
|
+
label: {
|
|
142
|
+
fontSize: 10,
|
|
143
|
+
color: '#666',
|
|
144
|
+
marginBottom: 4,
|
|
145
|
+
},
|
|
146
|
+
darkText: {
|
|
147
|
+
color: '#aaa',
|
|
148
|
+
},
|
|
149
|
+
loading: {
|
|
162
150
|
padding: 10,
|
|
163
|
-
|
|
151
|
+
alignItems: 'center',
|
|
152
|
+
},
|
|
153
|
+
loadingText: {
|
|
154
|
+
fontSize: 11,
|
|
155
|
+
color: '#999',
|
|
156
|
+
},
|
|
157
|
+
debug: {
|
|
158
|
+
backgroundColor: '#ffecec',
|
|
159
|
+
padding: 8,
|
|
164
160
|
},
|
|
165
161
|
debugText: {
|
|
166
162
|
fontSize: 11,
|
|
167
163
|
color: '#c00',
|
|
168
|
-
textAlign: 'center',
|
|
169
|
-
},
|
|
170
|
-
debugInfo: {
|
|
171
|
-
marginTop: 4,
|
|
172
|
-
fontSize: 9,
|
|
173
|
-
color: '#888',
|
|
174
164
|
},
|
|
175
165
|
});
|
|
176
166
|
|