@bigcrunch/react-native-ads 0.5.0 → 0.7.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.
@@ -308,6 +308,7 @@ object BigCrunchAds {
308
308
  return SessionInfo(
309
309
  sessionId = SessionManager.getSessionId(),
310
310
  startTime = SessionManager.getSessionStartTime(),
311
+ sessionDepth = SessionManager.getSessionDepth(),
311
312
  screenViewCount = SessionManager.getScreenViewCount(),
312
313
  adRequestCount = SessionManager.getAdRequestCount(),
313
314
  adImpressionCount = SessionManager.getAdImpressionCount(),
@@ -50,7 +50,6 @@ internal class ConfigManager(
50
50
  return AppConfig(
51
51
  propertyId = propertyId,
52
52
  appName = "Mock Test App",
53
- environment = "test",
54
53
  gamNetworkCode = "", // Empty for AdMob sample ads
55
54
  s2s = com.bigcrunch.ads.models.S2SConfig(
56
55
  serverUrl = "https://s2s.bigcrunch.com/auction",
@@ -158,7 +157,8 @@ internal class ConfigManager(
158
157
  if (config != null) {
159
158
  cachedConfig = config
160
159
  saveToStorage(json)
161
- BCLogger.i("ConfigManager", "Config loaded successfully from network (${config.placements.size} placements)")
160
+ val placementIds = config.placements.map { it.placementId }
161
+ BCLogger.i("ConfigManager", "Config loaded successfully from network (${config.placements.size} placements): $placementIds")
162
162
  Result.success(config)
163
163
  } else {
164
164
  BCLogger.e("ConfigManager", "Invalid config JSON")
@@ -167,7 +167,8 @@ internal class ConfigManager(
167
167
  }
168
168
  storedConfig != null -> {
169
169
  // Network failed but we have cached version
170
- BCLogger.w("ConfigManager", "Using cached config, network fetch failed: ${result.exceptionOrNull()?.message}")
170
+ val cachedIds = storedConfig.placements.map { it.placementId }
171
+ BCLogger.w("ConfigManager", "Using cached config, network fetch failed: ${result.exceptionOrNull()?.message} (cached placements: $cachedIds)")
171
172
  Result.success(storedConfig)
172
173
  }
173
174
  else -> {
@@ -28,7 +28,7 @@ internal class DeviceContext private constructor(context: Context) {
28
28
 
29
29
  companion object {
30
30
  private const val TAG = "DeviceContext"
31
- internal const val SDK_VERSION = "0.5.0"
31
+ internal const val SDK_VERSION = "0.7.0"
32
32
 
33
33
  @Volatile
34
34
  private var instance: DeviceContext? = null
@@ -71,6 +71,7 @@ internal class SessionManager private constructor(private val storage: KeyValueS
71
71
  // Static accessors for tracking counters
72
72
  fun getSessionId(): String = getInstance().sessionId
73
73
  fun getSessionStartTime(): String = getInstance().sessionStartTime
74
+ fun getSessionDepth(): Int = getInstance().sessionDepth
74
75
  fun getScreenViewCount(): Int = getInstance().screenViewCounter.get()
75
76
  fun getAdRequestCount(): Int = getInstance().adRequestCounter.get()
76
77
  fun getAdImpressionCount(): Int = getInstance().adImpressionCounter.get()
@@ -17,9 +17,6 @@ data class AppConfig(
17
17
  @Json(name = "appName")
18
18
  val appName: String,
19
19
 
20
- @Json(name = "environment")
21
- val environment: String,
22
-
23
20
  @Json(name = "gamNetworkCode")
24
21
  val gamNetworkCode: String,
25
22
 
@@ -14,6 +14,7 @@ package com.bigcrunch.ads.models
14
14
  data class SessionInfo(
15
15
  val sessionId: String,
16
16
  val startTime: String,
17
+ val sessionDepth: Int,
17
18
  val screenViewCount: Int,
18
19
  val adRequestCount: Int,
19
20
  val adImpressionCount: Int,
@@ -39,6 +39,8 @@ class BigCrunchAdsModule(reactContext: ReactApplicationContext) :
39
39
 
40
40
  scope.launch {
41
41
  try {
42
+ android.util.Log.d("BigCrunchRNBridge", "initialize() called: propertyId=$propertyId env=$environment mock=${environment == "sandbox"}")
43
+
42
44
  BigCrunchAds.initialize(
43
45
  context = context,
44
46
  propertyId = propertyId,
@@ -50,12 +52,25 @@ class BigCrunchAdsModule(reactContext: ReactApplicationContext) :
50
52
  useMockConfig = environment == "sandbox"
51
53
  )
52
54
 
55
+ android.util.Log.d("BigCrunchRNBridge", "native initialize() returned, isInitialized=${BigCrunchAds.isInitialized()}")
56
+
53
57
  if (debug) {
54
58
  BigCrunchAds.setDebugMode(true)
55
59
  }
56
60
 
57
- // SDK initialization is complete
58
- // The Android SDK now handles config loading internally
61
+ // Wait for config to be loaded before resolving the promise
62
+ // This ensures placements are available when the app starts loading ads
63
+ android.util.Log.d("BigCrunchRNBridge", "waiting for config...")
64
+ val configLoaded = BigCrunchAds.waitForConfig()
65
+ android.util.Log.d("BigCrunchRNBridge", "waitForConfig returned: $configLoaded, isConfigReady=${BigCrunchAds.isConfigReady()}")
66
+
67
+ if (!configLoaded) {
68
+ android.util.Log.e("BigCrunchRNBridge", "config failed to load, rejecting promise")
69
+ promise.reject("INIT_ERROR", "Failed to load configuration", null)
70
+ return@launch
71
+ }
72
+
73
+ android.util.Log.d("BigCrunchRNBridge", "init complete, resolving promise")
59
74
  promise.resolve(null)
60
75
  } catch (e: Exception) {
61
76
  promise.reject("INIT_ERROR", "Failed to initialize SDK: ${e.message}", e)
@@ -612,6 +627,7 @@ class BigCrunchAdsModule(reactContext: ReactApplicationContext) :
612
627
  val map = Arguments.createMap()
613
628
  map.putString("sessionId", info.sessionId)
614
629
  map.putString("startTime", info.startTime) // Changed from toDouble() - now ISO 8601 string
630
+ map.putInt("sessionDepth", info.sessionDepth)
615
631
  map.putInt("screenViewCount", info.screenViewCount)
616
632
  map.putInt("adRequestCount", info.adRequestCount)
617
633
  map.putInt("adImpressionCount", info.adImpressionCount)
@@ -202,6 +202,7 @@ public final class BigCrunchAds {
202
202
  sessionId: sm.sessionId,
203
203
  userId: sm.userId,
204
204
  startTime: sm.sessionStartTime,
205
+ sessionDepth: sm.sessionDepth,
205
206
  screenViewCount: sm.sessionDepth,
206
207
  adRequestCount: sm.adRequestCount,
207
208
  adImpressionCount: sm.adImpressionCount,
@@ -44,7 +44,6 @@ internal class ConfigManager {
44
44
  return AppConfig(
45
45
  propertyId: propertyId,
46
46
  appName: "Mock Test App",
47
- environment: "test",
48
47
  gamNetworkCode: "", // Empty for AdMob sample ads
49
48
  s2s: S2SConfig(
50
49
  serverUrl: "https://s2s.bigcrunch.com/auction",
@@ -148,7 +147,8 @@ internal class ConfigManager {
148
147
  let config = try JSONDecoder().decode(AppConfig.self, from: data)
149
148
  cachedConfig = config
150
149
  saveToStorage(json)
151
- BCLogger.info("Config loaded successfully from network (\(config.placements.count) placements)")
150
+ let placementIds = config.placements.map { $0.placementId }
151
+ BCLogger.info("Config loaded successfully from network (\(config.placements.count) placements): \(placementIds)")
152
152
  return .success(config)
153
153
  } catch {
154
154
  BCLogger.error("Failed to parse config JSON: \(error)")
@@ -158,7 +158,8 @@ internal class ConfigManager {
158
158
  case .failure(let error):
159
159
  // Network failed, check for cached version
160
160
  if let cached = cachedConfig {
161
- BCLogger.warning("Using cached config, network fetch failed: \(error)")
161
+ let cachedIds = cached.placements.map { $0.placementId }
162
+ BCLogger.warning("Using cached config, network fetch failed: \(error) (cached placements: \(cachedIds))")
162
163
  return .success(cached)
163
164
  } else {
164
165
  BCLogger.error("Config load failed and no cache available")
@@ -74,7 +74,7 @@ internal final class DeviceContext {
74
74
  // MARK: - SDK Properties
75
75
 
76
76
  /// SDK version
77
- static let SDK_VERSION = "0.5.0"
77
+ static let SDK_VERSION = "0.7.0"
78
78
  let sdkVersion: String = SDK_VERSION
79
79
 
80
80
  /// SDK platform (always "ios")
@@ -9,7 +9,6 @@ import Foundation
9
9
  public struct AppConfig: Codable {
10
10
  public let propertyId: String
11
11
  public let appName: String
12
- public let environment: String
13
12
  public let gamNetworkCode: String
14
13
  public let s2s: S2SConfig
15
14
  public let bidders: [String: BidderEntry]?
@@ -21,7 +20,6 @@ public struct AppConfig: Codable {
21
20
  public init(
22
21
  propertyId: String,
23
22
  appName: String,
24
- environment: String,
25
23
  gamNetworkCode: String,
26
24
  s2s: S2SConfig,
27
25
  bidders: [String: BidderEntry]? = nil,
@@ -32,7 +30,6 @@ public struct AppConfig: Codable {
32
30
  ) {
33
31
  self.propertyId = propertyId
34
32
  self.appName = appName
35
- self.environment = environment
36
33
  self.gamNetworkCode = gamNetworkCode
37
34
  self.s2s = s2s
38
35
  self.bidders = bidders
@@ -42,6 +39,18 @@ public struct AppConfig: Codable {
42
39
  self.placements = placements
43
40
  }
44
41
 
42
+ public init(from decoder: Decoder) throws {
43
+ let container = try decoder.container(keyedBy: CodingKeys.self)
44
+ propertyId = try container.decode(String.self, forKey: .propertyId)
45
+ appName = try container.decode(String.self, forKey: .appName)
46
+ gamNetworkCode = try container.decode(String.self, forKey: .gamNetworkCode)
47
+ s2s = try container.decode(S2SConfig.self, forKey: .s2s)
48
+ bidders = try container.decodeIfPresent([String: BidderEntry].self, forKey: .bidders)
49
+ amazonAps = try container.decodeIfPresent(GlobalAmazonConfig.self, forKey: .amazonAps)
50
+ useTestAds = try container.decodeIfPresent(Bool.self, forKey: .useTestAds) ?? false
51
+ refresh = try container.decodeIfPresent(RefreshConfig.self, forKey: .refresh)
52
+ placements = try container.decode([PlacementConfig].self, forKey: .placements)
53
+ }
45
54
  }
46
55
 
47
56
  /**
@@ -16,6 +16,9 @@ public struct SessionInfo {
16
16
  /// ISO 8601 timestamp when the session started
17
17
  public let startTime: String
18
18
 
19
+ /// Number of page views in current session (same as screenViewCount)
20
+ public let sessionDepth: Int
21
+
19
22
  /// Number of screen views in this session
20
23
  public let screenViewCount: Int
21
24
 
@@ -32,6 +35,7 @@ public struct SessionInfo {
32
35
  sessionId: String,
33
36
  userId: String,
34
37
  startTime: String,
38
+ sessionDepth: Int,
35
39
  screenViewCount: Int,
36
40
  adRequestCount: Int,
37
41
  adImpressionCount: Int,
@@ -40,6 +44,7 @@ public struct SessionInfo {
40
44
  self.sessionId = sessionId
41
45
  self.userId = userId
42
46
  self.startTime = startTime
47
+ self.sessionDepth = sessionDepth
43
48
  self.screenViewCount = screenViewCount
44
49
  self.adRequestCount = adRequestCount
45
50
  self.adImpressionCount = adImpressionCount
@@ -120,6 +120,28 @@ class RewardedDelegate: NSObject, BigCrunchRewardedDelegate {
120
120
  }
121
121
  }
122
122
 
123
+ // MARK: - Initialization Callback Bridge
124
+
125
+ class InitCallbackBridge: NSObject, BigCrunchInitializationCallback {
126
+ private let onSuccess: () -> Void
127
+ private let onFailure: (String) -> Void
128
+
129
+ init(onSuccess: @escaping () -> Void, onFailure: @escaping (String) -> Void) {
130
+ self.onSuccess = onSuccess
131
+ self.onFailure = onFailure
132
+ }
133
+
134
+ func onInitialized() {
135
+ NSLog("[BigCrunchRNBridge] callback onInitialized fired, resolving promise")
136
+ onSuccess()
137
+ }
138
+
139
+ func onInitializationFailed(error: String) {
140
+ NSLog("[BigCrunchRNBridge] callback onInitializationFailed: %@", error)
141
+ onFailure(error)
142
+ }
143
+ }
144
+
123
145
  @objc(BigCrunchAdsModule)
124
146
  class BigCrunchAdsModule: RCTEventEmitter {
125
147
 
@@ -129,6 +151,7 @@ class BigCrunchAdsModule: RCTEventEmitter {
129
151
  var rewardedCache: [String: Any] = [:]
130
152
  private var interstitialDelegates: [String: InterstitialDelegate] = [:]
131
153
  var rewardedDelegates: [String: RewardedDelegate] = [:]
154
+ private var initCallbackBridge: InitCallbackBridge?
132
155
 
133
156
  override static func moduleName() -> String! {
134
157
  return "BigCrunchAdsModule"
@@ -208,17 +231,31 @@ class BigCrunchAdsModule: RCTEventEmitter {
208
231
  // Map environment strings to SDK enum - "sandbox" maps to .staging
209
232
  let env: BigCrunchEnv = environment == "sandbox" ? .staging : .prod
210
233
 
234
+ NSLog("[BigCrunchRNBridge] initialize() called: propertyId=%@ env=%@ mock=%d", propertyId, environment, useMockConfig ? 1 : 0)
235
+
236
+ // Use callback to wait for config to load before resolving the promise
237
+ // This ensures placements are available when the app starts loading ads
238
+ let callbackBridge = InitCallbackBridge(
239
+ onSuccess: {
240
+ NSLog("[BigCrunchRNBridge] init complete, setting isSDKInitialized=true, resolving promise")
241
+ BigCrunchAdsModule.isSDKInitialized = true
242
+ resolver(nil)
243
+ },
244
+ onFailure: { error in
245
+ NSLog("[BigCrunchRNBridge] init failed: %@, rejecting promise", error)
246
+ rejecter("INIT_ERROR", "Failed to load configuration: \(error)", nil)
247
+ }
248
+ )
249
+ // Store strong reference so it isn't deallocated before callback fires
250
+ self.initCallbackBridge = callbackBridge
251
+
211
252
  BigCrunchAds.initialize(
212
253
  propertyId: propertyId,
213
254
  env: env,
214
- useMockConfig: useMockConfig
255
+ useMockConfig: useMockConfig,
256
+ callback: callbackBridge
215
257
  )
216
-
217
- // Track that we've initialized
218
- BigCrunchAdsModule.isSDKInitialized = true
219
-
220
- // Note: debug mode is handled by SDK based on env (.staging enables verbose logging)
221
- resolver(nil)
258
+ NSLog("[BigCrunchRNBridge] native initialize() returned, waiting for callback...")
222
259
  }
223
260
  }
224
261
 
@@ -254,7 +291,6 @@ class BigCrunchAdsModule: RCTEventEmitter {
254
291
  let configDict: [String: Any] = [
255
292
  "propertyId": config.propertyId,
256
293
  "appName": config.appName,
257
- "environment": config.environment,
258
294
  "gamNetworkCode": config.gamNetworkCode,
259
295
  "s2s": [
260
296
  "enabled": config.s2s.enabled,
@@ -481,6 +517,7 @@ class BigCrunchAdsModule: RCTEventEmitter {
481
517
  "sessionId": info.sessionId,
482
518
  "userId": info.userId,
483
519
  "startTime": info.startTime,
520
+ "sessionDepth": info.sessionDepth,
484
521
  "screenViewCount": info.screenViewCount,
485
522
  "adRequestCount": info.adRequestCount,
486
523
  "adImpressionCount": info.adImpressionCount,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigcrunch/react-native-ads",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "BigCrunch Mobile Ads SDK for React Native - Simplified in-app advertising with S2S demand and Google Ad Manager",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -92,4 +92,4 @@
92
92
  "optional": false
93
93
  }
94
94
  }
95
- }
95
+ }