@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.
- package/README.md +417 -0
- package/android/build.gradle +70 -0
- package/android/settings.gradle +6 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchAdsModule.kt +653 -0
- package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchAdsPackage.kt +20 -0
- package/android/src/main/java/com/bigcrunch/ads/react/BigCrunchBannerViewManager.kt +296 -0
- package/ios/BigCrunchAdsModule.swift +588 -0
- package/ios/BigCrunchBannerViewManager.swift +270 -0
- package/ios/react-native-bigcrunch-ads-Bridging-Header.h +8 -0
- package/lib/BigCrunchAds.d.ts +168 -0
- package/lib/BigCrunchAds.d.ts.map +1 -0
- package/lib/BigCrunchAds.js +241 -0
- package/lib/BigCrunchBannerView.d.ts +21 -0
- package/lib/BigCrunchBannerView.d.ts.map +1 -0
- package/lib/BigCrunchBannerView.js +176 -0
- package/lib/BigCrunchInterstitial.d.ts +66 -0
- package/lib/BigCrunchInterstitial.d.ts.map +1 -0
- package/lib/BigCrunchInterstitial.js +222 -0
- package/lib/BigCrunchRewarded.d.ts +85 -0
- package/lib/BigCrunchRewarded.d.ts.map +1 -0
- package/lib/BigCrunchRewarded.js +257 -0
- package/lib/NativeBigCrunchAds.d.ts +71 -0
- package/lib/NativeBigCrunchAds.d.ts.map +1 -0
- package/lib/NativeBigCrunchAds.js +54 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +32 -0
- package/lib/types/ads.d.ts +101 -0
- package/lib/types/ads.d.ts.map +1 -0
- package/lib/types/ads.js +4 -0
- package/lib/types/config.d.ts +137 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +4 -0
- package/lib/types/events.d.ts +306 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/events.js +4 -0
- package/lib/types/index.d.ts +175 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +23 -0
- package/package.json +88 -0
- package/react-native-bigcrunch-ads.podspec +27 -0
- package/src/BigCrunchAds.ts +298 -0
- package/src/BigCrunchBannerView.tsx +262 -0
- package/src/BigCrunchInterstitial.ts +266 -0
- package/src/BigCrunchRewarded.ts +307 -0
- package/src/NativeBigCrunchAds.ts +120 -0
- package/src/index.ts +71 -0
- package/src/types/ads.ts +112 -0
- package/src/types/config.ts +145 -0
- package/src/types/events.ts +337 -0
- package/src/types/index.ts +193 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import React
|
|
3
|
+
import UIKit
|
|
4
|
+
import BigCrunchAds
|
|
5
|
+
import GoogleMobileAds
|
|
6
|
+
|
|
7
|
+
@objc(BigCrunchBannerViewManager)
|
|
8
|
+
class BigCrunchBannerViewManager: RCTViewManager {
|
|
9
|
+
|
|
10
|
+
override static func requiresMainQueueSetup() -> Bool {
|
|
11
|
+
return true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override func view() -> UIView! {
|
|
15
|
+
let wrapper = BigCrunchBannerViewWrapper()
|
|
16
|
+
wrapper.bridge = self.bridge
|
|
17
|
+
return wrapper
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Note: Property setters are handled automatically by RCT_EXPORT_VIEW_PROPERTY
|
|
21
|
+
// which sets @objc properties directly on the view
|
|
22
|
+
|
|
23
|
+
// MARK: - Command Methods
|
|
24
|
+
|
|
25
|
+
@objc func loadAd(_ node: NSNumber) {
|
|
26
|
+
DispatchQueue.main.async { [weak self] in
|
|
27
|
+
guard let view = self?.bridge?.uiManager?.view(forReactTag: node) as? BigCrunchBannerViewWrapper else { return }
|
|
28
|
+
view.loadAd()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@objc func pauseAd(_ node: NSNumber) {
|
|
33
|
+
// Pause functionality not implemented in current SDK version
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc func resumeAd(_ node: NSNumber) {
|
|
37
|
+
// Resume functionality not implemented in current SDK version
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@objc func destroy(_ node: NSNumber) {
|
|
41
|
+
DispatchQueue.main.async { [weak self] in
|
|
42
|
+
guard let view = self?.bridge?.uiManager?.view(forReactTag: node) as? BigCrunchBannerViewWrapper else { return }
|
|
43
|
+
view.destroy()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// MARK: - BigCrunchBannerViewWrapper
|
|
49
|
+
|
|
50
|
+
class BigCrunchBannerViewWrapper: UIView {
|
|
51
|
+
|
|
52
|
+
var bannerView: BigCrunchBannerView?
|
|
53
|
+
|
|
54
|
+
@objc var placementId: String? {
|
|
55
|
+
didSet {
|
|
56
|
+
if placementId != oldValue {
|
|
57
|
+
setupBannerView()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// React Native sets "size" prop but we store as sizeString
|
|
63
|
+
@objc var size: String {
|
|
64
|
+
get { return sizeString }
|
|
65
|
+
set {
|
|
66
|
+
sizeString = newValue
|
|
67
|
+
updateAdSize()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var sizeString: String = "BANNER"
|
|
72
|
+
@objc var customWidth: NSNumber? {
|
|
73
|
+
didSet {
|
|
74
|
+
_customWidth = customWidth?.intValue
|
|
75
|
+
updateAdSize()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
private var _customWidth: Int?
|
|
79
|
+
|
|
80
|
+
@objc var customHeight: NSNumber? {
|
|
81
|
+
didSet {
|
|
82
|
+
_customHeight = customHeight?.intValue
|
|
83
|
+
updateAdSize()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
private var _customHeight: Int?
|
|
87
|
+
|
|
88
|
+
@objc var autoLoad: Bool = false {
|
|
89
|
+
didSet {
|
|
90
|
+
if autoLoad && placementId != nil {
|
|
91
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
|
|
92
|
+
self?.loadAd()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@objc var refreshInterval: NSNumber = 0
|
|
99
|
+
|
|
100
|
+
@objc var customTargeting: NSDictionary? {
|
|
101
|
+
didSet {
|
|
102
|
+
_customTargeting = customTargeting as? [String: String]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
private var _customTargeting: [String: String]?
|
|
106
|
+
|
|
107
|
+
@objc var viewId: String?
|
|
108
|
+
|
|
109
|
+
weak var bridge: RCTBridge?
|
|
110
|
+
|
|
111
|
+
override init(frame: CGRect) {
|
|
112
|
+
super.init(frame: frame)
|
|
113
|
+
backgroundColor = .clear
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
required init?(coder: NSCoder) {
|
|
117
|
+
fatalError("init(coder:) has not been implemented")
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
func setupBannerView() {
|
|
121
|
+
guard let placementId = placementId else { return }
|
|
122
|
+
|
|
123
|
+
// Remove existing banner view
|
|
124
|
+
bannerView?.removeFromSuperview()
|
|
125
|
+
bannerView = nil
|
|
126
|
+
|
|
127
|
+
// Create new banner view
|
|
128
|
+
let newBannerView = BigCrunchBannerView(frame: bounds)
|
|
129
|
+
newBannerView.configure(placementId: placementId)
|
|
130
|
+
newBannerView.delegate = self
|
|
131
|
+
newBannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
132
|
+
|
|
133
|
+
addSubview(newBannerView)
|
|
134
|
+
|
|
135
|
+
// Add constraints
|
|
136
|
+
NSLayoutConstraint.activate([
|
|
137
|
+
newBannerView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
138
|
+
newBannerView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
139
|
+
newBannerView.topAnchor.constraint(equalTo: topAnchor),
|
|
140
|
+
newBannerView.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
141
|
+
])
|
|
142
|
+
|
|
143
|
+
self.bannerView = newBannerView
|
|
144
|
+
|
|
145
|
+
updateAdSize()
|
|
146
|
+
|
|
147
|
+
if autoLoad {
|
|
148
|
+
loadAd()
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
func updateAdSize() {
|
|
153
|
+
guard let bannerView = bannerView else { return }
|
|
154
|
+
|
|
155
|
+
var adSize: GoogleMobileAds.AdSize
|
|
156
|
+
var sizeOverride: CGSize?
|
|
157
|
+
|
|
158
|
+
if let width = _customWidth, let height = _customHeight {
|
|
159
|
+
sizeOverride = CGSize(width: width, height: height)
|
|
160
|
+
adSize = GoogleMobileAds.adSizeFor(cgSize: sizeOverride!)
|
|
161
|
+
} else {
|
|
162
|
+
switch sizeString {
|
|
163
|
+
case "BANNER":
|
|
164
|
+
sizeOverride = CGSize(width: 320, height: 50)
|
|
165
|
+
adSize = GoogleMobileAds.AdSizeBanner
|
|
166
|
+
case "LARGE_BANNER":
|
|
167
|
+
sizeOverride = CGSize(width: 320, height: 100)
|
|
168
|
+
adSize = GoogleMobileAds.AdSizeLargeBanner
|
|
169
|
+
case "MEDIUM_RECTANGLE":
|
|
170
|
+
sizeOverride = CGSize(width: 300, height: 250)
|
|
171
|
+
adSize = GoogleMobileAds.AdSizeMediumRectangle
|
|
172
|
+
case "FULL_BANNER":
|
|
173
|
+
sizeOverride = CGSize(width: 468, height: 60)
|
|
174
|
+
adSize = GoogleMobileAds.AdSizeFullBanner
|
|
175
|
+
case "LEADERBOARD":
|
|
176
|
+
sizeOverride = CGSize(width: 728, height: 90)
|
|
177
|
+
adSize = GoogleMobileAds.AdSizeLeaderboard
|
|
178
|
+
case "ADAPTIVE":
|
|
179
|
+
let frame = self.frame.width > 0 ? self.frame : UIScreen.main.bounds
|
|
180
|
+
adSize = GoogleMobileAds.currentOrientationAnchoredAdaptiveBanner(width: frame.width)
|
|
181
|
+
sizeOverride = adSize.size
|
|
182
|
+
case "SMART":
|
|
183
|
+
// Smart banner is deprecated, use adaptive
|
|
184
|
+
let frame = self.frame.width > 0 ? self.frame : UIScreen.main.bounds
|
|
185
|
+
adSize = GoogleMobileAds.currentOrientationAnchoredAdaptiveBanner(width: frame.width)
|
|
186
|
+
sizeOverride = adSize.size
|
|
187
|
+
default:
|
|
188
|
+
sizeOverride = CGSize(width: 320, height: 50)
|
|
189
|
+
adSize = GoogleMobileAds.AdSizeBanner
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Set the size override on the native banner view
|
|
194
|
+
bannerView.adSizeOverride = sizeOverride
|
|
195
|
+
|
|
196
|
+
// Update frame constraints
|
|
197
|
+
if _customWidth == nil && _customHeight == nil {
|
|
198
|
+
self.frame.size = adSize.size
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
func loadAd() {
|
|
203
|
+
bannerView?.loadAd()
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
func destroy() {
|
|
207
|
+
bannerView?.destroy()
|
|
208
|
+
bannerView = nil
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
override func removeFromSuperview() {
|
|
212
|
+
destroy()
|
|
213
|
+
super.removeFromSuperview()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
internal override func reactViewController() -> UIViewController? {
|
|
217
|
+
var responder: UIResponder? = self
|
|
218
|
+
while responder != nil {
|
|
219
|
+
if let viewController = responder as? UIViewController {
|
|
220
|
+
return viewController
|
|
221
|
+
}
|
|
222
|
+
responder = responder?.next
|
|
223
|
+
}
|
|
224
|
+
return nil
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private func sendEvent(name: String, params: [String: Any]) {
|
|
228
|
+
var eventParams = params
|
|
229
|
+
eventParams["viewId"] = viewId
|
|
230
|
+
eventParams["placementId"] = placementId
|
|
231
|
+
|
|
232
|
+
// Send event through RCTEventEmitter via the bridge
|
|
233
|
+
guard let bridge = bridge,
|
|
234
|
+
let eventEmitter = bridge.module(for: BigCrunchAdsModule.self) as? RCTEventEmitter else {
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
eventEmitter.sendEvent(withName: name, body: eventParams)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// MARK: - BigCrunchBannerViewDelegate
|
|
242
|
+
|
|
243
|
+
extension BigCrunchBannerViewWrapper: BigCrunchBannerViewDelegate {
|
|
244
|
+
|
|
245
|
+
func bannerViewDidLoadAd(_ bannerView: BigCrunchBannerView) {
|
|
246
|
+
sendEvent(name: "BigCrunchBannerAdLoaded", params: [:])
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
func bannerView(_ bannerView: BigCrunchBannerView, didFailToLoadWithError error: String) {
|
|
250
|
+
sendEvent(name: "BigCrunchBannerAdFailedToLoad", params: [
|
|
251
|
+
"errorCode": "LOAD_FAILED",
|
|
252
|
+
"errorMessage": error
|
|
253
|
+
])
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
func bannerViewDidRecordImpression(_ bannerView: BigCrunchBannerView) {
|
|
257
|
+
sendEvent(name: "BigCrunchBannerAdImpression", params: [:])
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
func bannerViewDidRecordClick(_ bannerView: BigCrunchBannerView) {
|
|
261
|
+
sendEvent(name: "BigCrunchBannerAdClicked", params: [:])
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Note: The native SDK doesn't provide these events yet, but we can add them later
|
|
265
|
+
// when the SDK supports them:
|
|
266
|
+
// - BigCrunchBannerAdOpened
|
|
267
|
+
// - BigCrunchBannerAdClosed
|
|
268
|
+
// - BigCrunchBannerAdRevenue
|
|
269
|
+
// - BigCrunchBannerAdViewable
|
|
270
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigCrunch Mobile Ads SDK for React Native
|
|
3
|
+
* Main API class
|
|
4
|
+
*/
|
|
5
|
+
import type { InitializationOptions, Environment, SessionInfo, DeviceContext, AppConfig, EventSubscription } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Main entry point for BigCrunch Mobile Ads SDK
|
|
8
|
+
*/
|
|
9
|
+
export declare class BigCrunchAds {
|
|
10
|
+
private static isInitializedFlag;
|
|
11
|
+
private static initializationPromise;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize the BigCrunch Ads SDK
|
|
14
|
+
* Must be called before using any other SDK features
|
|
15
|
+
*
|
|
16
|
+
* @param propertyId - Your BigCrunch property ID
|
|
17
|
+
* @param apiKey - Your API key for authentication
|
|
18
|
+
* @param environment - Environment to use (default: 'production')
|
|
19
|
+
* @param options - Additional initialization options
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* await BigCrunchAds.initialize(
|
|
24
|
+
* 'your-property-id',
|
|
25
|
+
* 'your-api-key',
|
|
26
|
+
* 'production'
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
static initialize(propertyId: string, apiKey: string, environment?: Environment, options?: Partial<InitializationOptions>): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Check if the SDK is initialized
|
|
33
|
+
*/
|
|
34
|
+
static isInitialized(): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Track a screen view for analytics
|
|
37
|
+
*
|
|
38
|
+
* @param screenName - Name of the screen being viewed
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* BigCrunchAds.trackScreenView('HomeScreen');
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
static trackScreenView(screenName: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the current app configuration
|
|
48
|
+
* Returns null if config hasn't been loaded yet
|
|
49
|
+
*/
|
|
50
|
+
static getAppConfig(): Promise<AppConfig | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Force refresh the app configuration from backend
|
|
53
|
+
*/
|
|
54
|
+
static refreshConfig(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Get current session information
|
|
57
|
+
*/
|
|
58
|
+
static getSessionInfo(): Promise<SessionInfo>;
|
|
59
|
+
/**
|
|
60
|
+
* Start a new session (usually handled automatically)
|
|
61
|
+
*/
|
|
62
|
+
static startNewSession(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Get device context information
|
|
65
|
+
*/
|
|
66
|
+
static getDeviceContext(): Promise<DeviceContext>;
|
|
67
|
+
/**
|
|
68
|
+
* Set GDPR consent string
|
|
69
|
+
*
|
|
70
|
+
* @param consent - GDPR consent string
|
|
71
|
+
*/
|
|
72
|
+
static setGdprConsent(consent: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Set CCPA compliance string
|
|
75
|
+
*
|
|
76
|
+
* @param ccpaString - CCPA string (e.g., "1YNN")
|
|
77
|
+
*/
|
|
78
|
+
static setCcpaString(ccpaString: string): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Set COPPA compliance
|
|
81
|
+
*
|
|
82
|
+
* @param isCompliant - Whether the app is COPPA compliant
|
|
83
|
+
*/
|
|
84
|
+
static setCoppaCompliant(isCompliant: boolean): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Enable or disable debug mode
|
|
87
|
+
*
|
|
88
|
+
* @param enabled - Whether to enable debug mode
|
|
89
|
+
*/
|
|
90
|
+
static setDebugMode(enabled: boolean): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Add a test device ID for testing ads
|
|
93
|
+
*
|
|
94
|
+
* @param deviceId - Device ID to add as test device
|
|
95
|
+
*/
|
|
96
|
+
static addTestDevice(deviceId: string): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Remove a test device ID
|
|
99
|
+
*
|
|
100
|
+
* @param deviceId - Device ID to remove from test devices
|
|
101
|
+
*/
|
|
102
|
+
static removeTestDevice(deviceId: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Get list of test device IDs
|
|
105
|
+
*/
|
|
106
|
+
static getTestDevices(): Promise<string[]>;
|
|
107
|
+
/**
|
|
108
|
+
* Set UTM parameters for attribution tracking
|
|
109
|
+
*
|
|
110
|
+
* These parameters are persisted and used for all analytics events.
|
|
111
|
+
* Typically set from deep link parameters.
|
|
112
|
+
*
|
|
113
|
+
* @param params - UTM parameters object
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* BigCrunchAds.setUTMParameters({
|
|
118
|
+
* source: 'google',
|
|
119
|
+
* medium: 'cpc',
|
|
120
|
+
* campaign: 'summer_sale',
|
|
121
|
+
* term: 'running shoes',
|
|
122
|
+
* content: 'variant_a'
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
static setUTMParameters(params: {
|
|
127
|
+
source?: string;
|
|
128
|
+
medium?: string;
|
|
129
|
+
campaign?: string;
|
|
130
|
+
term?: string;
|
|
131
|
+
content?: string;
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Clear UTM parameters
|
|
135
|
+
*/
|
|
136
|
+
static clearUTMParameters(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Add a global event listener
|
|
139
|
+
*
|
|
140
|
+
* @param eventName - Native event name to listen to
|
|
141
|
+
* @param listener - Callback function
|
|
142
|
+
* @returns Subscription object with remove() method
|
|
143
|
+
*/
|
|
144
|
+
static addEventListener(eventName: string, listener: (event: any) => void): EventSubscription;
|
|
145
|
+
/**
|
|
146
|
+
* Listen for configuration updates
|
|
147
|
+
*/
|
|
148
|
+
static onConfigUpdated(listener: (config: AppConfig) => void): EventSubscription;
|
|
149
|
+
/**
|
|
150
|
+
* Listen for configuration failures
|
|
151
|
+
*/
|
|
152
|
+
static onConfigFailed(listener: (error: Error) => void): EventSubscription;
|
|
153
|
+
/**
|
|
154
|
+
* Listen for session start events
|
|
155
|
+
*/
|
|
156
|
+
static onSessionStarted(listener: (session: SessionInfo) => void): EventSubscription;
|
|
157
|
+
/**
|
|
158
|
+
* Listen for session end events
|
|
159
|
+
*/
|
|
160
|
+
static onSessionEnded(listener: (session: SessionInfo) => void): EventSubscription;
|
|
161
|
+
/**
|
|
162
|
+
* Ensure SDK is initialized before calling methods
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
private static ensureInitialized;
|
|
166
|
+
}
|
|
167
|
+
export default BigCrunchAds;
|
|
168
|
+
//# sourceMappingURL=BigCrunchAds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BigCrunchAds.d.ts","sourceRoot":"","sources":["../src/BigCrunchAds.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BigCrunch Mobile Ads SDK for React Native
|
|
3
|
+
* Main API class
|
|
4
|
+
*/
|
|
5
|
+
import { NativeBigCrunchAds, BigCrunchAdsEventEmitter, NativeEventNames, } from './NativeBigCrunchAds';
|
|
6
|
+
/**
|
|
7
|
+
* Main entry point for BigCrunch Mobile Ads SDK
|
|
8
|
+
*/
|
|
9
|
+
export class BigCrunchAds {
|
|
10
|
+
static isInitializedFlag = false;
|
|
11
|
+
static initializationPromise = null;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize the BigCrunch Ads SDK
|
|
14
|
+
* Must be called before using any other SDK features
|
|
15
|
+
*
|
|
16
|
+
* @param propertyId - Your BigCrunch property ID
|
|
17
|
+
* @param apiKey - Your API key for authentication
|
|
18
|
+
* @param environment - Environment to use (default: 'production')
|
|
19
|
+
* @param options - Additional initialization options
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* await BigCrunchAds.initialize(
|
|
24
|
+
* 'your-property-id',
|
|
25
|
+
* 'your-api-key',
|
|
26
|
+
* 'production'
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
static async initialize(propertyId, apiKey, environment = 'production', options) {
|
|
31
|
+
if (this.isInitializedFlag) {
|
|
32
|
+
console.warn('BigCrunchAds: SDK is already initialized');
|
|
33
|
+
return this.initializationPromise;
|
|
34
|
+
}
|
|
35
|
+
const initOptions = {
|
|
36
|
+
propertyId,
|
|
37
|
+
apiKey,
|
|
38
|
+
environment,
|
|
39
|
+
...options,
|
|
40
|
+
};
|
|
41
|
+
this.initializationPromise = NativeBigCrunchAds.initialize(initOptions)
|
|
42
|
+
.then(() => {
|
|
43
|
+
this.isInitializedFlag = true;
|
|
44
|
+
console.log('BigCrunchAds: SDK initialized successfully');
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
this.isInitializedFlag = false;
|
|
48
|
+
this.initializationPromise = null;
|
|
49
|
+
throw error;
|
|
50
|
+
});
|
|
51
|
+
return this.initializationPromise;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if the SDK is initialized
|
|
55
|
+
*/
|
|
56
|
+
static async isInitialized() {
|
|
57
|
+
if (this.isInitializedFlag) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return NativeBigCrunchAds.isInitialized();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Track a screen view for analytics
|
|
64
|
+
*
|
|
65
|
+
* @param screenName - Name of the screen being viewed
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* BigCrunchAds.trackScreenView('HomeScreen');
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
static async trackScreenView(screenName) {
|
|
73
|
+
this.ensureInitialized();
|
|
74
|
+
return NativeBigCrunchAds.trackScreenView(screenName);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the current app configuration
|
|
78
|
+
* Returns null if config hasn't been loaded yet
|
|
79
|
+
*/
|
|
80
|
+
static async getAppConfig() {
|
|
81
|
+
this.ensureInitialized();
|
|
82
|
+
return NativeBigCrunchAds.getAppConfig();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Force refresh the app configuration from backend
|
|
86
|
+
*/
|
|
87
|
+
static async refreshConfig() {
|
|
88
|
+
this.ensureInitialized();
|
|
89
|
+
return NativeBigCrunchAds.refreshConfig();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get current session information
|
|
93
|
+
*/
|
|
94
|
+
static async getSessionInfo() {
|
|
95
|
+
this.ensureInitialized();
|
|
96
|
+
return NativeBigCrunchAds.getSessionInfo();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Start a new session (usually handled automatically)
|
|
100
|
+
*/
|
|
101
|
+
static async startNewSession() {
|
|
102
|
+
this.ensureInitialized();
|
|
103
|
+
return NativeBigCrunchAds.startNewSession();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get device context information
|
|
107
|
+
*/
|
|
108
|
+
static async getDeviceContext() {
|
|
109
|
+
return NativeBigCrunchAds.getDeviceContext();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Set GDPR consent string
|
|
113
|
+
*
|
|
114
|
+
* @param consent - GDPR consent string
|
|
115
|
+
*/
|
|
116
|
+
static async setGdprConsent(consent) {
|
|
117
|
+
return NativeBigCrunchAds.setGdprConsent(consent);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Set CCPA compliance string
|
|
121
|
+
*
|
|
122
|
+
* @param ccpaString - CCPA string (e.g., "1YNN")
|
|
123
|
+
*/
|
|
124
|
+
static async setCcpaString(ccpaString) {
|
|
125
|
+
return NativeBigCrunchAds.setCcpaString(ccpaString);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set COPPA compliance
|
|
129
|
+
*
|
|
130
|
+
* @param isCompliant - Whether the app is COPPA compliant
|
|
131
|
+
*/
|
|
132
|
+
static async setCoppaCompliant(isCompliant) {
|
|
133
|
+
return NativeBigCrunchAds.setCoppaCompliant(isCompliant);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Enable or disable debug mode
|
|
137
|
+
*
|
|
138
|
+
* @param enabled - Whether to enable debug mode
|
|
139
|
+
*/
|
|
140
|
+
static async setDebugMode(enabled) {
|
|
141
|
+
return NativeBigCrunchAds.setDebugMode(enabled);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Add a test device ID for testing ads
|
|
145
|
+
*
|
|
146
|
+
* @param deviceId - Device ID to add as test device
|
|
147
|
+
*/
|
|
148
|
+
static async addTestDevice(deviceId) {
|
|
149
|
+
return NativeBigCrunchAds.addTestDevice(deviceId);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Remove a test device ID
|
|
153
|
+
*
|
|
154
|
+
* @param deviceId - Device ID to remove from test devices
|
|
155
|
+
*/
|
|
156
|
+
static async removeTestDevice(deviceId) {
|
|
157
|
+
return NativeBigCrunchAds.removeTestDevice(deviceId);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Get list of test device IDs
|
|
161
|
+
*/
|
|
162
|
+
static async getTestDevices() {
|
|
163
|
+
return NativeBigCrunchAds.getTestDevices();
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Set UTM parameters for attribution tracking
|
|
167
|
+
*
|
|
168
|
+
* These parameters are persisted and used for all analytics events.
|
|
169
|
+
* Typically set from deep link parameters.
|
|
170
|
+
*
|
|
171
|
+
* @param params - UTM parameters object
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* BigCrunchAds.setUTMParameters({
|
|
176
|
+
* source: 'google',
|
|
177
|
+
* medium: 'cpc',
|
|
178
|
+
* campaign: 'summer_sale',
|
|
179
|
+
* term: 'running shoes',
|
|
180
|
+
* content: 'variant_a'
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
static async setUTMParameters(params) {
|
|
185
|
+
return NativeBigCrunchAds.setUTMParameters(params);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Clear UTM parameters
|
|
189
|
+
*/
|
|
190
|
+
static async clearUTMParameters() {
|
|
191
|
+
return NativeBigCrunchAds.clearUTMParameters();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Add a global event listener
|
|
195
|
+
*
|
|
196
|
+
* @param eventName - Native event name to listen to
|
|
197
|
+
* @param listener - Callback function
|
|
198
|
+
* @returns Subscription object with remove() method
|
|
199
|
+
*/
|
|
200
|
+
static addEventListener(eventName, listener) {
|
|
201
|
+
const subscription = BigCrunchAdsEventEmitter.addListener(eventName, listener);
|
|
202
|
+
return {
|
|
203
|
+
remove: () => subscription.remove(),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Listen for configuration updates
|
|
208
|
+
*/
|
|
209
|
+
static onConfigUpdated(listener) {
|
|
210
|
+
return this.addEventListener(NativeEventNames.CONFIG_UPDATED, listener);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Listen for configuration failures
|
|
214
|
+
*/
|
|
215
|
+
static onConfigFailed(listener) {
|
|
216
|
+
return this.addEventListener(NativeEventNames.CONFIG_FAILED, listener);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Listen for session start events
|
|
220
|
+
*/
|
|
221
|
+
static onSessionStarted(listener) {
|
|
222
|
+
return this.addEventListener(NativeEventNames.SESSION_STARTED, listener);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Listen for session end events
|
|
226
|
+
*/
|
|
227
|
+
static onSessionEnded(listener) {
|
|
228
|
+
return this.addEventListener(NativeEventNames.SESSION_ENDED, listener);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Ensure SDK is initialized before calling methods
|
|
232
|
+
* @private
|
|
233
|
+
*/
|
|
234
|
+
static ensureInitialized() {
|
|
235
|
+
if (!this.isInitializedFlag && !this.initializationPromise) {
|
|
236
|
+
throw new Error('BigCrunchAds: SDK is not initialized. Call BigCrunchAds.initialize() first.');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Export as default for convenience
|
|
241
|
+
export default BigCrunchAds;
|