@upeex/ads-sdk 0.1.0 → 0.1.2
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 +9 -2
- package/dist/index.js +85 -62
- package/dist/signals.d.ts +8 -9
- package/package.json +16 -8
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,2 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type LoadAdParams = {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
client: string;
|
|
4
|
+
slot: string;
|
|
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,90 +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
|
-
var _a;
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const Application = await import('expo-application');
|
|
24
|
-
bundle = (_a = Application.applicationId) !== null && _a !== void 0 ? _a : null;
|
|
6
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7
|
+
let platform = 'unknown';
|
|
8
|
+
let screenWidth = 0;
|
|
9
|
+
let screenHeight = 0;
|
|
10
|
+
let userAgent = 'unknown';
|
|
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;
|
|
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';
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
//
|
|
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
|
|
28
31
|
}
|
|
29
32
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
platform,
|
|
34
|
+
screenWidth,
|
|
35
|
+
screenHeight,
|
|
36
|
+
userAgent,
|
|
37
|
+
locale,
|
|
38
|
+
timezone,
|
|
35
39
|
};
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
async function loadAd(client, slot) {
|
|
42
|
+
async function fetchAd({ baseUrl, client, slot, display = 'BANNER', }) {
|
|
40
43
|
const signals = await getSignals();
|
|
41
|
-
const
|
|
44
|
+
const res = await fetch(`${baseUrl}/make`, {
|
|
42
45
|
method: 'POST',
|
|
43
46
|
headers: { 'Content-Type': 'application/json' },
|
|
44
47
|
body: JSON.stringify({
|
|
45
48
|
client,
|
|
46
49
|
slot,
|
|
47
|
-
|
|
48
|
-
signals
|
|
49
|
-
|
|
50
|
+
display,
|
|
51
|
+
isMobile: signals.platform !== 'web' ? 1 : 0,
|
|
52
|
+
...signals,
|
|
53
|
+
}),
|
|
50
54
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
55
|
+
if (!res.ok)
|
|
56
|
+
return null;
|
|
57
|
+
return res.json();
|
|
54
58
|
}
|
|
55
|
-
function countView(token) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (_a) { }
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
function AdBanner({ client, slot }) {
|
|
70
|
+
function AdBanner({ client, slot, baseUrl = 'http://localhost:3000', theme = 'light', style = {}, }) {
|
|
64
71
|
const [ad, setAd] = useState(null);
|
|
65
|
-
const viewed = useRef(false);
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
loadAd(client, slot).then(setAd);
|
|
68
|
-
}, []);
|
|
69
72
|
useEffect(() => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}, (ad.view_time || 5) * 1000);
|
|
78
|
-
return () => clearTimeout(t);
|
|
79
|
-
}, [ad]);
|
|
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]);
|
|
80
80
|
if (!ad)
|
|
81
81
|
return null;
|
|
82
|
-
|
|
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 })] }));
|
|
83
91
|
}
|
|
84
92
|
const styles = StyleSheet.create({
|
|
85
|
-
container: {
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
},
|
|
88
111
|
});
|
|
89
112
|
|
|
90
113
|
export { AdBanner };
|
package/dist/signals.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export {};
|
|
1
|
+
export declare function getSignals(): Promise<{
|
|
2
|
+
platform: string;
|
|
3
|
+
screenWidth: number;
|
|
4
|
+
screenHeight: number;
|
|
5
|
+
userAgent: string;
|
|
6
|
+
locale: string;
|
|
7
|
+
timezone: string;
|
|
8
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upeex/ads-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
|
22
21
|
"react-native",
|
|
23
22
|
"expo",
|
|
24
23
|
"sdk",
|
|
25
|
-
"upeex"
|
|
24
|
+
"upeex",
|
|
25
|
+
"upee"
|
|
26
26
|
],
|
|
27
|
-
|
|
28
27
|
"author": "Upeex",
|
|
29
|
-
"license": "MIT"
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"expo-localization": "^17.0.8"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"rollup": "^4.57.0",
|
|
34
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
35
|
+
"tslib": "^2.8.1",
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
}
|
|
30
38
|
}
|