@upeex/ads-sdk 0.1.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/README.md +24 -0
- package/dist/AdBanner.d.ts +4 -0
- package/dist/core.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +90 -0
- package/dist/signals.d.ts +9 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
## Uso
|
|
3
|
+
|
|
4
|
+
### Componente AdBanner
|
|
5
|
+
|
|
6
|
+
function App() {
|
|
7
|
+
return (
|
|
8
|
+
<View>
|
|
9
|
+
{/* ... */}
|
|
10
|
+
<AdBanner client="SEU_CLIENTE" slot="SEU_SLOT" />
|
|
11
|
+
</View>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Funções
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { loadAd, countView } from '@upeex/ads-sdk';
|
|
20
|
+
|
|
21
|
+
// Carregar anúncio
|
|
22
|
+
const ad = await loadAd('CLIENTE', 'SLOT');
|
|
23
|
+
|
|
24
|
+
|
package/dist/core.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as AdBanner } from './AdBanner';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { StyleSheet, AppState, View, Text, TouchableOpacity, Image, Linking } from 'react-native';
|
|
4
|
+
|
|
5
|
+
async function getSignals() {
|
|
6
|
+
var _a;
|
|
7
|
+
let os;
|
|
8
|
+
let model;
|
|
9
|
+
let bundle = null;
|
|
10
|
+
// 🌍 Sempre disponível (JS puro)
|
|
11
|
+
const lang = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
12
|
+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
13
|
+
// 📱 Tenta Expo (se existir)
|
|
14
|
+
try {
|
|
15
|
+
const Device = await import('expo-device');
|
|
16
|
+
os = Device.osName;
|
|
17
|
+
model = Device.modelName;
|
|
18
|
+
}
|
|
19
|
+
catch (_b) {
|
|
20
|
+
// não é Expo, segue a vida
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const Application = await import('expo-application');
|
|
24
|
+
bundle = (_a = Application.applicationId) !== null && _a !== void 0 ? _a : null;
|
|
25
|
+
}
|
|
26
|
+
catch (_c) {
|
|
27
|
+
// não é Expo
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
os,
|
|
31
|
+
model,
|
|
32
|
+
bundle,
|
|
33
|
+
lang,
|
|
34
|
+
tz
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const BASE_URL = 'https://teste.hosthp.com.br/ads';
|
|
39
|
+
async function loadAd(client, slot) {
|
|
40
|
+
const signals = await getSignals();
|
|
41
|
+
const makeRes = await fetch(`${BASE_URL}/make/index.php`, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: { 'Content-Type': 'application/json' },
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
client,
|
|
46
|
+
slot,
|
|
47
|
+
platform: 'app',
|
|
48
|
+
signals
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
const makeData = await makeRes.json();
|
|
52
|
+
const showRes = await fetch(makeData.show_url);
|
|
53
|
+
return showRes.json();
|
|
54
|
+
}
|
|
55
|
+
function countView(token) {
|
|
56
|
+
fetch(`${BASE_URL}/count/view.php`, {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: { 'Content-Type': 'application/json' },
|
|
59
|
+
body: JSON.stringify({ token })
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function AdBanner({ client, slot }) {
|
|
64
|
+
const [ad, setAd] = useState(null);
|
|
65
|
+
const viewed = useRef(false);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
loadAd(client, slot).then(setAd);
|
|
68
|
+
}, []);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!(ad === null || ad === void 0 ? void 0 : ad.token))
|
|
71
|
+
return;
|
|
72
|
+
const t = setTimeout(() => {
|
|
73
|
+
if (!viewed.current && AppState.currentState === 'active') {
|
|
74
|
+
viewed.current = true;
|
|
75
|
+
countView(ad.token);
|
|
76
|
+
}
|
|
77
|
+
}, (ad.view_time || 5) * 1000);
|
|
78
|
+
return () => clearTimeout(t);
|
|
79
|
+
}, [ad]);
|
|
80
|
+
if (!ad)
|
|
81
|
+
return null;
|
|
82
|
+
return (jsxs(View, { style: styles.container, children: [jsx(Text, { style: styles.label, children: "Promovido" }), jsx(TouchableOpacity, { onPress: () => Linking.openURL(ad.click_url), children: jsx(Image, { source: { uri: ad.image }, style: styles.banner, resizeMode: "contain" }) })] }));
|
|
83
|
+
}
|
|
84
|
+
const styles = StyleSheet.create({
|
|
85
|
+
container: { width: '100%', alignItems: 'center', marginVertical: 8 },
|
|
86
|
+
label: { fontSize: 10, color: '#777', marginBottom: 2 },
|
|
87
|
+
banner: { width: '100%', height: 50 }
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export { AdBanner };
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@upeex/ads-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Upeex Ads SDK for React Native and universal apps",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"react": ">=17",
|
|
12
|
+
"react-native": ">=0.68"
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rollup -c"
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ads",
|
|
21
|
+
"mobile-ads",
|
|
22
|
+
"react-native",
|
|
23
|
+
"expo",
|
|
24
|
+
"sdk",
|
|
25
|
+
"upeex"
|
|
26
|
+
],
|
|
27
|
+
|
|
28
|
+
"author": "Upeex",
|
|
29
|
+
"license": "MIT"
|
|
30
|
+
}
|