@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,258 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AdShiftReactNativePlugin.mm
|
|
3
|
+
// AdShiftReactNativePlugin
|
|
4
|
+
//
|
|
5
|
+
// Objective-C++ implementation of the Turbo Module.
|
|
6
|
+
// Bridges React Native JS to Swift SDK via AdShiftReactNativePluginHelper.
|
|
7
|
+
//
|
|
8
|
+
// Copyright © 2025 AdShift. All rights reserved.
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
#import "AdShiftReactNativePlugin.h"
|
|
12
|
+
#import <React/RCTLog.h>
|
|
13
|
+
|
|
14
|
+
// Import Swift module (generated by Xcode)
|
|
15
|
+
#if __has_include(<AdShiftReactNativePlugin/AdShiftReactNativePlugin-Swift.h>)
|
|
16
|
+
#import <AdShiftReactNativePlugin/AdShiftReactNativePlugin-Swift.h>
|
|
17
|
+
#elif __has_include("AdShiftReactNativePlugin-Swift.h")
|
|
18
|
+
#import "AdShiftReactNativePlugin-Swift.h"
|
|
19
|
+
#else
|
|
20
|
+
// Fallback for development builds
|
|
21
|
+
@class AdShiftReactNativePluginHelper;
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
@implementation AdShiftReactNativePlugin {
|
|
25
|
+
BOOL _hasListeners;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
RCT_EXPORT_MODULE(AdShiftReactNativePlugin)
|
|
29
|
+
|
|
30
|
+
// MARK: - Module Setup
|
|
31
|
+
|
|
32
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
33
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
34
|
+
return std::make_shared<facebook::react::NativeAdShiftReactNativePluginSpecJSI>(params);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// MARK: - Event Emitter Support
|
|
38
|
+
|
|
39
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
40
|
+
return @[@"onDeepLink"];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (void)startObserving {
|
|
44
|
+
_hasListeners = YES;
|
|
45
|
+
|
|
46
|
+
// Register deep link callback with Swift helper
|
|
47
|
+
if (@available(iOS 15.0, *)) {
|
|
48
|
+
[[AdShiftReactNativePluginHelper shared] setDeepLinkEventCallback:^(NSDictionary<NSString *, id> *event) {
|
|
49
|
+
if (self->_hasListeners) {
|
|
50
|
+
[self sendEventWithName:@"onDeepLink" body:event];
|
|
51
|
+
}
|
|
52
|
+
}];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
- (void)stopObserving {
|
|
57
|
+
_hasListeners = NO;
|
|
58
|
+
|
|
59
|
+
if (@available(iOS 15.0, *)) {
|
|
60
|
+
[[AdShiftReactNativePluginHelper shared] clearDeepLinkEventCallback];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// MARK: - Lifecycle Methods
|
|
65
|
+
|
|
66
|
+
- (void)initialize:(NSDictionary *)config {
|
|
67
|
+
RCTLogInfo(@"[AdShift] Initializing SDK with config");
|
|
68
|
+
|
|
69
|
+
if (@available(iOS 15.0, *)) {
|
|
70
|
+
[[AdShiftReactNativePluginHelper shared] initializeWithConfig:config];
|
|
71
|
+
} else {
|
|
72
|
+
RCTLogWarn(@"[AdShift] iOS 15.0+ required");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
- (void)start:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
77
|
+
RCTLogInfo(@"[AdShift] Starting SDK");
|
|
78
|
+
|
|
79
|
+
if (@available(iOS 15.0, *)) {
|
|
80
|
+
[[AdShiftReactNativePluginHelper shared] startWithCompletion:^(NSDictionary *result, NSError *error) {
|
|
81
|
+
if (error) {
|
|
82
|
+
reject(@"START_ERROR", error.localizedDescription, error);
|
|
83
|
+
} else {
|
|
84
|
+
resolve(result ?: @{@"success": @YES});
|
|
85
|
+
}
|
|
86
|
+
}];
|
|
87
|
+
} else {
|
|
88
|
+
reject(@"UNSUPPORTED", @"iOS 15.0+ required", nil);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
- (void)stop {
|
|
93
|
+
RCTLogInfo(@"[AdShift] Stopping SDK");
|
|
94
|
+
|
|
95
|
+
if (@available(iOS 15.0, *)) {
|
|
96
|
+
[[AdShiftReactNativePluginHelper shared] stop];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
- (NSNumber *)isStarted {
|
|
101
|
+
if (@available(iOS 15.0, *)) {
|
|
102
|
+
BOOL started = [[AdShiftReactNativePluginHelper shared] isStarted];
|
|
103
|
+
return @(started);
|
|
104
|
+
}
|
|
105
|
+
return @NO;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// MARK: - Configuration Methods
|
|
109
|
+
|
|
110
|
+
- (void)setCustomerUserId:(NSString *)userId {
|
|
111
|
+
RCTLogInfo(@"[AdShift] Setting customer user ID");
|
|
112
|
+
|
|
113
|
+
if (@available(iOS 15.0, *)) {
|
|
114
|
+
[[AdShiftReactNativePluginHelper shared] setCustomerUserId:userId];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
- (void)setDebugEnabled:(BOOL)enabled {
|
|
119
|
+
RCTLogInfo(@"[AdShift] Setting debug enabled: %@", enabled ? @"YES" : @"NO");
|
|
120
|
+
|
|
121
|
+
if (@available(iOS 15.0, *)) {
|
|
122
|
+
[[AdShiftReactNativePluginHelper shared] setDebugEnabled:enabled];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
- (void)setAppOpenDebounceMs:(double)ms {
|
|
127
|
+
RCTLogInfo(@"[AdShift] Setting app open debounce: %.0fms", ms);
|
|
128
|
+
|
|
129
|
+
if (@available(iOS 15.0, *)) {
|
|
130
|
+
[[AdShiftReactNativePluginHelper shared] setAppOpenDebounceMs:(NSInteger)ms];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// MARK: - Consent Methods
|
|
135
|
+
|
|
136
|
+
- (void)setConsentData:(NSDictionary *)consent {
|
|
137
|
+
RCTLogInfo(@"[AdShift] Setting consent data");
|
|
138
|
+
|
|
139
|
+
if (@available(iOS 15.0, *)) {
|
|
140
|
+
[[AdShiftReactNativePluginHelper shared] setConsentData:consent];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
- (void)enableTCFDataCollection:(BOOL)enabled {
|
|
145
|
+
RCTLogInfo(@"[AdShift] Setting TCF data collection: %@", enabled ? @"YES" : @"NO");
|
|
146
|
+
|
|
147
|
+
if (@available(iOS 15.0, *)) {
|
|
148
|
+
[[AdShiftReactNativePluginHelper shared] enableTCFDataCollection:enabled];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
- (void)refreshConsent:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
153
|
+
RCTLogInfo(@"[AdShift] Refreshing consent");
|
|
154
|
+
|
|
155
|
+
if (@available(iOS 15.0, *)) {
|
|
156
|
+
[[AdShiftReactNativePluginHelper shared] refreshConsentWithCompletion:^(NSDictionary *result, NSError *error) {
|
|
157
|
+
if (error) {
|
|
158
|
+
reject(@"CONSENT_ERROR", error.localizedDescription, error);
|
|
159
|
+
} else {
|
|
160
|
+
resolve(result ?: @{});
|
|
161
|
+
}
|
|
162
|
+
}];
|
|
163
|
+
} else {
|
|
164
|
+
reject(@"UNSUPPORTED", @"iOS 15.0+ required", nil);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// MARK: - Event Tracking Methods
|
|
169
|
+
|
|
170
|
+
- (void)trackEvent:(NSString *)eventName
|
|
171
|
+
values:(NSDictionary *)values
|
|
172
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
173
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
174
|
+
RCTLogInfo(@"[AdShift] Tracking event: %@", eventName);
|
|
175
|
+
|
|
176
|
+
if (@available(iOS 15.0, *)) {
|
|
177
|
+
[[AdShiftReactNativePluginHelper shared] trackEvent:eventName
|
|
178
|
+
values:values
|
|
179
|
+
completion:^(NSDictionary *result, NSError *error) {
|
|
180
|
+
if (error) {
|
|
181
|
+
reject(@"TRACK_ERROR", error.localizedDescription, error);
|
|
182
|
+
} else {
|
|
183
|
+
resolve(nil);
|
|
184
|
+
}
|
|
185
|
+
}];
|
|
186
|
+
} else {
|
|
187
|
+
reject(@"UNSUPPORTED", @"iOS 15.0+ required", nil);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
- (void)trackPurchase:(NSString *)productId
|
|
192
|
+
price:(double)price
|
|
193
|
+
currency:(NSString *)currency
|
|
194
|
+
token:(NSString *)token
|
|
195
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
196
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
197
|
+
RCTLogInfo(@"[AdShift] Tracking purchase: %@", productId);
|
|
198
|
+
|
|
199
|
+
if (@available(iOS 15.0, *)) {
|
|
200
|
+
[[AdShiftReactNativePluginHelper shared] trackPurchaseWithProductId:productId
|
|
201
|
+
price:price
|
|
202
|
+
currency:currency
|
|
203
|
+
token:token
|
|
204
|
+
completion:^(NSDictionary *result, NSError *error) {
|
|
205
|
+
if (error) {
|
|
206
|
+
reject(@"TRACK_ERROR", error.localizedDescription, error);
|
|
207
|
+
} else {
|
|
208
|
+
resolve(nil);
|
|
209
|
+
}
|
|
210
|
+
}];
|
|
211
|
+
} else {
|
|
212
|
+
reject(@"UNSUPPORTED", @"iOS 15.0+ required", nil);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// MARK: - Deep Link Methods
|
|
217
|
+
|
|
218
|
+
- (void)handleDeepLink:(NSString *)url
|
|
219
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
220
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
221
|
+
RCTLogInfo(@"[AdShift] Handling deep link: %@", url);
|
|
222
|
+
|
|
223
|
+
if (@available(iOS 15.0, *)) {
|
|
224
|
+
[[AdShiftReactNativePluginHelper shared] handleDeepLink:url
|
|
225
|
+
completion:^(NSDictionary *result, NSError *error) {
|
|
226
|
+
if (error) {
|
|
227
|
+
// Return error as result, not reject (consistent with TypeScript API)
|
|
228
|
+
resolve(@{
|
|
229
|
+
@"status": @"error",
|
|
230
|
+
@"errorMessage": error.localizedDescription,
|
|
231
|
+
@"isDeferred": @NO
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
resolve(result ?: @{@"status": @"notFound", @"isDeferred": @NO});
|
|
235
|
+
}
|
|
236
|
+
}];
|
|
237
|
+
} else {
|
|
238
|
+
resolve(@{
|
|
239
|
+
@"status": @"error",
|
|
240
|
+
@"errorMessage": @"iOS 15.0+ required",
|
|
241
|
+
@"isDeferred": @NO
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// MARK: - Event Emitter Required Methods
|
|
247
|
+
|
|
248
|
+
- (void)addListener:(NSString *)eventType {
|
|
249
|
+
// Required by NativeEventEmitter
|
|
250
|
+
// Actual setup done in startObserving
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
- (void)removeListeners:(double)count {
|
|
254
|
+
// Required by NativeEventEmitter
|
|
255
|
+
// Actual cleanup done in stopObserving
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@end
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AdShiftReactNativePluginHelper.swift
|
|
3
|
+
// AdShiftReactNativePlugin
|
|
4
|
+
//
|
|
5
|
+
// Swift helper that bridges Objective-C++ Turbo Module to Swift SDK.
|
|
6
|
+
// Provides @objc compatible wrappers for Swift-only features.
|
|
7
|
+
//
|
|
8
|
+
// Copyright © 2025 AdShift. All rights reserved.
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
import Foundation
|
|
12
|
+
import AdshiftSDK
|
|
13
|
+
|
|
14
|
+
/// Callback types for async operations
|
|
15
|
+
public typealias StartCallback = ([String: Any]?, Error?) -> Void
|
|
16
|
+
public typealias TrackCallback = ([String: Any]?, Error?) -> Void
|
|
17
|
+
public typealias DeepLinkCallback = ([String: Any]?, Error?) -> Void
|
|
18
|
+
public typealias DeepLinkEventCallback = ([String: Any]) -> Void
|
|
19
|
+
|
|
20
|
+
/// React Native helper class that provides @objc compatible methods for the Swift SDK.
|
|
21
|
+
///
|
|
22
|
+
/// This is needed because:
|
|
23
|
+
/// 1. AdshiftSDK uses @MainActor which requires Swift
|
|
24
|
+
/// 2. Swift enums with associated values don't export to Objective-C
|
|
25
|
+
/// 3. Swift async/await needs to be converted to callbacks for ObjC++
|
|
26
|
+
@available(iOS 15.0, *)
|
|
27
|
+
@objc public class AdShiftReactNativePluginHelper: NSObject {
|
|
28
|
+
|
|
29
|
+
/// Shared instance
|
|
30
|
+
@objc public static let shared = AdShiftReactNativePluginHelper()
|
|
31
|
+
|
|
32
|
+
/// Stored deep link event callback for NativeEventEmitter
|
|
33
|
+
private var deepLinkEventCallback: DeepLinkEventCallback?
|
|
34
|
+
|
|
35
|
+
/// Whether deep link listener is registered
|
|
36
|
+
private var isDeepLinkListenerRegistered = false
|
|
37
|
+
|
|
38
|
+
private override init() {
|
|
39
|
+
super.init()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// MARK: - SDK Lifecycle
|
|
43
|
+
|
|
44
|
+
/// Initializes the SDK with configuration dictionary
|
|
45
|
+
@objc public func initialize(config: [String: Any]) {
|
|
46
|
+
Task { @MainActor in
|
|
47
|
+
// Required: API key
|
|
48
|
+
if let apiKey = config["apiKey"] as? String, !apiKey.isEmpty {
|
|
49
|
+
Adshift.shared.apiKey = apiKey
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Optional: Debug mode
|
|
53
|
+
if let isDebug = config["isDebug"] as? Bool {
|
|
54
|
+
Adshift.shared.isDebug = isDebug
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Optional: App open debounce
|
|
58
|
+
if let appOpenDebounceMs = config["appOpenDebounceMs"] as? Int {
|
|
59
|
+
Adshift.shared.appOpenDebounceMs = appOpenDebounceMs
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// iOS only: SKAN settings
|
|
63
|
+
if let disableSKAN = config["disableSKAN"] as? Bool {
|
|
64
|
+
Adshift.shared.disableSKAN = disableSKAN
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// iOS only: ATT settings
|
|
68
|
+
if let waitForATTBeforeStart = config["waitForATTBeforeStart"] as? Bool {
|
|
69
|
+
Adshift.shared.waitForATTBeforeStart = waitForATTBeforeStart
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if let attTimeoutMs = config["attTimeoutMs"] as? Int {
|
|
73
|
+
Adshift.shared.attTimeoutMs = attTimeoutMs
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Android only options are ignored on iOS (collectOaid)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// Starts the SDK with completion callback
|
|
81
|
+
@objc public func start(completion: @escaping StartCallback) {
|
|
82
|
+
Task { @MainActor in
|
|
83
|
+
Adshift.shared.start { response, error in
|
|
84
|
+
if let error = error {
|
|
85
|
+
completion(nil, error)
|
|
86
|
+
} else {
|
|
87
|
+
completion(response ?? ["success": true], nil)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// Stops the SDK
|
|
94
|
+
@objc public func stop() {
|
|
95
|
+
Task { @MainActor in
|
|
96
|
+
Adshift.shared.stop()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/// Checks if SDK is started
|
|
101
|
+
@objc public func isStarted() -> Bool {
|
|
102
|
+
// Must dispatch to MainActor since Adshift.shared is @MainActor isolated
|
|
103
|
+
var result = false
|
|
104
|
+
if Thread.isMainThread {
|
|
105
|
+
result = MainActor.assumeIsolated {
|
|
106
|
+
Adshift.shared.isStarted()
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
DispatchQueue.main.sync {
|
|
110
|
+
result = MainActor.assumeIsolated {
|
|
111
|
+
Adshift.shared.isStarted()
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// MARK: - Configuration
|
|
119
|
+
|
|
120
|
+
/// Sets customer user ID
|
|
121
|
+
@objc public func setCustomerUserId(_ userId: String) {
|
|
122
|
+
Task { @MainActor in
|
|
123
|
+
Adshift.shared.setCustomerUserId(userId)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// Sets debug mode
|
|
128
|
+
@objc public func setDebugEnabled(_ enabled: Bool) {
|
|
129
|
+
Task { @MainActor in
|
|
130
|
+
Adshift.shared.isDebug = enabled
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// Sets app open debounce interval
|
|
135
|
+
@objc public func setAppOpenDebounceMs(_ milliseconds: Int) {
|
|
136
|
+
Task { @MainActor in
|
|
137
|
+
Adshift.shared.appOpenDebounceMs = milliseconds
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// MARK: - Consent
|
|
142
|
+
|
|
143
|
+
/// Sets consent data from dictionary
|
|
144
|
+
@objc public func setConsentData(_ consentDict: [String: Any]) {
|
|
145
|
+
Task { @MainActor in
|
|
146
|
+
let isGDPR = consentDict["isUserSubjectToGDPR"] as? Bool ?? false
|
|
147
|
+
let dataUsage = consentDict["hasConsentForDataUsage"] as? Bool ?? false
|
|
148
|
+
let personalization = consentDict["hasConsentForAdsPersonalization"] as? Bool ?? false
|
|
149
|
+
let storage = consentDict["hasConsentForAdStorage"] as? Bool ?? false
|
|
150
|
+
|
|
151
|
+
let consent: AdShiftConsent
|
|
152
|
+
if isGDPR {
|
|
153
|
+
consent = AdShiftConsent.forGDPRUser(
|
|
154
|
+
hasConsentForDataUsage: dataUsage,
|
|
155
|
+
hasConsentForAdsPersonalization: personalization,
|
|
156
|
+
hasConsentForAdStorage: storage
|
|
157
|
+
)
|
|
158
|
+
} else {
|
|
159
|
+
consent = AdShiftConsent.forNonGDPRUser()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Adshift.shared.setConsentData(consent)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// Enables/disables TCF data collection
|
|
167
|
+
@objc public func enableTCFDataCollection(_ enabled: Bool) {
|
|
168
|
+
Task { @MainActor in
|
|
169
|
+
Adshift.shared.enableTCFDataCollection(enabled)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// Refreshes consent state
|
|
174
|
+
@objc public func refreshConsent(completion: @escaping ([String: Any]?, Error?) -> Void) {
|
|
175
|
+
Task { @MainActor in
|
|
176
|
+
let snapshot = Adshift.shared.refreshConsent()
|
|
177
|
+
// Convert ConsentSnapshot to dictionary
|
|
178
|
+
var result: [String: Any] = [
|
|
179
|
+
"source": snapshot.source.rawValue.lowercased(),
|
|
180
|
+
"tcStringPresent": snapshot.tcStringPresent,
|
|
181
|
+
"appliedAtMillis": snapshot.appliedAtMillis
|
|
182
|
+
]
|
|
183
|
+
|
|
184
|
+
// Optional fields
|
|
185
|
+
if let gdprApplies = snapshot.gdprApplies {
|
|
186
|
+
result["gdprApplies"] = gdprApplies
|
|
187
|
+
}
|
|
188
|
+
if let adUserDataEnabled = snapshot.adUserDataEnabled {
|
|
189
|
+
result["adUserDataEnabled"] = adUserDataEnabled
|
|
190
|
+
}
|
|
191
|
+
if let adPersonalizationEnabled = snapshot.adPersonalizationEnabled {
|
|
192
|
+
result["adPersonalizationEnabled"] = adPersonalizationEnabled
|
|
193
|
+
}
|
|
194
|
+
if let adStorageEnabled = snapshot.adStorageEnabled {
|
|
195
|
+
result["adStorageEnabled"] = adStorageEnabled
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Convenience field for JS
|
|
199
|
+
result["hasConsent"] = (snapshot.adStorageEnabled == true) || (snapshot.adUserDataEnabled == true)
|
|
200
|
+
|
|
201
|
+
completion(result, nil)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// MARK: - Event Tracking
|
|
206
|
+
|
|
207
|
+
/// Tracks an event with optional values
|
|
208
|
+
@objc public func trackEvent(
|
|
209
|
+
_ eventName: String,
|
|
210
|
+
values: [String: Any]?,
|
|
211
|
+
completion: @escaping TrackCallback
|
|
212
|
+
) {
|
|
213
|
+
Task { @MainActor in
|
|
214
|
+
let eventType = mapStringToEventType(eventName)
|
|
215
|
+
|
|
216
|
+
await Adshift.shared.track(
|
|
217
|
+
event: eventType,
|
|
218
|
+
values: values,
|
|
219
|
+
completionHandler: { response, error in
|
|
220
|
+
if let error = error {
|
|
221
|
+
completion(nil, error)
|
|
222
|
+
} else {
|
|
223
|
+
completion(response, nil)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/// Tracks a purchase event
|
|
231
|
+
@objc public func trackPurchase(
|
|
232
|
+
productId: String,
|
|
233
|
+
price: Double,
|
|
234
|
+
currency: String,
|
|
235
|
+
token: String,
|
|
236
|
+
completion: @escaping TrackCallback
|
|
237
|
+
) {
|
|
238
|
+
Task { @MainActor in
|
|
239
|
+
await Adshift.shared.trackPurchase(
|
|
240
|
+
productId: productId,
|
|
241
|
+
price: price,
|
|
242
|
+
currency: currency,
|
|
243
|
+
token: token,
|
|
244
|
+
completionHandler: { response, error in
|
|
245
|
+
if let error = error {
|
|
246
|
+
completion(nil, error)
|
|
247
|
+
} else {
|
|
248
|
+
completion(response, nil)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// MARK: - Deep Links
|
|
256
|
+
|
|
257
|
+
/// Handles a deep link URL
|
|
258
|
+
@objc public func handleDeepLink(
|
|
259
|
+
_ urlString: String,
|
|
260
|
+
completion: @escaping DeepLinkCallback
|
|
261
|
+
) {
|
|
262
|
+
guard let url = URL(string: urlString) else {
|
|
263
|
+
let error = NSError(
|
|
264
|
+
domain: "AdShiftReactNativePlugin",
|
|
265
|
+
code: -1,
|
|
266
|
+
userInfo: [NSLocalizedDescriptionKey: "Invalid URL: \(urlString)"]
|
|
267
|
+
)
|
|
268
|
+
completion(nil, error)
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
Task { @MainActor in
|
|
273
|
+
do {
|
|
274
|
+
let response = try await Adshift.shared.handleDeepLink(url: url)
|
|
275
|
+
let result = serializeDeepLinkResponse(response)
|
|
276
|
+
completion(result, nil)
|
|
277
|
+
} catch {
|
|
278
|
+
let result: [String: Any] = [
|
|
279
|
+
"status": "error",
|
|
280
|
+
"errorMessage": error.localizedDescription,
|
|
281
|
+
"isDeferred": false
|
|
282
|
+
]
|
|
283
|
+
completion(result, nil)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/// Registers deep link event callback for NativeEventEmitter
|
|
289
|
+
@objc public func setDeepLinkEventCallback(_ callback: @escaping DeepLinkEventCallback) {
|
|
290
|
+
self.deepLinkEventCallback = callback
|
|
291
|
+
|
|
292
|
+
// Register with native SDK only once
|
|
293
|
+
if !isDeepLinkListenerRegistered {
|
|
294
|
+
Task { @MainActor in
|
|
295
|
+
Adshift.shared.onDeepLinkReceived { [weak self] response in
|
|
296
|
+
guard let self = self, let callback = self.deepLinkEventCallback else { return }
|
|
297
|
+
let serialized = self.serializeDeepLinkResponse(response)
|
|
298
|
+
callback(serialized)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
isDeepLinkListenerRegistered = true
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/// Clears deep link event callback
|
|
306
|
+
@objc public func clearDeepLinkEventCallback() {
|
|
307
|
+
deepLinkEventCallback = nil
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// MARK: - Private Helpers
|
|
311
|
+
|
|
312
|
+
/// Maps string event name to ASInAppEventType enum
|
|
313
|
+
private func mapStringToEventType(_ eventName: String) -> ASInAppEventType {
|
|
314
|
+
switch eventName {
|
|
315
|
+
case "as_purchase": return .purchase
|
|
316
|
+
case "as_login": return .login
|
|
317
|
+
case "as_add_to_cart": return .addToCart
|
|
318
|
+
case "as_add_to_wishlist": return .addToWishList
|
|
319
|
+
case "as_add_payment_info": return .addPaymentInfo
|
|
320
|
+
case "as_initiated_checkout": return .initiatedCheckout
|
|
321
|
+
case "as_complete_registration": return .completeRegistration
|
|
322
|
+
case "as_tutorial_completion": return .tutorialCompletion
|
|
323
|
+
case "as_level_achieved": return .levelAchieved
|
|
324
|
+
case "as_achievement_unlocked": return .achievementUnlocked
|
|
325
|
+
case "as_content_view": return .contentView
|
|
326
|
+
case "as_list_view": return .listView
|
|
327
|
+
case "as_search": return .search
|
|
328
|
+
case "as_rate": return .rate
|
|
329
|
+
case "as_share": return .share
|
|
330
|
+
case "as_invite": return .invite
|
|
331
|
+
case "as_re_engage": return .reEngage
|
|
332
|
+
case "as_update": return .update
|
|
333
|
+
case "as_opened_from_push_notification": return .openedFromPushNotification
|
|
334
|
+
case "as_subscribe": return .subscribe
|
|
335
|
+
case "as_start_trial": return .startTrial
|
|
336
|
+
case "as_ad_click": return .adClick
|
|
337
|
+
case "as_ad_view": return .adView
|
|
338
|
+
case "as_spent_credits": return .spentCredit
|
|
339
|
+
case "as_travel_booking": return .travelBooking
|
|
340
|
+
case "as_location_changed": return .locationChanged
|
|
341
|
+
case "as_location_coordinates": return .locationCoordinates
|
|
342
|
+
case "as_order_id": return .orderId
|
|
343
|
+
case "as_customer_segment": return .customerSegment
|
|
344
|
+
default: return .customEvent(eventName)
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/// Serializes DeeplinkResponse to dictionary for React Native
|
|
349
|
+
private func serializeDeepLinkResponse(_ response: DeeplinkResponse) -> [String: Any] {
|
|
350
|
+
var result: [String: Any] = [:]
|
|
351
|
+
|
|
352
|
+
// Deep link URL
|
|
353
|
+
if let deeplink = response.deeplink {
|
|
354
|
+
result["deepLink"] = deeplink
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Deep link value (for routing)
|
|
358
|
+
if let value = response.deep_link_value {
|
|
359
|
+
result["deepLinkValue"] = value
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Sub parameters
|
|
363
|
+
if let sub1 = response.deep_link_sub1 { result["deepLinkSub1"] = sub1 }
|
|
364
|
+
if let sub2 = response.deep_link_sub2 { result["deepLinkSub2"] = sub2 }
|
|
365
|
+
if let sub3 = response.deep_link_sub3 { result["deepLinkSub3"] = sub3 }
|
|
366
|
+
if let sub4 = response.deep_link_sub4 { result["deepLinkSub4"] = sub4 }
|
|
367
|
+
if let sub5 = response.deep_link_sub5 { result["deepLinkSub5"] = sub5 }
|
|
368
|
+
|
|
369
|
+
// Parameters
|
|
370
|
+
if let params = response.params, !params.isEmpty {
|
|
371
|
+
result["params"] = params
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Is deferred
|
|
375
|
+
result["isDeferred"] = response.isDeferred ?? false
|
|
376
|
+
|
|
377
|
+
// Status
|
|
378
|
+
if let status = response.status {
|
|
379
|
+
switch status {
|
|
380
|
+
case .found:
|
|
381
|
+
result["status"] = "found"
|
|
382
|
+
case .notFound:
|
|
383
|
+
result["status"] = "notFound"
|
|
384
|
+
case .error:
|
|
385
|
+
result["status"] = "error"
|
|
386
|
+
@unknown default:
|
|
387
|
+
result["status"] = response.deeplink != nil ? "found" : "notFound"
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
result["status"] = response.deeplink != nil ? "found" : "notFound"
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Error message
|
|
394
|
+
if let error = response.error {
|
|
395
|
+
result["status"] = "error"
|
|
396
|
+
switch error {
|
|
397
|
+
case .decodingError:
|
|
398
|
+
result["errorMessage"] = "Decoding error"
|
|
399
|
+
case .invalidURL:
|
|
400
|
+
result["errorMessage"] = "Invalid URL"
|
|
401
|
+
case .deepLinkNotFound:
|
|
402
|
+
result["errorMessage"] = "Deep link not found"
|
|
403
|
+
case .systemError(let message):
|
|
404
|
+
result["errorMessage"] = message
|
|
405
|
+
@unknown default:
|
|
406
|
+
result["errorMessage"] = "Unknown error"
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return result
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|