@bigcrunch/react-native-ads 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.
Files changed (52) hide show
  1. package/README.md +417 -0
  2. package/android/build.gradle +70 -0
  3. package/android/settings.gradle +6 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchAdsModule.kt +653 -0
  6. package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchAdsPackage.kt +20 -0
  7. package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchBannerViewManager.kt +296 -0
  8. package/ios/BigCrunchAdsModule.swift +588 -0
  9. package/ios/BigCrunchBannerViewManager.swift +270 -0
  10. package/ios/react-native-bigcrunch-ads-Bridging-Header.h +8 -0
  11. package/lib/BigCrunchAds.d.ts +168 -0
  12. package/lib/BigCrunchAds.d.ts.map +1 -0
  13. package/lib/BigCrunchAds.js +241 -0
  14. package/lib/BigCrunchBannerView.d.ts +21 -0
  15. package/lib/BigCrunchBannerView.d.ts.map +1 -0
  16. package/lib/BigCrunchBannerView.js +176 -0
  17. package/lib/BigCrunchInterstitial.d.ts +66 -0
  18. package/lib/BigCrunchInterstitial.d.ts.map +1 -0
  19. package/lib/BigCrunchInterstitial.js +222 -0
  20. package/lib/BigCrunchRewarded.d.ts +85 -0
  21. package/lib/BigCrunchRewarded.d.ts.map +1 -0
  22. package/lib/BigCrunchRewarded.js +257 -0
  23. package/lib/NativeBigCrunchAds.d.ts +71 -0
  24. package/lib/NativeBigCrunchAds.d.ts.map +1 -0
  25. package/lib/NativeBigCrunchAds.js +54 -0
  26. package/lib/index.d.ts +28 -0
  27. package/lib/index.d.ts.map +1 -0
  28. package/lib/index.js +32 -0
  29. package/lib/types/ads.d.ts +101 -0
  30. package/lib/types/ads.d.ts.map +1 -0
  31. package/lib/types/ads.js +4 -0
  32. package/lib/types/config.d.ts +137 -0
  33. package/lib/types/config.d.ts.map +1 -0
  34. package/lib/types/config.js +4 -0
  35. package/lib/types/events.d.ts +306 -0
  36. package/lib/types/events.d.ts.map +1 -0
  37. package/lib/types/events.js +4 -0
  38. package/lib/types/index.d.ts +175 -0
  39. package/lib/types/index.d.ts.map +1 -0
  40. package/lib/types/index.js +23 -0
  41. package/package.json +88 -0
  42. package/react-native-bigcrunch-ads.podspec +27 -0
  43. package/src/BigCrunchAds.ts +298 -0
  44. package/src/BigCrunchBannerView.tsx +262 -0
  45. package/src/BigCrunchInterstitial.ts +266 -0
  46. package/src/BigCrunchRewarded.ts +307 -0
  47. package/src/NativeBigCrunchAds.ts +120 -0
  48. package/src/index.ts +71 -0
  49. package/src/types/ads.ts +112 -0
  50. package/src/types/config.ts +145 -0
  51. package/src/types/events.ts +337 -0
  52. package/src/types/index.ts +193 -0
package/README.md ADDED
@@ -0,0 +1,417 @@
1
+ # BigCrunch Mobile Ads SDK for React Native
2
+
3
+ Simplified in-app advertising for React Native apps with Prebid and Google Ad Manager integration.
4
+
5
+ ## Features
6
+
7
+ - 🎯 **Simple Integration**: One SDK to handle Prebid, Google Ad Manager, and Amazon demand
8
+ - 📊 **Built-in Analytics**: Automatic tracking of impressions, clicks, and revenue
9
+ - 💰 **Revenue Optimization**: Server-side header bidding via Prebid Server
10
+ - 🔧 **Configuration-Driven**: Manage placements from BigCrunch dashboard
11
+ - 📱 **Cross-Platform**: Supports both iOS and Android
12
+ - 🎨 **Ad Formats**: Banner, Interstitial, and Rewarded ads
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @bigcrunch/react-native-ads
18
+ # or
19
+ yarn add @bigcrunch/react-native-ads
20
+ ```
21
+
22
+ ### iOS Setup
23
+
24
+ ```bash
25
+ cd ios && pod install
26
+ ```
27
+
28
+ Add the following to your `Info.plist`:
29
+
30
+ ```xml
31
+ <key>GADApplicationIdentifier</key>
32
+ <string>YOUR_ADMOB_APP_ID</string>
33
+
34
+ <key>SKAdNetworkItems</key>
35
+ <array>
36
+ <!-- Add SKAdNetwork identifiers -->
37
+ </array>
38
+ ```
39
+
40
+ ### Android Setup
41
+
42
+ Add the following to your `AndroidManifest.xml`:
43
+
44
+ ```xml
45
+ <meta-data
46
+ android:name="com.google.android.gms.ads.APPLICATION_ID"
47
+ android:value="YOUR_ADMOB_APP_ID"/>
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ### 1. Initialize the SDK
53
+
54
+ ```typescript
55
+ import { BigCrunchAds } from '@bigcrunch/react-native-ads';
56
+
57
+ // Initialize at app startup (e.g., in App.tsx)
58
+ async function initializeAds() {
59
+ try {
60
+ await BigCrunchAds.initialize(
61
+ 'your-property-id',
62
+ 'your-api-key',
63
+ 'production' // or 'sandbox'
64
+ );
65
+ console.log('BigCrunch Ads initialized successfully');
66
+ } catch (error) {
67
+ console.error('Failed to initialize BigCrunch Ads:', error);
68
+ }
69
+ }
70
+
71
+ // Call on app launch
72
+ initializeAds();
73
+ ```
74
+
75
+ ### 2. Track Screen Views
76
+
77
+ ```typescript
78
+ import { BigCrunchAds } from '@bigcrunch/react-native-ads';
79
+
80
+ // Track screen views for analytics
81
+ BigCrunchAds.trackScreenView('HomeScreen');
82
+ ```
83
+
84
+ ## Ad Formats
85
+
86
+ ### Banner Ads
87
+
88
+ ```tsx
89
+ import { BigCrunchBannerView } from '@bigcrunch/react-native-ads';
90
+
91
+ function HomeScreen() {
92
+ return (
93
+ <View>
94
+ {/* Your content */}
95
+
96
+ <BigCrunchBannerView
97
+ placementId="banner-home"
98
+ size="BANNER" // or "MEDIUM_RECTANGLE", "ADAPTIVE", etc.
99
+ style={{ alignSelf: 'center' }}
100
+ onAdLoaded={() => console.log('Banner loaded')}
101
+ onAdFailedToLoad={(error) => console.error('Banner failed:', error)}
102
+ onAdRevenue={(revenue) => console.log('Revenue:', revenue)}
103
+ />
104
+ </View>
105
+ );
106
+ }
107
+ ```
108
+
109
+ #### Available Banner Sizes
110
+
111
+ - `BANNER` - 320x50
112
+ - `LARGE_BANNER` - 320x100
113
+ - `MEDIUM_RECTANGLE` - 300x250
114
+ - `FULL_BANNER` - 468x60
115
+ - `LEADERBOARD` - 728x90
116
+ - `ADAPTIVE` - Adaptive banner (recommended)
117
+ - Custom size: `{ width: 300, height: 250 }`
118
+
119
+ ### Interstitial Ads
120
+
121
+ ```typescript
122
+ import { BigCrunchInterstitial } from '@bigcrunch/react-native-ads';
123
+
124
+ // Load an interstitial
125
+ async function loadInterstitial() {
126
+ try {
127
+ await BigCrunchInterstitial.load({
128
+ placementId: 'interstitial-level-complete'
129
+ });
130
+ console.log('Interstitial loaded');
131
+ } catch (error) {
132
+ console.error('Failed to load interstitial:', error);
133
+ }
134
+ }
135
+
136
+ // Show the interstitial
137
+ async function showInterstitial() {
138
+ const isLoaded = await BigCrunchInterstitial.isLoaded('interstitial-level-complete');
139
+
140
+ if (isLoaded) {
141
+ await BigCrunchInterstitial.show('interstitial-level-complete');
142
+ }
143
+ }
144
+
145
+ // Listen for events
146
+ BigCrunchInterstitial.addEventListener(
147
+ 'interstitial-level-complete',
148
+ 'adClosed',
149
+ () => {
150
+ console.log('Interstitial closed');
151
+ // Load next ad or continue game
152
+ }
153
+ );
154
+ ```
155
+
156
+ ### Rewarded Ads
157
+
158
+ ```typescript
159
+ import { BigCrunchRewarded } from '@bigcrunch/react-native-ads';
160
+
161
+ // Load a rewarded ad
162
+ async function loadRewardedAd() {
163
+ try {
164
+ await BigCrunchRewarded.load({
165
+ placementId: 'rewarded-extra-life'
166
+ });
167
+ console.log('Rewarded ad loaded');
168
+ } catch (error) {
169
+ console.error('Failed to load rewarded ad:', error);
170
+ }
171
+ }
172
+
173
+ // Set up reward listener
174
+ BigCrunchRewarded.addEventListener(
175
+ 'rewarded-extra-life',
176
+ 'rewardEarned',
177
+ (event) => {
178
+ console.log(`User earned ${event.rewardAmount} ${event.rewardType}`);
179
+ // Grant reward to user
180
+ }
181
+ );
182
+
183
+ // Show the rewarded ad
184
+ async function showRewardedAd() {
185
+ const isLoaded = await BigCrunchRewarded.isLoaded('rewarded-extra-life');
186
+
187
+ if (isLoaded) {
188
+ await BigCrunchRewarded.show('rewarded-extra-life');
189
+ } else {
190
+ console.log('Rewarded ad not ready');
191
+ }
192
+ }
193
+ ```
194
+
195
+ ## Advanced Features
196
+
197
+ ### Custom Targeting
198
+
199
+ ```typescript
200
+ // Banner with custom targeting
201
+ <BigCrunchBannerView
202
+ placementId="banner-home"
203
+ customTargeting={{
204
+ 'user_level': '5',
205
+ 'game_mode': 'survival'
206
+ }}
207
+ />
208
+
209
+ // Interstitial with custom targeting
210
+ await BigCrunchInterstitial.load({
211
+ placementId: 'interstitial-level-complete',
212
+ customTargeting: {
213
+ 'level': '10',
214
+ 'score': 'high'
215
+ }
216
+ });
217
+ ```
218
+
219
+ ### Privacy Settings
220
+
221
+ ```typescript
222
+ // GDPR Consent
223
+ await BigCrunchAds.setGdprConsent('consent_string_here');
224
+
225
+ // CCPA Compliance
226
+ await BigCrunchAds.setCcpaString('1YNN');
227
+
228
+ // COPPA Compliance
229
+ await BigCrunchAds.setCoppaCompliant(true);
230
+ ```
231
+
232
+ ### Debug Mode & Test Devices
233
+
234
+ ```typescript
235
+ // Enable debug mode
236
+ await BigCrunchAds.setDebugMode(true);
237
+
238
+ // Add test devices
239
+ await BigCrunchAds.addTestDevice('YOUR_DEVICE_ID');
240
+ ```
241
+
242
+ ### Event Listeners
243
+
244
+ ```typescript
245
+ // Global configuration events
246
+ BigCrunchAds.onConfigUpdated((config) => {
247
+ console.log('Config updated:', config);
248
+ });
249
+
250
+ // Session events
251
+ BigCrunchAds.onSessionStarted((session) => {
252
+ console.log('New session started:', session.sessionId);
253
+ });
254
+
255
+ // Ad-specific events
256
+ const subscription = BigCrunchInterstitial.addEventListener(
257
+ 'interstitial-main',
258
+ 'adRevenue',
259
+ (event) => {
260
+ console.log('Revenue received:', event.revenue);
261
+ }
262
+ );
263
+
264
+ // Remove listener when done
265
+ subscription.remove();
266
+ ```
267
+
268
+ ## TypeScript Support
269
+
270
+ The SDK includes full TypeScript definitions:
271
+
272
+ ```typescript
273
+ import type {
274
+ AdError,
275
+ AdRevenue,
276
+ BannerSize,
277
+ PlacementConfig,
278
+ SessionInfo
279
+ } from '@bigcrunch/react-native-ads';
280
+ ```
281
+
282
+ ## API Reference
283
+
284
+ ### BigCrunchAds
285
+
286
+ | Method | Description |
287
+ |--------|-------------|
288
+ | `initialize(propertyId, apiKey, environment)` | Initialize the SDK |
289
+ | `trackScreenView(screenName)` | Track a screen view |
290
+ | `getAppConfig()` | Get current app configuration |
291
+ | `getSessionInfo()` | Get current session information |
292
+ | `setGdprConsent(consent)` | Set GDPR consent string |
293
+ | `setCcpaString(ccpaString)` | Set CCPA compliance string |
294
+ | `setCoppaCompliant(isCompliant)` | Set COPPA compliance |
295
+ | `setDebugMode(enabled)` | Enable/disable debug mode |
296
+
297
+ ### BigCrunchBannerView Props
298
+
299
+ | Prop | Type | Description |
300
+ |------|------|-------------|
301
+ | `placementId` | string | Required. Placement ID from dashboard |
302
+ | `size` | BannerSize \| CustomSize | Banner size (default: BANNER) |
303
+ | `autoLoad` | boolean | Auto-load ad on mount (default: true) |
304
+ | `refreshInterval` | number | Auto-refresh interval in seconds |
305
+ | `customTargeting` | object | Custom targeting parameters |
306
+ | `onAdLoaded` | function | Called when ad loads |
307
+ | `onAdFailedToLoad` | function | Called on load failure |
308
+ | `onAdImpression` | function | Called on impression |
309
+ | `onAdClicked` | function | Called on click |
310
+ | `onAdRevenue` | function | Called on revenue (ILRD) |
311
+
312
+ ### BigCrunchInterstitial
313
+
314
+ | Method | Description |
315
+ |--------|-------------|
316
+ | `load(options)` | Load an interstitial ad |
317
+ | `show(placementId)` | Show a loaded interstitial |
318
+ | `isLoaded(placementId)` | Check if ad is loaded |
319
+ | `destroy(placementId)` | Destroy an interstitial instance |
320
+ | `addEventListener(placementId, event, listener)` | Add event listener |
321
+
322
+ ### BigCrunchRewarded
323
+
324
+ | Method | Description |
325
+ |--------|-------------|
326
+ | `load(options)` | Load a rewarded ad |
327
+ | `show(placementId)` | Show a loaded rewarded ad |
328
+ | `isLoaded(placementId)` | Check if ad is loaded |
329
+ | `destroy(placementId)` | Destroy a rewarded instance |
330
+ | `addEventListener(placementId, event, listener)` | Add event listener |
331
+ | `onRewardEarned(placementId, listener)` | Listen for rewards |
332
+
333
+ ## Error Handling
334
+
335
+ ```typescript
336
+ import { AdErrorCode } from '@bigcrunch/react-native-ads';
337
+
338
+ // Handle banner errors
339
+ <BigCrunchBannerView
340
+ placementId="banner-home"
341
+ onAdFailedToLoad={(error) => {
342
+ switch (error.code) {
343
+ case AdErrorCode.NO_FILL:
344
+ console.log('No ads available');
345
+ break;
346
+ case AdErrorCode.NETWORK_ERROR:
347
+ console.log('Network error');
348
+ break;
349
+ case AdErrorCode.INVALID_PLACEMENT:
350
+ console.log('Invalid placement ID');
351
+ break;
352
+ default:
353
+ console.error('Ad error:', error.message);
354
+ }
355
+ }}
356
+ />
357
+ ```
358
+
359
+ ## Example App
360
+
361
+ Check out the [example app](./example) for a complete implementation:
362
+
363
+ ```bash
364
+ cd react-native/example
365
+ npm install
366
+ npm run ios # or npm run android
367
+ ```
368
+
369
+ ## Troubleshooting
370
+
371
+ ### iOS Issues
372
+
373
+ 1. **Module not found**: Run `cd ios && pod install`
374
+ 2. **Build failures**: Clean build folder and rebuild
375
+ 3. **App crashes on launch**: Verify GADApplicationIdentifier in Info.plist
376
+
377
+ ### Android Issues
378
+
379
+ 1. **Manifest merger failed**: Check APPLICATION_ID in AndroidManifest.xml
380
+ 2. **Build failures**: Sync project with Gradle files
381
+ 3. **MultiDex issues**: Enable multidex in your app
382
+
383
+ ### Common Issues
384
+
385
+ 1. **Ads not loading**:
386
+ - Verify initialization is complete
387
+ - Check placement IDs match dashboard
388
+ - Ensure test mode is disabled in production
389
+
390
+ 2. **Revenue not tracking**:
391
+ - Verify ILRD is enabled in Google Ad Manager
392
+ - Check revenue event listeners are set up
393
+
394
+ 3. **TypeScript errors**:
395
+ - Update to latest version
396
+ - Rebuild TypeScript definitions: `npm run typescript`
397
+
398
+ ## Requirements
399
+
400
+ - React Native 0.60+
401
+ - iOS 13.0+
402
+ - Android API 21+
403
+ - TypeScript 4.0+ (optional)
404
+
405
+ ## License
406
+
407
+ MIT
408
+
409
+ ## Support
410
+
411
+ - Documentation: https://docs.bigcrunch.com/mobile-ads-sdk
412
+ - Issues: https://github.com/bigcrunch/mobile-ads-sdk/issues
413
+ - Email: support@bigcrunch.com
414
+
415
+ ## Contributing
416
+
417
+ See [CONTRIBUTING.md](../CONTRIBUTING.md) for details.
@@ -0,0 +1,70 @@
1
+ buildscript {
2
+ ext.kotlin_version = '1.7.10'
3
+
4
+ repositories {
5
+ google()
6
+ mavenCentral()
7
+ }
8
+
9
+ dependencies {
10
+ classpath 'com.android.tools.build:gradle:7.3.1'
11
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12
+ }
13
+ }
14
+
15
+ apply plugin: 'com.android.library'
16
+ apply plugin: 'kotlin-android'
17
+
18
+ def safeExtGet(prop, fallback) {
19
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
20
+ }
21
+
22
+ android {
23
+ compileSdkVersion safeExtGet('compileSdkVersion', 34)
24
+ namespace 'com.bigcrunch.ads.react'
25
+
26
+ defaultConfig {
27
+ minSdkVersion safeExtGet('minSdkVersion', 21)
28
+ targetSdkVersion safeExtGet('targetSdkVersion', 34)
29
+ versionCode 1
30
+ versionName "0.1.0"
31
+ }
32
+
33
+ buildTypes {
34
+ release {
35
+ minifyEnabled false
36
+ }
37
+ }
38
+
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_1_8
41
+ targetCompatibility JavaVersion.VERSION_1_8
42
+ }
43
+
44
+ kotlinOptions {
45
+ jvmTarget = '1.8'
46
+ freeCompilerArgs += ['-Xskip-metadata-version-check']
47
+ }
48
+ }
49
+
50
+ repositories {
51
+ google()
52
+ mavenCentral()
53
+ maven { url "https://jitpack.io" }
54
+ }
55
+
56
+ dependencies {
57
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
58
+
59
+ // React Native dependency
60
+ implementation 'com.facebook.react:react-native:+'
61
+
62
+ // Native Android SDK dependency
63
+ // This includes all required dependencies (Google Ads, Prebid, OkHttp, Moshi)
64
+ // as transitive dependencies, eliminating the need for duplication
65
+ implementation project(':bigcrunch-ads')
66
+
67
+ // Coroutines - needed by React Native bridge code
68
+ // (Native SDK uses 'implementation' so not automatically transitive)
69
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
70
+ }
@@ -0,0 +1,6 @@
1
+ // Include the native Android SDK module from the parent directory
2
+ // This allows the React Native Android module to depend on the native SDK
3
+ // and eliminates code duplication
4
+
5
+ include ':bigcrunch-ads'
6
+ project(':bigcrunch-ads').projectDir = new File(rootProject.projectDir, '../../android/bigcrunch-ads')
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.bigcrunch.ads.react">
3
+ </manifest>