@adshift/react-native-plugin 1.0.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/AdShiftReactNativePlugin.podspec +30 -0
- package/LICENSE +45 -0
- package/README.md +810 -0
- package/android/build.gradle +80 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +420 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginPackage.kt +33 -0
- package/ios/AdShiftReactNativePlugin.h +24 -0
- package/ios/AdShiftReactNativePlugin.mm +258 -0
- package/ios/AdShiftReactNativePluginHelper.swift +413 -0
- package/lib/module/Adshift.js +468 -0
- package/lib/module/Adshift.js.map +1 -0
- package/lib/module/NativeAdShiftReactNativePlugin.js +18 -0
- package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -0
- package/lib/module/index.js +57 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/AdshiftConfig.js +44 -0
- package/lib/module/types/AdshiftConfig.js.map +1 -0
- package/lib/module/types/AdshiftConsent.js +101 -0
- package/lib/module/types/AdshiftConsent.js.map +1 -0
- package/lib/module/types/AdshiftDeepLink.js +121 -0
- package/lib/module/types/AdshiftDeepLink.js.map +1 -0
- package/lib/module/types/AdshiftEventType.js +108 -0
- package/lib/module/types/AdshiftEventType.js.map +1 -0
- package/lib/module/types/index.js +10 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Adshift.d.ts +335 -0
- package/lib/typescript/src/Adshift.d.ts.map +1 -0
- package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts +143 -0
- package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +47 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftConfig.d.ts +74 -0
- package/lib/typescript/src/types/AdshiftConfig.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftConsent.d.ts +88 -0
- package/lib/typescript/src/types/AdshiftConsent.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftDeepLink.d.ts +93 -0
- package/lib/typescript/src/types/AdshiftDeepLink.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftEventType.d.ts +87 -0
- package/lib/typescript/src/types/AdshiftEventType.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +5 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/package.json +143 -0
- package/src/Adshift.ts +539 -0
- package/src/NativeAdShiftReactNativePlugin.ts +177 -0
- package/src/index.tsx +68 -0
- package/src/types/AdshiftConfig.ts +108 -0
- package/src/types/AdshiftConsent.ts +127 -0
- package/src/types/AdshiftDeepLink.ts +194 -0
- package/src/types/AdshiftEventType.ts +135 -0
- package/src/types/index.ts +7 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativePlugin_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativePlugin_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.adshift.reactnativeplugin"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lintOptions {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
|
|
78
|
+
// AdShift Android SDK from Maven Central
|
|
79
|
+
implementation "com.adshift:android-sdk:2.0.3"
|
|
80
|
+
}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
package com.adshift.reactnativeplugin
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.net.Uri
|
|
5
|
+
import android.os.Handler
|
|
6
|
+
import android.os.Looper
|
|
7
|
+
import com.facebook.react.bridge.Arguments
|
|
8
|
+
import com.facebook.react.bridge.Promise
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
|
+
import com.facebook.react.bridge.ReadableMap
|
|
11
|
+
import com.facebook.react.bridge.WritableMap
|
|
12
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
13
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
14
|
+
import com.adshift.sdk.core.AdShiftLib
|
|
15
|
+
import com.adshift.sdk.core.AdShiftConsent
|
|
16
|
+
import com.adshift.sdk.core.AdShiftRequestListener
|
|
17
|
+
import com.adshift.sdk.core.deeplink.DeepLinkListener
|
|
18
|
+
import com.adshift.sdk.core.deeplink.DeepLinkResult
|
|
19
|
+
import com.adshift.sdk.core.deeplink.DeepLinkStatus
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* AdShift React Native Turbo Module for Android.
|
|
23
|
+
*
|
|
24
|
+
* Bridges React Native JavaScript to native AdShift Android SDK.
|
|
25
|
+
* Implements NativeAdShiftReactNativePluginSpec generated by Codegen.
|
|
26
|
+
*/
|
|
27
|
+
@ReactModule(name = AdShiftReactNativePluginModule.NAME)
|
|
28
|
+
class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationContext) :
|
|
29
|
+
NativeAdShiftReactNativePluginSpec(reactContext) {
|
|
30
|
+
|
|
31
|
+
companion object {
|
|
32
|
+
const val NAME = "AdShiftReactNativePlugin"
|
|
33
|
+
private const val EVENT_DEEP_LINK = "onDeepLink"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Handler for main thread operations
|
|
37
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
38
|
+
|
|
39
|
+
// Track if we have listeners
|
|
40
|
+
private var listenerCount = 0
|
|
41
|
+
private var deepLinkListenerRegistered = false
|
|
42
|
+
|
|
43
|
+
// Pending promise for handleDeepLink() one-shot calls
|
|
44
|
+
private var pendingDeepLinkPromise: Promise? = null
|
|
45
|
+
|
|
46
|
+
override fun getName(): String = NAME
|
|
47
|
+
|
|
48
|
+
// ============ Lifecycle Methods ============
|
|
49
|
+
|
|
50
|
+
override fun initialize(config: ReadableMap) {
|
|
51
|
+
val context = reactContext.applicationContext ?: return
|
|
52
|
+
|
|
53
|
+
val apiKey = config.getString("apiKey")
|
|
54
|
+
if (apiKey.isNullOrBlank()) {
|
|
55
|
+
logError("initialize", "apiKey is required")
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Initialize SDK with API key
|
|
61
|
+
AdShiftLib.initSdk(context, apiKey)
|
|
62
|
+
|
|
63
|
+
// Apply optional configuration
|
|
64
|
+
if (config.hasKey("isDebug")) {
|
|
65
|
+
AdShiftLib.setDebugLog(config.getBoolean("isDebug"))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (config.hasKey("appOpenDebounceMs")) {
|
|
69
|
+
AdShiftLib.setAppOpenDebounceMs(config.getDouble("appOpenDebounceMs").toLong())
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Android only: OAID collection
|
|
73
|
+
if (config.hasKey("collectOaid")) {
|
|
74
|
+
AdShiftLib.setCollectOaid(config.getBoolean("collectOaid"))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// iOS only options are ignored on Android (disableSKAN, waitForATT, attTimeout)
|
|
78
|
+
|
|
79
|
+
logInfo("SDK initialized successfully")
|
|
80
|
+
} catch (e: Exception) {
|
|
81
|
+
logError("initialize", e.message)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override fun start(promise: Promise) {
|
|
86
|
+
try {
|
|
87
|
+
AdShiftLib.start(object : AdShiftRequestListener {
|
|
88
|
+
override fun onSuccess() {
|
|
89
|
+
val result = Arguments.createMap().apply {
|
|
90
|
+
putBoolean("success", true)
|
|
91
|
+
}
|
|
92
|
+
promise.resolve(result)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override fun onError(code: Int, error: String) {
|
|
96
|
+
promise.reject("START_ERROR", error)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
} catch (e: Exception) {
|
|
100
|
+
promise.reject("START_ERROR", e.message, e)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
override fun stop() {
|
|
105
|
+
// Must run on main thread due to Android SDK requirements
|
|
106
|
+
mainHandler.post {
|
|
107
|
+
try {
|
|
108
|
+
AdShiftLib.stop()
|
|
109
|
+
} catch (e: Exception) {
|
|
110
|
+
logError("stop", e.message)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
override fun isStarted(): Boolean {
|
|
116
|
+
return try {
|
|
117
|
+
AdShiftLib.isStarted()
|
|
118
|
+
} catch (e: Exception) {
|
|
119
|
+
false
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ============ Configuration Methods ============
|
|
124
|
+
|
|
125
|
+
override fun setCustomerUserId(userId: String) {
|
|
126
|
+
try {
|
|
127
|
+
AdShiftLib.setCustomerUserId(userId)
|
|
128
|
+
} catch (e: Exception) {
|
|
129
|
+
logError("setCustomerUserId", e.message)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
override fun setDebugEnabled(enabled: Boolean) {
|
|
134
|
+
try {
|
|
135
|
+
AdShiftLib.setDebugLog(enabled)
|
|
136
|
+
} catch (e: Exception) {
|
|
137
|
+
logError("setDebugEnabled", e.message)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
override fun setAppOpenDebounceMs(ms: Double) {
|
|
142
|
+
try {
|
|
143
|
+
AdShiftLib.setAppOpenDebounceMs(ms.toLong())
|
|
144
|
+
} catch (e: Exception) {
|
|
145
|
+
logError("setAppOpenDebounceMs", e.message)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ============ Consent Methods ============
|
|
150
|
+
|
|
151
|
+
override fun setConsentData(consent: ReadableMap) {
|
|
152
|
+
try {
|
|
153
|
+
val adShiftConsent = mapToAdShiftConsent(consent)
|
|
154
|
+
AdShiftLib.setConsentData(adShiftConsent)
|
|
155
|
+
} catch (e: Exception) {
|
|
156
|
+
logError("setConsentData", e.message)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
override fun enableTCFDataCollection(enabled: Boolean) {
|
|
161
|
+
try {
|
|
162
|
+
AdShiftLib.enableTCFDataCollection(enabled)
|
|
163
|
+
} catch (e: Exception) {
|
|
164
|
+
logError("enableTCFDataCollection", e.message)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
override fun refreshConsent(promise: Promise) {
|
|
169
|
+
try {
|
|
170
|
+
val snapshot = AdShiftLib.refreshConsent()
|
|
171
|
+
val result = Arguments.createMap().apply {
|
|
172
|
+
putString("source", snapshot.source.name.lowercase())
|
|
173
|
+
snapshot.gdprApplies?.let { putInt("gdprApplies", it) }
|
|
174
|
+
putBoolean("tcStringPresent", snapshot.tcStringPresent)
|
|
175
|
+
putBoolean("gppPresent", snapshot.gppPresent)
|
|
176
|
+
snapshot.adUserDataEnabled?.let { putBoolean("adUserDataEnabled", it) }
|
|
177
|
+
snapshot.adPersonalizationEnabled?.let { putBoolean("adPersonalizationEnabled", it) }
|
|
178
|
+
snapshot.adStorageEnabled?.let { putBoolean("adStorageEnabled", it) }
|
|
179
|
+
putDouble("appliedAtMillis", snapshot.appliedAtMillis.toDouble())
|
|
180
|
+
// Convenience field for JS
|
|
181
|
+
putBoolean("hasConsent", snapshot.adStorageEnabled == true || snapshot.adUserDataEnabled == true)
|
|
182
|
+
}
|
|
183
|
+
promise.resolve(result)
|
|
184
|
+
} catch (e: Exception) {
|
|
185
|
+
promise.reject("CONSENT_ERROR", e.message, e)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ============ Event Tracking Methods ============
|
|
190
|
+
|
|
191
|
+
override fun trackEvent(eventName: String, values: ReadableMap?, promise: Promise) {
|
|
192
|
+
try {
|
|
193
|
+
// Filter out null values and cast to Map<String, Any>
|
|
194
|
+
val eventValues: Map<String, Any> = values?.toHashMap()
|
|
195
|
+
?.filterValues { it != null }
|
|
196
|
+
?.mapValues { it.value as Any }
|
|
197
|
+
?: emptyMap()
|
|
198
|
+
|
|
199
|
+
AdShiftLib.trackEvent(
|
|
200
|
+
eventName = eventName,
|
|
201
|
+
eventValue = eventValues,
|
|
202
|
+
listener = object : AdShiftRequestListener {
|
|
203
|
+
override fun onSuccess() {
|
|
204
|
+
promise.resolve(null)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
override fun onError(code: Int, error: String) {
|
|
208
|
+
promise.reject("TRACK_ERROR", error)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
} catch (e: Exception) {
|
|
213
|
+
promise.reject("TRACK_ERROR", e.message, e)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
override fun trackPurchase(
|
|
218
|
+
productId: String,
|
|
219
|
+
price: Double,
|
|
220
|
+
currency: String,
|
|
221
|
+
token: String,
|
|
222
|
+
promise: Promise
|
|
223
|
+
) {
|
|
224
|
+
try {
|
|
225
|
+
AdShiftLib.trackPurchase(
|
|
226
|
+
productId = productId,
|
|
227
|
+
price = price,
|
|
228
|
+
currency = currency,
|
|
229
|
+
token = token,
|
|
230
|
+
listener = object : AdShiftRequestListener {
|
|
231
|
+
override fun onSuccess() {
|
|
232
|
+
promise.resolve(null)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
override fun onError(code: Int, error: String) {
|
|
236
|
+
promise.reject("TRACK_ERROR", error)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
} catch (e: Exception) {
|
|
241
|
+
promise.reject("TRACK_ERROR", e.message, e)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ============ Deep Link Methods ============
|
|
246
|
+
|
|
247
|
+
override fun handleDeepLink(url: String, promise: Promise) {
|
|
248
|
+
try {
|
|
249
|
+
val uri = Uri.parse(url)
|
|
250
|
+
val intent = Intent(Intent.ACTION_VIEW, uri)
|
|
251
|
+
|
|
252
|
+
// Store promise to resolve when deep link callback fires
|
|
253
|
+
pendingDeepLinkPromise = promise
|
|
254
|
+
|
|
255
|
+
// Ensure unified listener is registered
|
|
256
|
+
ensureDeepLinkListenerRegistered()
|
|
257
|
+
|
|
258
|
+
AdShiftLib.handleAppLinkIntent(intent)
|
|
259
|
+
} catch (e: Exception) {
|
|
260
|
+
pendingDeepLinkPromise = null
|
|
261
|
+
val errorResult = Arguments.createMap().apply {
|
|
262
|
+
putString("status", "error")
|
|
263
|
+
putString("errorMessage", e.message ?: "Unknown error")
|
|
264
|
+
putBoolean("isDeferred", false)
|
|
265
|
+
}
|
|
266
|
+
promise.resolve(errorResult)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ============ Event Emitter Methods ============
|
|
271
|
+
|
|
272
|
+
override fun addListener(eventType: String) {
|
|
273
|
+
listenerCount++
|
|
274
|
+
|
|
275
|
+
// Register deep link listener when first listener is added
|
|
276
|
+
if (listenerCount == 1) {
|
|
277
|
+
ensureDeepLinkListenerRegistered()
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
override fun removeListeners(count: Double) {
|
|
282
|
+
listenerCount -= count.toInt()
|
|
283
|
+
if (listenerCount < 0) listenerCount = 0
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Ensures single unified deep link listener is registered.
|
|
288
|
+
* Handles both one-shot Promise (handleDeepLink) and EventEmitter (onDeepLink) callbacks.
|
|
289
|
+
*/
|
|
290
|
+
private fun ensureDeepLinkListenerRegistered() {
|
|
291
|
+
if (deepLinkListenerRegistered) return
|
|
292
|
+
|
|
293
|
+
try {
|
|
294
|
+
AdShiftLib.setDeepLinkListener(object : DeepLinkListener {
|
|
295
|
+
override fun onDeepLinking(deepLinkResult: DeepLinkResult) {
|
|
296
|
+
val resultMap = mapDeepLinkResultToWritableMap(deepLinkResult)
|
|
297
|
+
|
|
298
|
+
mainHandler.post {
|
|
299
|
+
// First: resolve any pending Promise from handleDeepLink()
|
|
300
|
+
pendingDeepLinkPromise?.let { promise ->
|
|
301
|
+
promise.resolve(resultMap)
|
|
302
|
+
pendingDeepLinkPromise = null
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Second: emit to EventEmitter subscribers (if any)
|
|
306
|
+
if (listenerCount > 0) {
|
|
307
|
+
// Create a copy since we may have already used resultMap for promise
|
|
308
|
+
val eventMap = mapDeepLinkResultToWritableMap(deepLinkResult)
|
|
309
|
+
sendEvent(EVENT_DEEP_LINK, eventMap)
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
deepLinkListenerRegistered = true
|
|
315
|
+
} catch (e: Exception) {
|
|
316
|
+
// SDK might not be initialized yet
|
|
317
|
+
logError("ensureDeepLinkListenerRegistered", e.message)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Sends event to JavaScript via DeviceEventEmitter.
|
|
323
|
+
*/
|
|
324
|
+
private fun sendEvent(eventName: String, params: WritableMap) {
|
|
325
|
+
mainHandler.post {
|
|
326
|
+
reactContext
|
|
327
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
328
|
+
?.emit(eventName, params)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ============ Mappers ============
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Maps ReadableMap consent to native AdShiftConsent.
|
|
336
|
+
*/
|
|
337
|
+
private fun mapToAdShiftConsent(consent: ReadableMap): AdShiftConsent {
|
|
338
|
+
val isGDPR = consent.getBooleanOrDefault("isUserSubjectToGDPR", false)
|
|
339
|
+
val dataUsage = consent.getBooleanOrDefault("hasConsentForDataUsage", false)
|
|
340
|
+
val personalization = consent.getBooleanOrDefault("hasConsentForAdsPersonalization", false)
|
|
341
|
+
val storage = consent.getBooleanOrDefault("hasConsentForAdStorage", false)
|
|
342
|
+
|
|
343
|
+
return if (isGDPR) {
|
|
344
|
+
AdShiftConsent.forGDPRUser(
|
|
345
|
+
hasConsentForDataUsage = dataUsage,
|
|
346
|
+
hasConsentForAdsPersonalization = personalization,
|
|
347
|
+
hasConsentForAdStorage = storage
|
|
348
|
+
)
|
|
349
|
+
} else {
|
|
350
|
+
AdShiftConsent.forNonGDPRUser()
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Maps native DeepLinkResult to WritableMap for React Native.
|
|
356
|
+
*/
|
|
357
|
+
private fun mapDeepLinkResultToWritableMap(result: DeepLinkResult): WritableMap {
|
|
358
|
+
return Arguments.createMap().apply {
|
|
359
|
+
// Deep link URL
|
|
360
|
+
result.uri?.toString()?.let { putString("deepLink", it) }
|
|
361
|
+
|
|
362
|
+
// Deep link value - extract from queryParams if present
|
|
363
|
+
// Note: Android SDK doesn't have deepLinkValue as separate field like iOS
|
|
364
|
+
result.queryParams?.get("deep_link_value")?.let { putString("deepLinkValue", it) }
|
|
365
|
+
|
|
366
|
+
// Sub parameters
|
|
367
|
+
result.sub1?.let { putString("deepLinkSub1", it) }
|
|
368
|
+
result.sub2?.let { putString("deepLinkSub2", it) }
|
|
369
|
+
result.sub3?.let { putString("deepLinkSub3", it) }
|
|
370
|
+
result.sub4?.let { putString("deepLinkSub4", it) }
|
|
371
|
+
result.sub5?.let { putString("deepLinkSub5", it) }
|
|
372
|
+
|
|
373
|
+
// Query params (build combined map)
|
|
374
|
+
val paramsMap = Arguments.createMap()
|
|
375
|
+
result.queryParams?.forEach { (key, value) ->
|
|
376
|
+
paramsMap.putString(key, value)
|
|
377
|
+
}
|
|
378
|
+
// Also add sub params to params for consistency with iOS
|
|
379
|
+
result.sub1?.let { paramsMap.putString("deep_link_sub1", it) }
|
|
380
|
+
result.sub2?.let { paramsMap.putString("deep_link_sub2", it) }
|
|
381
|
+
result.sub3?.let { paramsMap.putString("deep_link_sub3", it) }
|
|
382
|
+
result.sub4?.let { paramsMap.putString("deep_link_sub4", it) }
|
|
383
|
+
result.sub5?.let { paramsMap.putString("deep_link_sub5", it) }
|
|
384
|
+
|
|
385
|
+
if (paramsMap.toHashMap().isNotEmpty()) {
|
|
386
|
+
putMap("params", paramsMap)
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Is deferred
|
|
390
|
+
putBoolean("isDeferred", result.isDeferred)
|
|
391
|
+
|
|
392
|
+
// Status
|
|
393
|
+
val statusString = when (result.status) {
|
|
394
|
+
DeepLinkStatus.FOUND -> "found"
|
|
395
|
+
DeepLinkStatus.NOT_FOUND -> "notFound"
|
|
396
|
+
DeepLinkStatus.ERROR -> "error"
|
|
397
|
+
}
|
|
398
|
+
putString("status", statusString)
|
|
399
|
+
|
|
400
|
+
// Error message
|
|
401
|
+
result.error?.let { error ->
|
|
402
|
+
putString("errorMessage", error.name.lowercase().replace("_", " "))
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// ============ Utilities ============
|
|
408
|
+
|
|
409
|
+
private fun ReadableMap.getBooleanOrDefault(key: String, default: Boolean): Boolean {
|
|
410
|
+
return if (hasKey(key)) getBoolean(key) else default
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
private fun logInfo(message: String) {
|
|
414
|
+
android.util.Log.i("AdShiftRN", message)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private fun logError(method: String, message: String?) {
|
|
418
|
+
android.util.Log.e("AdShiftRN", "[$method] Error: $message")
|
|
419
|
+
}
|
|
420
|
+
}
|
package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginPackage.kt
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package com.adshift.reactnativeplugin
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
9
|
+
|
|
10
|
+
class AdShiftReactNativePluginPackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == AdShiftReactNativePluginModule.NAME) {
|
|
13
|
+
AdShiftReactNativePluginModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
20
|
+
return ReactModuleInfoProvider {
|
|
21
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
22
|
+
moduleInfos[AdShiftReactNativePluginModule.NAME] = ReactModuleInfo(
|
|
23
|
+
AdShiftReactNativePluginModule.NAME,
|
|
24
|
+
AdShiftReactNativePluginModule.NAME,
|
|
25
|
+
false, // canOverrideExistingModule
|
|
26
|
+
false, // needsEagerInit
|
|
27
|
+
false, // isCxxModule
|
|
28
|
+
true // isTurboModule
|
|
29
|
+
)
|
|
30
|
+
moduleInfos
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AdShiftReactNativePlugin.h
|
|
3
|
+
// AdShiftReactNativePlugin
|
|
4
|
+
//
|
|
5
|
+
// Turbo Module header for AdShift React Native Plugin.
|
|
6
|
+
// Conforms to the Codegen-generated spec.
|
|
7
|
+
//
|
|
8
|
+
// Copyright © 2025 AdShift. All rights reserved.
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
#import <React/RCTEventEmitter.h>
|
|
12
|
+
#import <AdShiftReactNativePluginSpec/AdShiftReactNativePluginSpec.h>
|
|
13
|
+
|
|
14
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
15
|
+
|
|
16
|
+
/// AdShift React Native Turbo Module
|
|
17
|
+
///
|
|
18
|
+
/// Bridges React Native JavaScript to native AdShift iOS SDK.
|
|
19
|
+
/// Implements NativeAdShiftReactNativePluginSpec generated by Codegen.
|
|
20
|
+
@interface AdShiftReactNativePlugin : RCTEventEmitter <NativeAdShiftReactNativePluginSpec>
|
|
21
|
+
|
|
22
|
+
@end
|
|
23
|
+
|
|
24
|
+
NS_ASSUME_NONNULL_END
|