@upeex/ads-sdk 0.1.1 → 0.1.3
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/AdBanner.d.ts +9 -4
- package/dist/core.d.ts +7 -5
- package/dist/index.js +81 -50
- package/dist/signals.d.ts +3 -5
- package/package.json +3 -2
package/dist/AdBanner.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
client:
|
|
3
|
-
slot:
|
|
4
|
-
|
|
1
|
+
type Props = {
|
|
2
|
+
client: string;
|
|
3
|
+
slot: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
theme?: 'light' | 'dark';
|
|
6
|
+
style?: object;
|
|
7
|
+
};
|
|
8
|
+
export default function AdBanner({ client, slot, baseUrl, theme, style, }: Props): any;
|
|
9
|
+
export {};
|
package/dist/core.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
baseUrl
|
|
1
|
+
type LoadAdParams = {
|
|
2
|
+
baseUrl: string;
|
|
3
3
|
client: string;
|
|
4
4
|
slot: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
5
|
+
display?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function fetchAd({ baseUrl, client, slot, display, }: LoadAdParams): Promise<any>;
|
|
8
|
+
export declare function countView(baseUrl: string, token: string): Promise<void>;
|
|
9
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,82 +1,113 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useState,
|
|
3
|
-
import {
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { Platform, Dimensions, StyleSheet, TouchableOpacity, Text, Linking } from 'react-native';
|
|
4
4
|
|
|
5
5
|
async function getSignals() {
|
|
6
|
-
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
lang = intl.locale;
|
|
11
|
-
tz = intl.timeZone;
|
|
12
|
-
}
|
|
13
|
-
catch (_a) { }
|
|
6
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7
|
+
let platform = 'unknown';
|
|
8
|
+
let screenWidth = 0;
|
|
9
|
+
let screenHeight = 0;
|
|
14
10
|
let userAgent = 'unknown';
|
|
15
|
-
|
|
11
|
+
let locale = 'en-US';
|
|
12
|
+
let timezone = 'UTC';
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
// Web / PWA
|
|
15
|
+
platform = 'web';
|
|
16
|
+
screenWidth = window.innerWidth;
|
|
17
|
+
screenHeight = window.innerHeight;
|
|
16
18
|
userAgent = navigator.userAgent;
|
|
19
|
+
locale =
|
|
20
|
+
((_c = (_b = (_a = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat) === null || _a === void 0 ? void 0 : _a.call(Intl)) === null || _b === void 0 ? void 0 : _b.resolvedOptions) === null || _c === void 0 ? void 0 : _c.call(_b).locale) || 'en-US';
|
|
21
|
+
timezone =
|
|
22
|
+
((_f = (_e = (_d = Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat) === null || _d === void 0 ? void 0 : _d.call(Intl)) === null || _e === void 0 ? void 0 : _e.resolvedOptions) === null || _f === void 0 ? void 0 : _f.call(_e).timeZone) || 'UTC';
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
else if (typeof Platform !== 'undefined') {
|
|
25
|
+
// React Native
|
|
26
|
+
platform = Platform.OS;
|
|
27
|
+
const dim = Dimensions.get('window');
|
|
28
|
+
screenWidth = dim.width;
|
|
29
|
+
screenHeight = dim.height;
|
|
30
|
+
// RN não tem userAgent nativo
|
|
23
31
|
}
|
|
24
32
|
return {
|
|
25
|
-
|
|
33
|
+
platform,
|
|
26
34
|
screenWidth,
|
|
27
35
|
screenHeight,
|
|
28
36
|
userAgent,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
href: typeof location !== 'undefined' ? location.href : 'app://mobile',
|
|
32
|
-
hostname: typeof location !== 'undefined' ? location.hostname : 'mobile-app'
|
|
37
|
+
locale,
|
|
38
|
+
timezone,
|
|
33
39
|
};
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
async function
|
|
42
|
+
async function fetchAd({ baseUrl, client, slot, display = 'BANNER', }) {
|
|
37
43
|
const signals = await getSignals();
|
|
38
|
-
const
|
|
44
|
+
const res = await fetch(`${baseUrl}/make`, {
|
|
39
45
|
method: 'POST',
|
|
40
|
-
headers: {
|
|
41
|
-
'Content-Type': 'application/json'
|
|
42
|
-
},
|
|
46
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
47
|
body: JSON.stringify({
|
|
44
48
|
client,
|
|
45
49
|
slot,
|
|
46
|
-
display
|
|
47
|
-
|
|
48
|
-
...signals
|
|
49
|
-
})
|
|
50
|
+
display,
|
|
51
|
+
isMobile: signals.platform !== 'web' ? 1 : 0,
|
|
52
|
+
...signals,
|
|
53
|
+
}),
|
|
50
54
|
});
|
|
51
|
-
if (!
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
if (!res.ok)
|
|
56
|
+
return null;
|
|
57
|
+
return res.json();
|
|
58
|
+
}
|
|
59
|
+
async function countView(baseUrl, token) {
|
|
60
|
+
try {
|
|
61
|
+
await fetch(`${baseUrl}/count/views`, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: { 'Content-Type': 'application/json' },
|
|
64
|
+
body: JSON.stringify({ token }),
|
|
65
|
+
});
|
|
57
66
|
}
|
|
58
|
-
|
|
59
|
-
return showRes.json();
|
|
67
|
+
catch (_a) { }
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
function AdBanner({ client, slot }) {
|
|
70
|
+
function AdBanner({ client, slot, baseUrl = 'https://ads.upeex.com.br', theme = 'light', style = {}, }) {
|
|
63
71
|
const [ad, setAd] = useState(null);
|
|
64
|
-
useRef(false);
|
|
65
72
|
useEffect(() => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
fetchAd({ baseUrl, client, slot }).then((data) => {
|
|
74
|
+
if (!data)
|
|
75
|
+
return;
|
|
76
|
+
setAd(data);
|
|
77
|
+
countView(baseUrl, data.adtoken);
|
|
78
|
+
});
|
|
79
|
+
}, [client, slot, baseUrl]);
|
|
72
80
|
if (!ad)
|
|
73
81
|
return null;
|
|
74
|
-
|
|
82
|
+
const handlePress = () => {
|
|
83
|
+
if (Platform.OS === 'web') {
|
|
84
|
+
window.open(ad.url, '_blank');
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
Linking.openURL(ad.url);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return (jsxs(TouchableOpacity, { style: [styles.container, theme === 'dark' && styles.dark, style], onPress: handlePress, children: [jsx(Text, { style: styles.title, children: "Publicidade" }), jsx(Text, { style: styles.text, children: ad.url })] }));
|
|
75
91
|
}
|
|
76
92
|
const styles = StyleSheet.create({
|
|
77
|
-
container: {
|
|
78
|
-
|
|
79
|
-
|
|
93
|
+
container: {
|
|
94
|
+
backgroundColor: '#f2f2f2',
|
|
95
|
+
padding: 12,
|
|
96
|
+
borderTopWidth: 1,
|
|
97
|
+
borderColor: '#ddd',
|
|
98
|
+
},
|
|
99
|
+
dark: {
|
|
100
|
+
backgroundColor: '#121212',
|
|
101
|
+
},
|
|
102
|
+
title: {
|
|
103
|
+
fontSize: 12,
|
|
104
|
+
fontWeight: '600',
|
|
105
|
+
marginBottom: 4,
|
|
106
|
+
},
|
|
107
|
+
text: {
|
|
108
|
+
fontSize: 11,
|
|
109
|
+
color: '#555',
|
|
110
|
+
},
|
|
80
111
|
});
|
|
81
112
|
|
|
82
113
|
export { AdBanner };
|
package/dist/signals.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export declare function getSignals(): Promise<{
|
|
2
|
-
|
|
2
|
+
platform: string;
|
|
3
3
|
screenWidth: number;
|
|
4
4
|
screenHeight: number;
|
|
5
5
|
userAgent: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
href: string;
|
|
9
|
-
hostname: string;
|
|
6
|
+
locale: string;
|
|
7
|
+
timezone: string;
|
|
10
8
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upeex/ads-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"react-native",
|
|
22
22
|
"expo",
|
|
23
23
|
"sdk",
|
|
24
|
-
"upeex"
|
|
24
|
+
"upeex",
|
|
25
|
+
"upee"
|
|
25
26
|
],
|
|
26
27
|
"author": "Upeex",
|
|
27
28
|
"license": "MIT",
|