@upeex/ads-sdk 0.1.0 → 0.1.1
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/core.d.ts +7 -2
- package/dist/index.js +44 -52
- package/dist/signals.d.ts +8 -7
- package/package.json +14 -7
package/dist/core.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export interface LoadAdOptions {
|
|
2
|
+
baseUrl?: string;
|
|
3
|
+
client: string;
|
|
4
|
+
slot: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function loadAd({ baseUrl, client, slot }: LoadAdOptions): Promise<any>;
|
|
7
|
+
export declare function countView(baseUrl: string, token: string): void;
|
package/dist/index.js
CHANGED
|
@@ -1,82 +1,74 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useRef, useEffect } from 'react';
|
|
3
|
-
import { StyleSheet,
|
|
3
|
+
import { StyleSheet, View, Text, TouchableOpacity, Image, Linking } from 'react-native';
|
|
4
4
|
|
|
5
5
|
async function getSignals() {
|
|
6
|
-
|
|
7
|
-
let
|
|
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)
|
|
6
|
+
let lang = 'pt-BR';
|
|
7
|
+
let tz = 'UTC';
|
|
14
8
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
const intl = Intl.DateTimeFormat().resolvedOptions();
|
|
10
|
+
lang = intl.locale;
|
|
11
|
+
tz = intl.timeZone;
|
|
18
12
|
}
|
|
19
|
-
catch (
|
|
20
|
-
|
|
13
|
+
catch (_a) { }
|
|
14
|
+
let userAgent = 'unknown';
|
|
15
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent) {
|
|
16
|
+
userAgent = navigator.userAgent;
|
|
21
17
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// não é Expo
|
|
18
|
+
let screenWidth = 0;
|
|
19
|
+
let screenHeight = 0;
|
|
20
|
+
if (typeof window !== 'undefined' && window.screen) {
|
|
21
|
+
screenWidth = window.screen.width;
|
|
22
|
+
screenHeight = window.screen.height;
|
|
28
23
|
}
|
|
29
24
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
isMobile: true,
|
|
26
|
+
screenWidth,
|
|
27
|
+
screenHeight,
|
|
28
|
+
userAgent,
|
|
33
29
|
lang,
|
|
34
|
-
tz
|
|
30
|
+
tz,
|
|
31
|
+
href: typeof location !== 'undefined' ? location.href : 'app://mobile',
|
|
32
|
+
hostname: typeof location !== 'undefined' ? location.hostname : 'mobile-app'
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
async function loadAd(client, slot) {
|
|
36
|
+
async function loadAd({ baseUrl = 'http://localhost:3000', client, slot }) {
|
|
40
37
|
const signals = await getSignals();
|
|
41
|
-
const makeRes = await fetch(`${
|
|
38
|
+
const makeRes = await fetch(`${baseUrl}/ad/make/mobile`, {
|
|
42
39
|
method: 'POST',
|
|
43
|
-
headers: {
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json'
|
|
42
|
+
},
|
|
44
43
|
body: JSON.stringify({
|
|
45
44
|
client,
|
|
46
45
|
slot,
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
display: 'BANNER',
|
|
47
|
+
responsive: 1,
|
|
48
|
+
...signals
|
|
49
49
|
})
|
|
50
50
|
});
|
|
51
|
+
if (!makeRes.ok) {
|
|
52
|
+
throw new Error('Erro ao chamar /ad/make/mobile');
|
|
53
|
+
}
|
|
51
54
|
const makeData = await makeRes.json();
|
|
52
|
-
|
|
55
|
+
if (!makeData.url) {
|
|
56
|
+
throw new Error('MAKE não retornou URL');
|
|
57
|
+
}
|
|
58
|
+
const showRes = await fetch(makeData.url);
|
|
53
59
|
return showRes.json();
|
|
54
60
|
}
|
|
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
61
|
|
|
63
62
|
function AdBanner({ client, slot }) {
|
|
64
63
|
const [ad, setAd] = useState(null);
|
|
65
|
-
|
|
64
|
+
useRef(false);
|
|
66
65
|
useEffect(() => {
|
|
67
|
-
loadAd(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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]);
|
|
66
|
+
loadAd({
|
|
67
|
+
baseUrl: 'http://localhost:3000',
|
|
68
|
+
client,
|
|
69
|
+
slot
|
|
70
|
+
}).then(setAd);
|
|
71
|
+
}, [client, slot]);
|
|
80
72
|
if (!ad)
|
|
81
73
|
return null;
|
|
82
74
|
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" }) })] }));
|
package/dist/signals.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare function getSignals(): Promise<{
|
|
2
|
+
isMobile: boolean;
|
|
3
|
+
screenWidth: number;
|
|
4
|
+
screenHeight: number;
|
|
5
|
+
userAgent: string;
|
|
5
6
|
lang: string;
|
|
6
7
|
tz: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
href: string;
|
|
9
|
+
hostname: string;
|
|
10
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upeex/ads-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Upeex Ads SDK for React Native and universal apps",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
8
10
|
"sideEffects": false,
|
|
9
|
-
|
|
10
11
|
"peerDependencies": {
|
|
11
12
|
"react": ">=17",
|
|
12
13
|
"react-native": ">=0.68"
|
|
13
14
|
},
|
|
14
|
-
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "rollup -c"
|
|
17
17
|
},
|
|
18
|
-
|
|
19
18
|
"keywords": [
|
|
20
19
|
"ads",
|
|
21
20
|
"mobile-ads",
|
|
@@ -24,7 +23,15 @@
|
|
|
24
23
|
"sdk",
|
|
25
24
|
"upeex"
|
|
26
25
|
],
|
|
27
|
-
|
|
28
26
|
"author": "Upeex",
|
|
29
|
-
"license": "MIT"
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"expo-localization": "^17.0.8"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"rollup": "^4.57.0",
|
|
33
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
34
|
+
"tslib": "^2.8.1",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
}
|
|
30
37
|
}
|