@adtogether/react-native-sdk 0.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/README.md +145 -0
- package/lib/commonjs/AdTogether.js +85 -0
- package/lib/commonjs/AdTogether.js.map +1 -0
- package/lib/commonjs/AdTogetherBanner.js +174 -0
- package/lib/commonjs/AdTogetherBanner.js.map +1 -0
- package/lib/commonjs/AdTogetherInterstitial.js +259 -0
- package/lib/commonjs/AdTogetherInterstitial.js.map +1 -0
- package/lib/commonjs/index.js +50 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/AdTogether.js +80 -0
- package/lib/module/AdTogether.js.map +1 -0
- package/lib/module/AdTogetherBanner.js +168 -0
- package/lib/module/AdTogetherBanner.js.map +1 -0
- package/lib/module/AdTogetherInterstitial.js +253 -0
- package/lib/module/AdTogetherInterstitial.js.map +1 -0
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/AdTogether.d.ts +17 -0
- package/lib/typescript/AdTogether.d.ts.map +1 -0
- package/lib/typescript/AdTogetherBanner.d.ts +11 -0
- package/lib/typescript/AdTogetherBanner.d.ts.map +1 -0
- package/lib/typescript/AdTogetherInterstitial.d.ts +12 -0
- package/lib/typescript/AdTogetherInterstitial.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +18 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/AdTogether.ts +98 -0
- package/src/AdTogetherBanner.tsx +175 -0
- package/src/AdTogetherInterstitial.tsx +230 -0
- package/src/index.ts +4 -0
- package/src/types.ts +19 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# AdTogether React Native SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@adtogether/react-native-sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<strong>"Show an ad, get an ad shown"</strong><br>
|
|
8
|
+
The Universal Ad Exchange & Reciprocal Marketing Platform
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
**AdTogether** is an ad exchange platform designed to empower developers and creators. By participating in our network, you can engage in reciprocal marketing for your own applications while simultaneously driving traffic to your products and helping you **increase conversions**. Our core philosophy is simple: **"Show an ad, get an ad shown"**.
|
|
14
|
+
|
|
15
|
+
This SDK allows React Native developers to easily integrate AdTogether ads into their applications. By displaying ads from other community members, you earn **Ad Credits** that allow your own app's ads to be shown across the AdTogether network.
|
|
16
|
+
|
|
17
|
+
### 🖼️ Visualizing the Experience
|
|
18
|
+
|
|
19
|
+
| **Native Banner Ad** | **Interstitial Full-Screen** |
|
|
20
|
+
|:---:|:---:|
|
|
21
|
+
|  |  |
|
|
22
|
+
| *Adaptive React Native Banner Component* | *Full-Screen Interstitial Experience* |
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- 🖼️ **Banner Ads** — Native React Native `AdTogetherBanner` component with impression tracking.
|
|
27
|
+
- 📺 **Interstitial Ads** — Full-screen `AdTogetherInterstitial` component with a configurable close-button countdown.
|
|
28
|
+
- 🌑 **Dark Mode Support** — All ad components automatically adapt to system preference.
|
|
29
|
+
- ⚖️ **Fair Exchange** — Automated impression and click tracking ensures fair distribution of ad credits.
|
|
30
|
+
- 🔌 **Easy Integration** — A single `initialize()` call and one component is all you need to start earning credits and increase conversions.
|
|
31
|
+
|
|
32
|
+
## Getting Started
|
|
33
|
+
|
|
34
|
+
### 1. Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @adtogether/react-native-sdk
|
|
38
|
+
# or
|
|
39
|
+
yarn add @adtogether/react-native-sdk
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Initialize
|
|
43
|
+
|
|
44
|
+
Call `AdTogether.initialize()` before rendering any ad components. You can obtain your App ID from the [AdTogether Dashboard](https://adtogether.relaxsoftwareapps.com/dashboard).
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { AdTogether } from '@adtogether/react-native-sdk';
|
|
48
|
+
|
|
49
|
+
AdTogether.initialize({ appId: 'YOUR_APP_ID' });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Banner Ads
|
|
55
|
+
|
|
56
|
+
Use the `AdTogetherBanner` component anywhere in your React Native app.
|
|
57
|
+
|
|
58
|
+
```jsx
|
|
59
|
+
import { AdTogetherBanner } from '@adtogether/react-native-sdk';
|
|
60
|
+
import { View, Text } from 'react-native';
|
|
61
|
+
|
|
62
|
+
function MyApp() {
|
|
63
|
+
return (
|
|
64
|
+
<View style={{ flex: 1 }}>
|
|
65
|
+
<Text>My Awesome App</Text>
|
|
66
|
+
|
|
67
|
+
<AdTogetherBanner
|
|
68
|
+
adUnitId="home_bottom_banner"
|
|
69
|
+
onAdLoaded={() => console.log('Banner loaded!')}
|
|
70
|
+
onAdFailedToLoad={(error) => console.error('Banner error:', error)}
|
|
71
|
+
/>
|
|
72
|
+
</View>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### `AdTogetherBanner` Props
|
|
78
|
+
|
|
79
|
+
| Prop | Type | Default | Description |
|
|
80
|
+
|--------------------|-------------------------|-----------|-------------|
|
|
81
|
+
| `adUnitId` | `string` | **required** | Unique identifier for this ad placement. |
|
|
82
|
+
| `theme` | `'dark' \| 'light' \| 'auto'` | `'auto'` | Color scheme. `'auto'` follows system preference. |
|
|
83
|
+
| `onAdLoaded` | `() => void` | — | Called when the ad has been successfully fetched and rendered. |
|
|
84
|
+
| `onAdFailedToLoad` | `(error: Error) => void`| — | Called if the ad fails to load. |
|
|
85
|
+
| `style` | `StyleProp<ViewStyle>` | — | Additional React Native styles for the container. |
|
|
86
|
+
|
|
87
|
+
### Interstitial Ads
|
|
88
|
+
|
|
89
|
+
Show a full-screen interstitial ad as a modal overlay. A countdown timer is displayed before the user is allowed to close the ad.
|
|
90
|
+
|
|
91
|
+
```jsx
|
|
92
|
+
import { useState } from 'react';
|
|
93
|
+
import { View, Button } from 'react-native';
|
|
94
|
+
import { AdTogetherInterstitial } from '@adtogether/react-native-sdk';
|
|
95
|
+
|
|
96
|
+
function MyApp() {
|
|
97
|
+
const [showInterstitial, setShowInterstitial] = useState(false);
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<View style={{ flex: 1, justifyContent: 'center' }}>
|
|
101
|
+
<Button title="Show Interstitial Ad" onPress={() => setShowInterstitial(true)} />
|
|
102
|
+
|
|
103
|
+
<AdTogetherInterstitial
|
|
104
|
+
adUnitId="level_complete_interstitial"
|
|
105
|
+
isOpen={showInterstitial}
|
|
106
|
+
onClose={() => setShowInterstitial(false)}
|
|
107
|
+
closeDelay={5}
|
|
108
|
+
onAdLoaded={() => console.log('Interstitial ready')}
|
|
109
|
+
onAdFailedToLoad={(error) => console.error('Interstitial error:', error)}
|
|
110
|
+
/>
|
|
111
|
+
</View>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### `AdTogetherInterstitial` Props
|
|
117
|
+
|
|
118
|
+
| Prop | Type | Default | Description |
|
|
119
|
+
|--------------------|-------------------------|-----------|-------------|
|
|
120
|
+
| `adUnitId` | `string` | **required** | Unique identifier for this ad placement. |
|
|
121
|
+
| `isOpen` | `boolean` | **required** | When `true`, the interstitial is displayed. |
|
|
122
|
+
| `onClose` | `() => void` | **required** | Called when the user closes the interstitial. |
|
|
123
|
+
| `closeDelay` | `number` | `3` | Seconds before the close button appears. A countdown is shown during this time. |
|
|
124
|
+
| `theme` | `'dark' \| 'light' \| 'auto'` | `'auto'` | Color scheme. `'auto'` follows system preference. |
|
|
125
|
+
| `onAdLoaded` | `() => void` | — | Called when the ad has been successfully fetched. |
|
|
126
|
+
| `onAdFailedToLoad` | `(error: Error) => void`| — | Called if the ad fails to load. The dialog is automatically dismissed on failure. |
|
|
127
|
+
|
|
128
|
+
## How Credits Work
|
|
129
|
+
|
|
130
|
+
1. **Earn credits** — Every time your app displays an ad from the AdTogether network and the impression is verified, you earn ad credits.
|
|
131
|
+
2. **Spend credits** — Your ad credits are automatically spent to show *your* campaigns inside other apps on the network, helping you increase conversions.
|
|
132
|
+
3. **Fair weighting** — Different ad formats and geographies have different credit weights, ensuring a level playing field for apps of all sizes.
|
|
133
|
+
|
|
134
|
+
Create and manage your campaigns from the [AdTogether Dashboard](https://adtogether.relaxsoftwareapps.com/dashboard).
|
|
135
|
+
|
|
136
|
+
## Additional Information
|
|
137
|
+
|
|
138
|
+
- 📖 **Documentation**: [adtogether.relaxsoftwareapps.com/docs](https://adtogether.relaxsoftwareapps.com/docs)
|
|
139
|
+
- 🐛 **Issues**: [GitHub Issues](https://github.com/undecided2003/AdTogether/issues)
|
|
140
|
+
- 💬 **Support**: Join our [Discord community](https://discord.gg/maA8g4ADpk) for real-time help.
|
|
141
|
+
- 🌐 **Dashboard**: [adtogether.relaxsoftwareapps.com/dashboard](https://adtogether.relaxsoftwareapps.com/dashboard)
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
This project is licensed under the MIT License — see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AdTogether = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
class AdTogether {
|
|
9
|
+
allowSelfAds = true;
|
|
10
|
+
baseUrl = 'https://adtogether.relaxsoftwareapps.com';
|
|
11
|
+
constructor() {}
|
|
12
|
+
static get shared() {
|
|
13
|
+
if (!AdTogether.instance) {
|
|
14
|
+
AdTogether.instance = new AdTogether();
|
|
15
|
+
}
|
|
16
|
+
return AdTogether.instance;
|
|
17
|
+
}
|
|
18
|
+
static initialize(options) {
|
|
19
|
+
const sdk = AdTogether.shared;
|
|
20
|
+
sdk.appId = options.apiKey || options.appId;
|
|
21
|
+
if (options.allowSelfAds !== undefined) {
|
|
22
|
+
sdk.allowSelfAds = options.allowSelfAds;
|
|
23
|
+
}
|
|
24
|
+
if (options.baseUrl) {
|
|
25
|
+
sdk.baseUrl = options.baseUrl;
|
|
26
|
+
}
|
|
27
|
+
console.log(`AdTogether SDK Initialized with App ID: ${sdk.appId}`);
|
|
28
|
+
}
|
|
29
|
+
assertInitialized() {
|
|
30
|
+
if (!this.appId) {
|
|
31
|
+
console.error('AdTogether Error: SDK has not been initialized. Please call AdTogether.initialize() before displaying ads.');
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
static async fetchAd(adUnitId, adType) {
|
|
37
|
+
if (!AdTogether.shared.assertInitialized()) {
|
|
38
|
+
throw new Error('AdTogether not initialized');
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const sdk = AdTogether.shared;
|
|
42
|
+
let url = `${sdk.baseUrl}/api/ads/serve?country=global&adUnitId=${adUnitId}&apiKey=${sdk.appId}`;
|
|
43
|
+
if (adType) {
|
|
44
|
+
url += `&adType=${adType}`;
|
|
45
|
+
}
|
|
46
|
+
if (sdk.lastAdId) {
|
|
47
|
+
url += `&exclude=${sdk.lastAdId}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Pass allowSelfAds
|
|
51
|
+
url += `&allowSelfAds=${sdk.allowSelfAds}&platform=${_reactNative.Platform.OS}`;
|
|
52
|
+
const response = await fetch(url);
|
|
53
|
+
if (response.ok) {
|
|
54
|
+
const ad = await response.json();
|
|
55
|
+
sdk.lastAdId = ad.id;
|
|
56
|
+
return ad;
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Failed to fetch ad. Status: ${response.status}`);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
static trackImpression(adId, token) {
|
|
64
|
+
this.trackEvent('/api/ads/impression', adId, token);
|
|
65
|
+
}
|
|
66
|
+
static trackClick(adId, token) {
|
|
67
|
+
this.trackEvent('/api/ads/click', adId, token);
|
|
68
|
+
}
|
|
69
|
+
static trackEvent(endpoint, adId, token) {
|
|
70
|
+
if (!AdTogether.shared.assertInitialized()) return;
|
|
71
|
+
fetch(`${AdTogether.shared.baseUrl}${endpoint}`, {
|
|
72
|
+
method: 'POST',
|
|
73
|
+
headers: {
|
|
74
|
+
'Content-Type': 'application/json'
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify({
|
|
77
|
+
adId,
|
|
78
|
+
token,
|
|
79
|
+
apiKey: AdTogether.shared.appId
|
|
80
|
+
})
|
|
81
|
+
}).catch(console.error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.AdTogether = AdTogether;
|
|
85
|
+
//# sourceMappingURL=AdTogether.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","AdTogether","allowSelfAds","baseUrl","constructor","shared","instance","initialize","options","sdk","appId","apiKey","undefined","console","log","assertInitialized","error","fetchAd","adUnitId","adType","Error","url","lastAdId","Platform","OS","response","fetch","ok","ad","json","id","status","err","trackImpression","adId","token","trackEvent","trackClick","endpoint","method","headers","body","JSON","stringify","catch","exports"],"sourceRoot":"..\\..\\src","sources":["AdTogether.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,UAAU,CAAC;EAGdC,YAAY,GAAY,IA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AU,CAACI,MAAM,CAACK;MAC5B,CAAC;IACH,CAAC,CAAC,CAACkC,KAAK,CAAC/B,OAAO,CAACG,KAAK,CAAC;EACzB;AACF;AAAC6B,OAAA,CAAA5C,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AdTogetherBanner = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _AdTogether = require("./AdTogether");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
const AdTogetherBanner = ({
|
|
13
|
+
adUnitId,
|
|
14
|
+
onAdLoaded,
|
|
15
|
+
onAdFailedToLoad,
|
|
16
|
+
theme = 'auto',
|
|
17
|
+
style
|
|
18
|
+
}) => {
|
|
19
|
+
const [adData, setAdData] = (0, _react.useState)(null);
|
|
20
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(true);
|
|
21
|
+
const [hasError, setHasError] = (0, _react.useState)(false);
|
|
22
|
+
const systemColorScheme = (0, _reactNative.useColorScheme)();
|
|
23
|
+
const impressionTrackedRef = (0, _react.useRef)(false);
|
|
24
|
+
(0, _react.useEffect)(() => {
|
|
25
|
+
let isMounted = true;
|
|
26
|
+
_AdTogether.AdTogether.fetchAd(adUnitId, 'banner').then(ad => {
|
|
27
|
+
if (isMounted) {
|
|
28
|
+
setAdData(ad);
|
|
29
|
+
setIsLoading(false);
|
|
30
|
+
onAdLoaded?.();
|
|
31
|
+
}
|
|
32
|
+
}).catch(err => {
|
|
33
|
+
if (isMounted) {
|
|
34
|
+
console.error('AdTogether Failed to load ad:', err);
|
|
35
|
+
setHasError(true);
|
|
36
|
+
setIsLoading(false);
|
|
37
|
+
onAdFailedToLoad?.(err);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
isMounted = false;
|
|
42
|
+
};
|
|
43
|
+
}, [adUnitId, onAdLoaded, onAdFailedToLoad]);
|
|
44
|
+
|
|
45
|
+
// Track impression when ad is rendered
|
|
46
|
+
(0, _react.useEffect)(() => {
|
|
47
|
+
if (adData && !isLoading && !hasError && !impressionTrackedRef.current) {
|
|
48
|
+
impressionTrackedRef.current = true;
|
|
49
|
+
_AdTogether.AdTogether.trackImpression(adData.id, adData.token);
|
|
50
|
+
}
|
|
51
|
+
}, [adData, isLoading, hasError]);
|
|
52
|
+
const handlePress = () => {
|
|
53
|
+
if (!adData) return;
|
|
54
|
+
_AdTogether.AdTogether.trackClick(adData.id, adData.token);
|
|
55
|
+
if (adData.clickUrl) {
|
|
56
|
+
_reactNative.Linking.openURL(adData.clickUrl).catch(console.error);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
if (isLoading) {
|
|
60
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
61
|
+
style: [styles.container, style]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (hasError || !adData) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const isDarkMode = theme === 'auto' ? systemColorScheme === 'dark' : theme === 'dark';
|
|
68
|
+
const bgColor = isDarkMode ? '#1F2937' : '#ffffff';
|
|
69
|
+
const borderColor = isDarkMode ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.1)';
|
|
70
|
+
const textColor = isDarkMode ? '#F9FAFB' : '#111827';
|
|
71
|
+
const descColor = isDarkMode ? '#9CA3AF' : '#6B7280';
|
|
72
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
|
|
73
|
+
activeOpacity: 0.8,
|
|
74
|
+
onPress: handlePress,
|
|
75
|
+
style: [styles.container, {
|
|
76
|
+
backgroundColor: bgColor,
|
|
77
|
+
borderColor
|
|
78
|
+
}, style],
|
|
79
|
+
children: [adData.imageUrl ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
80
|
+
style: styles.imageContainer,
|
|
81
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, {
|
|
82
|
+
source: {
|
|
83
|
+
uri: adData.imageUrl
|
|
84
|
+
},
|
|
85
|
+
style: styles.image,
|
|
86
|
+
resizeMode: "cover"
|
|
87
|
+
})
|
|
88
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
89
|
+
style: styles.textContainer,
|
|
90
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
91
|
+
style: styles.headerRow,
|
|
92
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
93
|
+
style: [styles.title, {
|
|
94
|
+
color: textColor
|
|
95
|
+
}],
|
|
96
|
+
numberOfLines: 1,
|
|
97
|
+
children: adData.title
|
|
98
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
99
|
+
style: styles.adBadge,
|
|
100
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
101
|
+
style: styles.adBadgeText,
|
|
102
|
+
children: "AD"
|
|
103
|
+
})
|
|
104
|
+
})]
|
|
105
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
106
|
+
style: [styles.description, {
|
|
107
|
+
color: descColor
|
|
108
|
+
}],
|
|
109
|
+
numberOfLines: 2,
|
|
110
|
+
children: adData.description
|
|
111
|
+
})]
|
|
112
|
+
})]
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
exports.AdTogetherBanner = AdTogetherBanner;
|
|
116
|
+
const styles = _reactNative.StyleSheet.create({
|
|
117
|
+
container: {
|
|
118
|
+
flexDirection: 'row',
|
|
119
|
+
width: '100%',
|
|
120
|
+
minHeight: 80,
|
|
121
|
+
borderRadius: 12,
|
|
122
|
+
borderWidth: 1,
|
|
123
|
+
overflow: 'hidden',
|
|
124
|
+
shadowColor: '#000',
|
|
125
|
+
shadowOffset: {
|
|
126
|
+
width: 0,
|
|
127
|
+
height: 2
|
|
128
|
+
},
|
|
129
|
+
shadowOpacity: 0.05,
|
|
130
|
+
shadowRadius: 5,
|
|
131
|
+
elevation: 2
|
|
132
|
+
},
|
|
133
|
+
imageContainer: {
|
|
134
|
+
width: 120,
|
|
135
|
+
height: '100%',
|
|
136
|
+
minHeight: 80
|
|
137
|
+
},
|
|
138
|
+
image: {
|
|
139
|
+
width: '100%',
|
|
140
|
+
height: '100%'
|
|
141
|
+
},
|
|
142
|
+
textContainer: {
|
|
143
|
+
padding: 12,
|
|
144
|
+
flex: 1,
|
|
145
|
+
justifyContent: 'center'
|
|
146
|
+
},
|
|
147
|
+
headerRow: {
|
|
148
|
+
flexDirection: 'row',
|
|
149
|
+
justifyContent: 'space-between',
|
|
150
|
+
alignItems: 'flex-start',
|
|
151
|
+
marginBottom: 4
|
|
152
|
+
},
|
|
153
|
+
title: {
|
|
154
|
+
fontWeight: 'bold',
|
|
155
|
+
fontSize: 14,
|
|
156
|
+
flex: 1
|
|
157
|
+
},
|
|
158
|
+
adBadge: {
|
|
159
|
+
backgroundColor: '#FBBF24',
|
|
160
|
+
paddingHorizontal: 4,
|
|
161
|
+
paddingVertical: 2,
|
|
162
|
+
borderRadius: 4,
|
|
163
|
+
marginLeft: 8
|
|
164
|
+
},
|
|
165
|
+
adBadgeText: {
|
|
166
|
+
color: '#000',
|
|
167
|
+
fontSize: 9,
|
|
168
|
+
fontWeight: 'bold'
|
|
169
|
+
},
|
|
170
|
+
description: {
|
|
171
|
+
fontSize: 12
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
//# sourceMappingURL=AdTogetherBanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_AdTogether","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AdTogetherBanner","adUnitId","onAdLoaded","onAdFailedToLoad","theme","style","adData","setAdData","useState","isLoading","setIsLoading","hasError","setHasError","systemColorScheme","useColorScheme","impressionTrackedRef","useRef","useEffect","isMounted","AdTogether","fetchAd","then","ad","catch","err","console","error","current","trackImpression","id","token","handlePress","trackClick","clickUrl","Linking","openURL","jsx","View","styles","container","isDarkMode","bgColor","borderColor","textColor","descColor","jsxs","TouchableOpacity","activeOpacity","onPress","backgroundColor","children","imageUrl","imageContainer","Image","source","uri","image","resizeMode","textContainer","headerRow","Text","title","color","numberOfLines","adBadge","adBadgeText","description","exports","StyleSheet","create","flexDirection","width","minHeight","borderRadius","borderWidth","overflow","shadowColor","shadowOffset","height","shadowOpacity","shadowRadius","elevation","padding","flex","justifyContent","alignItems","marginBottom","fontWeight","fontSize","paddingHorizontal","paddingVertical","marginLeft"],"sourceRoot":"..\\..\\src","sources":["AdTogetherBanner.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAA0C,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAD,wBAAAK,CAAA,EAAAC,CAAA,6B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C;EACDrB,WAAW,EAAE;IACXsB,QAAQ,EAAE;EACZ;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AdTogetherInterstitial = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _AdTogether = require("./AdTogether");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
|
+
const AdTogetherInterstitial = ({
|
|
13
|
+
adUnitId,
|
|
14
|
+
isOpen,
|
|
15
|
+
onClose,
|
|
16
|
+
closeDelay = 3,
|
|
17
|
+
onAdLoaded,
|
|
18
|
+
onAdFailedToLoad,
|
|
19
|
+
theme = 'auto'
|
|
20
|
+
}) => {
|
|
21
|
+
const [adData, setAdData] = (0, _react.useState)(null);
|
|
22
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(true);
|
|
23
|
+
const [hasError, setHasError] = (0, _react.useState)(false);
|
|
24
|
+
const [timeLeft, setTimeLeft] = (0, _react.useState)(closeDelay);
|
|
25
|
+
const systemColorScheme = (0, _reactNative.useColorScheme)();
|
|
26
|
+
const impressionTrackedRef = (0, _react.useRef)(false);
|
|
27
|
+
(0, _react.useEffect)(() => {
|
|
28
|
+
if (!isOpen) return;
|
|
29
|
+
let isMounted = true;
|
|
30
|
+
setIsLoading(true);
|
|
31
|
+
setHasError(false);
|
|
32
|
+
setTimeLeft(closeDelay);
|
|
33
|
+
impressionTrackedRef.current = false;
|
|
34
|
+
_AdTogether.AdTogether.fetchAd(adUnitId, 'interstitial').then(ad => {
|
|
35
|
+
if (isMounted) {
|
|
36
|
+
setAdData(ad);
|
|
37
|
+
setIsLoading(false);
|
|
38
|
+
onAdLoaded?.();
|
|
39
|
+
}
|
|
40
|
+
}).catch(err => {
|
|
41
|
+
if (isMounted) {
|
|
42
|
+
console.error('AdTogether Interstitial Failed:', err);
|
|
43
|
+
setHasError(true);
|
|
44
|
+
setIsLoading(false);
|
|
45
|
+
onAdFailedToLoad?.(err);
|
|
46
|
+
onClose(); // Automatically close on error
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return () => {
|
|
50
|
+
isMounted = false;
|
|
51
|
+
};
|
|
52
|
+
}, [adUnitId, isOpen, closeDelay, onAdLoaded, onAdFailedToLoad, onClose]);
|
|
53
|
+
|
|
54
|
+
// Track impression and start timer
|
|
55
|
+
(0, _react.useEffect)(() => {
|
|
56
|
+
if (isOpen && adData && !isLoading && !hasError && !impressionTrackedRef.current) {
|
|
57
|
+
impressionTrackedRef.current = true;
|
|
58
|
+
_AdTogether.AdTogether.trackImpression(adData.id, adData.token);
|
|
59
|
+
const timer = setInterval(() => {
|
|
60
|
+
setTimeLeft(prev => {
|
|
61
|
+
if (prev <= 1) {
|
|
62
|
+
clearInterval(timer);
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
return prev - 1;
|
|
66
|
+
});
|
|
67
|
+
}, 1000);
|
|
68
|
+
return () => clearInterval(timer);
|
|
69
|
+
}
|
|
70
|
+
}, [isOpen, adData, isLoading, hasError]);
|
|
71
|
+
const handlePress = () => {
|
|
72
|
+
if (!adData) return;
|
|
73
|
+
_AdTogether.AdTogether.trackClick(adData.id, adData.token);
|
|
74
|
+
if (adData.clickUrl) {
|
|
75
|
+
_reactNative.Linking.openURL(adData.clickUrl).catch(console.error);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
if (!isOpen || isLoading || hasError || !adData) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const isDarkMode = theme === 'auto' ? systemColorScheme === 'dark' : theme === 'dark';
|
|
82
|
+
const bgColor = isDarkMode ? '#111827' : '#ffffff';
|
|
83
|
+
const textColor = isDarkMode ? '#F9FAFB' : '#111827';
|
|
84
|
+
const descColor = isDarkMode ? '#9CA3AF' : '#6B7280';
|
|
85
|
+
const buttonBgColor = isDarkMode ? '#374151' : '#F3F4F6';
|
|
86
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Modal, {
|
|
87
|
+
visible: isOpen,
|
|
88
|
+
animationType: "slide",
|
|
89
|
+
transparent: false,
|
|
90
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.SafeAreaView, {
|
|
91
|
+
style: [styles.container, {
|
|
92
|
+
backgroundColor: bgColor
|
|
93
|
+
}],
|
|
94
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
95
|
+
style: styles.header,
|
|
96
|
+
children: timeLeft > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
97
|
+
style: [styles.closeButton, {
|
|
98
|
+
backgroundColor: buttonBgColor
|
|
99
|
+
}],
|
|
100
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
101
|
+
style: {
|
|
102
|
+
color: descColor,
|
|
103
|
+
fontWeight: 'bold'
|
|
104
|
+
},
|
|
105
|
+
children: timeLeft
|
|
106
|
+
})
|
|
107
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, {
|
|
108
|
+
onPress: onClose,
|
|
109
|
+
style: [styles.closeButton, {
|
|
110
|
+
backgroundColor: buttonBgColor
|
|
111
|
+
}],
|
|
112
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
113
|
+
style: {
|
|
114
|
+
color: textColor,
|
|
115
|
+
fontWeight: 'bold',
|
|
116
|
+
fontSize: 16
|
|
117
|
+
},
|
|
118
|
+
children: "\u2715"
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.TouchableOpacity, {
|
|
122
|
+
activeOpacity: 0.9,
|
|
123
|
+
style: styles.content,
|
|
124
|
+
onPress: handlePress,
|
|
125
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
126
|
+
style: styles.imageWrapper,
|
|
127
|
+
children: adData.imageUrl ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Image, {
|
|
128
|
+
source: {
|
|
129
|
+
uri: adData.imageUrl
|
|
130
|
+
},
|
|
131
|
+
style: styles.image,
|
|
132
|
+
resizeMode: "contain"
|
|
133
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
134
|
+
style: [styles.imagePlaceholder, {
|
|
135
|
+
backgroundColor: isDarkMode ? '#1F2937' : '#E5E7EB'
|
|
136
|
+
}]
|
|
137
|
+
})
|
|
138
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
139
|
+
style: styles.textWrapper,
|
|
140
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
141
|
+
style: styles.adBadge,
|
|
142
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
143
|
+
style: styles.adBadgeText,
|
|
144
|
+
children: "Advertisement"
|
|
145
|
+
})
|
|
146
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
147
|
+
style: [styles.title, {
|
|
148
|
+
color: textColor
|
|
149
|
+
}],
|
|
150
|
+
children: adData.title
|
|
151
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
152
|
+
style: [styles.description, {
|
|
153
|
+
color: descColor
|
|
154
|
+
}],
|
|
155
|
+
children: adData.description
|
|
156
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
157
|
+
style: styles.ctaButton,
|
|
158
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
159
|
+
style: styles.ctaText,
|
|
160
|
+
children: "Learn More"
|
|
161
|
+
})
|
|
162
|
+
})]
|
|
163
|
+
})]
|
|
164
|
+
})]
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
exports.AdTogetherInterstitial = AdTogetherInterstitial;
|
|
169
|
+
const styles = _reactNative.StyleSheet.create({
|
|
170
|
+
container: {
|
|
171
|
+
flex: 1
|
|
172
|
+
},
|
|
173
|
+
header: {
|
|
174
|
+
flexDirection: 'row',
|
|
175
|
+
justifyContent: 'flex-end',
|
|
176
|
+
padding: 16,
|
|
177
|
+
zIndex: 10
|
|
178
|
+
},
|
|
179
|
+
closeButton: {
|
|
180
|
+
width: 32,
|
|
181
|
+
height: 32,
|
|
182
|
+
borderRadius: 16,
|
|
183
|
+
alignItems: 'center',
|
|
184
|
+
justifyContent: 'center'
|
|
185
|
+
},
|
|
186
|
+
content: {
|
|
187
|
+
flex: 1,
|
|
188
|
+
padding: 24,
|
|
189
|
+
paddingTop: 0,
|
|
190
|
+
alignItems: 'center',
|
|
191
|
+
justifyContent: 'center'
|
|
192
|
+
},
|
|
193
|
+
imageWrapper: {
|
|
194
|
+
width: '100%',
|
|
195
|
+
aspectRatio: 1,
|
|
196
|
+
marginBottom: 32,
|
|
197
|
+
shadowColor: '#000',
|
|
198
|
+
shadowOffset: {
|
|
199
|
+
width: 0,
|
|
200
|
+
height: 10
|
|
201
|
+
},
|
|
202
|
+
shadowOpacity: 0.1,
|
|
203
|
+
shadowRadius: 20,
|
|
204
|
+
elevation: 5
|
|
205
|
+
},
|
|
206
|
+
image: {
|
|
207
|
+
width: '100%',
|
|
208
|
+
height: '100%',
|
|
209
|
+
borderRadius: 16
|
|
210
|
+
},
|
|
211
|
+
imagePlaceholder: {
|
|
212
|
+
width: '100%',
|
|
213
|
+
height: '100%',
|
|
214
|
+
borderRadius: 16
|
|
215
|
+
},
|
|
216
|
+
textWrapper: {
|
|
217
|
+
alignItems: 'center',
|
|
218
|
+
width: '100%'
|
|
219
|
+
},
|
|
220
|
+
adBadge: {
|
|
221
|
+
backgroundColor: '#FBBF24',
|
|
222
|
+
paddingHorizontal: 8,
|
|
223
|
+
paddingVertical: 4,
|
|
224
|
+
borderRadius: 6,
|
|
225
|
+
marginBottom: 16
|
|
226
|
+
},
|
|
227
|
+
adBadgeText: {
|
|
228
|
+
color: '#000',
|
|
229
|
+
fontSize: 10,
|
|
230
|
+
fontWeight: '900',
|
|
231
|
+
textTransform: 'uppercase'
|
|
232
|
+
},
|
|
233
|
+
title: {
|
|
234
|
+
fontSize: 24,
|
|
235
|
+
fontWeight: 'bold',
|
|
236
|
+
textAlign: 'center',
|
|
237
|
+
marginBottom: 12
|
|
238
|
+
},
|
|
239
|
+
description: {
|
|
240
|
+
fontSize: 16,
|
|
241
|
+
textAlign: 'center',
|
|
242
|
+
lineHeight: 24,
|
|
243
|
+
marginBottom: 32
|
|
244
|
+
},
|
|
245
|
+
ctaButton: {
|
|
246
|
+
backgroundColor: '#3B82F6',
|
|
247
|
+
paddingHorizontal: 32,
|
|
248
|
+
paddingVertical: 16,
|
|
249
|
+
borderRadius: 12,
|
|
250
|
+
width: '100%',
|
|
251
|
+
alignItems: 'center'
|
|
252
|
+
},
|
|
253
|
+
ctaText: {
|
|
254
|
+
color: '#FFFFFF',
|
|
255
|
+
fontSize: 16,
|
|
256
|
+
fontWeight: 'bold'
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=AdTogetherInterstitial.js.map
|