Skip to content

Commit 373309c

Browse files
committed
attribute from web test
1 parent 955c81b commit 373309c

File tree

13 files changed

+133
-48
lines changed

13 files changed

+133
-48
lines changed

.yarnrc.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ enableGlobalCache: false
44

55
nmHoistingLimits: workspaces
66

7-
nodeLinker: node-modules
8-
9-
yarnPath: .yarn/releases/yarn-3.6.1.cjs
7+
nodeLinker: node-modules

android/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
137137
dependencies {
138138
// noinspection GradleDynamicVersion
139139
api 'com.facebook.react:react-native:+'
140-
implementation 'com.apphud:ApphudSDK-Android:2.1.0'
140+
implementation 'com.apphud:ApphudSDK-Android:2.8.4'
141141
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
142-
implementation 'com.android.billingclient:billing:5.2.0'
142+
implementation 'com.android.billingclient:billing:7.1.1'
143143
}

android/src/main/java/com/reactnativeapphudsdk/ApphudSdkModule.kt

+23
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,29 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
173173
}
174174
}
175175

176+
@ReactMethod
177+
fun attributeFromWeb(options: ReadableMap, promise: Promise) {
178+
val data = options.toHashMap()?.let {
179+
val result = mutableMapOf<String, Any>()
180+
181+
for ((key, value) in it) {
182+
value?.let {
183+
result[key] = it
184+
}
185+
}
186+
187+
return@let result
188+
}
189+
190+
Apphud.attributeFromWeb(data) { result, user ->
191+
val result: WritableNativeMap = WritableNativeMap()
192+
result.putString("user_id", user?.userId ?: "")
193+
result.putBoolean("is_premium", Apphud.hasPremiumAccess())
194+
result.putBoolean("result", result)
195+
promise.resolve(result)
196+
}
197+
}
198+
176199
private fun stringToApphudAttributionProvider(value: String): ApphudAttributionProvider? {
177200
return enumValues<ApphudAttributionProvider>().find {
178201
it.name == value

example/ios/.xcode.env.local

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export NODE_BINARY=/opt/homebrew/Cellar/node@20/20.18.1/bin/node

example/ios/ApphudBridgeClass.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ApphudBridgeClass: NSObject {
1313
Apphud.submitPushNotificationsToken(token: data, callback: nil)
1414
}
1515

16-
@objc
16+
@MainActor @objc
1717
static func handleUserInfo(dict: [AnyHashable: Any]) {
1818
Apphud.handlePushNotification(apsInfo: dict)
1919
}

example/ios/ExampleApp.xcodeproj/project.pbxproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,10 @@
384384
"-DFOLLY_CFG_NO_COROUTINES=1",
385385
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
386386
);
387-
OTHER_LDFLAGS = "$(inherited) ";
387+
OTHER_LDFLAGS = (
388+
"$(inherited)",
389+
" ",
390+
);
388391
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
389392
SDKROOT = iphoneos;
390393
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -453,7 +456,10 @@
453456
"-DFOLLY_CFG_NO_COROUTINES=1",
454457
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
455458
);
456-
OTHER_LDFLAGS = "$(inherited) ";
459+
OTHER_LDFLAGS = (
460+
"$(inherited)",
461+
" ",
462+
);
457463
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
458464
SDKROOT = iphoneos;
459465
USE_HERMES = true;

example/ios/Podfile.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- ApphudSDK (3.1.4)
2+
- ApphudSDK (3.5.9)
33
- boost (1.84.0)
44
- DoubleConversion (1.1.6)
55
- fast_float (6.1.4)
@@ -1211,8 +1211,8 @@ PODS:
12111211
- React-jsiexecutor
12121212
- React-RCTFBReactNativeSpec
12131213
- ReactCommon/turbomodule/core
1214-
- react-native-apphud-sdk (2.1.0):
1215-
- ApphudSDK (= 3.1.4)
1214+
- react-native-apphud-sdk (2.2.0):
1215+
- ApphudSDK (= 3.5.9)
12161216
- React-Core
12171217
- react-native-safe-area-context (5.2.0):
12181218
- DoubleConversion
@@ -1932,7 +1932,7 @@ EXTERNAL SOURCES:
19321932
:path: "../node_modules/react-native/ReactCommon/yoga"
19331933

19341934
SPEC CHECKSUMS:
1935-
ApphudSDK: 5e5a30f21b8b44b864e5f16f2b2a122d2b906781
1935+
ApphudSDK: 4aad14717e9029d9e9defc205d75b4836cbed559
19361936
boost: 7e761d76ca2ce687f7cc98e698152abd03a18f90
19371937
DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb
19381938
fast_float: 06eeec4fe712a76acc9376682e4808b05ce978b6
@@ -1969,7 +1969,7 @@ SPEC CHECKSUMS:
19691969
React-logger: 1935d6e6461e9c8be4c87af56c56a4876021171e
19701970
React-Mapbuffer: 212171f037e3b22e6c2df839aa826806da480b85
19711971
React-microtasksnativemodule: 72564d5469003687d39bfc4efad281df8efc0684
1972-
react-native-apphud-sdk: c1ea12dd222d96375beed503e64cbf7451f0bcc8
1972+
react-native-apphud-sdk: 101e802e81c69f1ca8998ce2ec8c5fd961a52729
19731973
react-native-safe-area-context: 9c33120e9eac7741a5364cc2d9f74665049b76b3
19741974
React-nativeconfig: cb207ebba7cafce30657c7ad9f1587a8f32e4564
19751975
React-NativeModulesApple: 82a8bee52df9f5b378195a500f22be3a6ef0f890
@@ -2005,8 +2005,8 @@ SPEC CHECKSUMS:
20052005
RNReanimated: ef80cf675203a39bb5e5464234cb08a0f0040ac2
20062006
RNVectorIcons: 14a0c42f16a26bcc3e79a19bc1c5718284b1d469
20072007
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
2008-
Yoga: 2957d0e744897870b5a377f26522e3f08cadd7ac
2008+
Yoga: 1fd059161b449018342943b095a6d4e69bcaa719
20092009

20102010
PODFILE CHECKSUM: a12992b818b7dbdfe9a7e215f41593babfb4de2e
20112011

2012-
COCOAPODS: 1.15.2
2012+
COCOAPODS: 1.16.2

example/src/screens/ActionsScreen.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export default function ActionsScreen({ navigation }: Props) {
5050
console.log('START Has Active Subscription: = ' + active)
5151
);
5252

53+
ApphudSdk.attributeFromWeb({"apphud_user_id": "aaf48728-6854-4a37-9f3b-6ab59e66b4da"}).then((result) =>
54+
console.log('attribute from web result: = ' + JSON.stringify(result, null, 2))
55+
);
56+
5357
// ApphudSdk.setUserProperty({key: 'some_string_key2', value: 'some_string_valueee', setOnce: true})
5458
// ApphudSdk.setUserProperty({key: 'some_float_key3', value: 1.45, setOnce: true})
5559
// // ApphudSdk.incrementUserProperty({key: 'some2_float_ke2y', by: 2.01})

ios/ApphudSdk.m

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ @interface RCT_EXTERN_MODULE(ApphudSdk, NSObject)
5252
RCT_EXTERN_METHOD(enableDebugLogs)
5353
RCT_EXTERN_METHOD(logout:(RCTPromiseResolveBlock)resolve)
5454
RCT_EXTERN_METHOD(addAttribution:(NSDictionary*)options)
55+
RCT_EXTERN_METHOD(attributeFromWeb:(NSDictionary*)options withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
5556
RCT_EXTERN_METHOD(setUserProperty:(NSDictionary*)options)
5657
RCT_EXTERN_METHOD(incrementUserProperty:(NSDictionary*)options)
5758
RCT_EXTERN_METHOD(submitPushNotificationsToken:(NSString*)token)

ios/ApphudSdk.swift

+56-30
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ApphudSdk: NSObject {
66

77
override init() {
88
ApphudHttpClient.shared.sdkType = "reactnative";
9-
ApphudHttpClient.shared.sdkVersion = "2.1.0";
9+
ApphudHttpClient.shared.sdkVersion = "2.2.0";
1010
}
1111

1212
@objc(start:)
@@ -35,7 +35,9 @@ class ApphudSdk: NSObject {
3535

3636
@objc(logout)
3737
func logout() {
38-
Apphud.logout()
38+
Task {
39+
await Apphud.logout()
40+
}
3941
}
4042

4143
@objc(hasActiveSubscription:withRejecter:)
@@ -54,7 +56,18 @@ class ApphudSdk: NSObject {
5456
resolve(products.map { DataTransformer.skProduct(product: $0) });
5557
}
5658
}
57-
59+
60+
61+
func paywalls() async -> [ApphudPaywall] {
62+
await withCheckedContinuation { continuation in
63+
Task { @MainActor in
64+
Apphud.paywallsDidLoadCallback { paywalls, _ in
65+
continuation.resume(returning: paywalls)
66+
}
67+
}
68+
}
69+
}
70+
5871
@objc(purchase:withResolver:withRejecter:)
5972
func purchase(args: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
6073

@@ -64,9 +77,9 @@ class ApphudSdk: NSObject {
6477
}
6578
let paywallId = args["paywallId"] as? String
6679

67-
Task {
80+
Task { @MainActor in
6881
var product: ApphudProduct?
69-
let paywalls = await Apphud.paywalls()
82+
let paywalls = await paywalls()
7083

7184
for paywall in paywalls where product == nil {
7285
product = paywall.products.first { product in
@@ -124,35 +137,36 @@ class ApphudSdk: NSObject {
124137

125138
@objc(paywalls:withRejecter:)
126139
func paywalls(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
127-
Apphud.paywallsDidLoadCallback { paywalls in
128-
resolve(
129-
paywalls.map({ paywall in
130-
return paywall.toMap();
131-
})
132-
);
133-
}
140+
Task {
141+
let paywalls = await paywalls()
142+
resolve(
143+
paywalls.map({ paywall in
144+
return paywall.toMap();
145+
})
146+
);
147+
}
134148
}
135149

136150
@objc(paywallShown:)
137151
func paywallShown(identifier: String) {
138152
print("Paywall Shown: \(identifier)")
139153
Task {
140-
if let paywall = await Apphud.paywalls().first(where: { $0.identifier == identifier }) {
154+
if let paywall = await paywalls().first(where: { $0.identifier == identifier }) {
141155
Apphud.paywallShown(paywall)
142156
}
143157
}
144158
}
145159

146-
@objc(paywallClosed:)
147-
func paywallClosed(identifier: String) {
148-
Task {
149-
if let paywall = await Apphud.paywalls().first(where: { $0.identifier == identifier }) {
150-
Apphud.paywallClosed(paywall)
151-
}
152-
}
153-
}
160+
@objc(paywallClosed:)
161+
func paywallClosed(identifier: String) {
162+
Task {
163+
if let paywall = await paywalls().first(where: { $0.identifier == identifier }) {
164+
Apphud.paywallClosed(paywall)
165+
}
166+
}
167+
}
154168

155-
@objc(subscription:withRejecter:)
169+
@MainActor @objc(subscription:withRejecter:)
156170
func subscription(resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
157171
guard let subscription = Apphud.subscription() else {
158172
reject("Error", "User has no subscriptions", nil)
@@ -162,28 +176,29 @@ class ApphudSdk: NSObject {
162176
resolve(DataTransformer.apphudSubscription(subscription: subscription));
163177
}
164178

165-
@objc(subscriptions:withRejecter:)
179+
180+
@MainActor @objc(subscriptions:withRejecter:)
166181
func subscriptions(resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
167182
let subs = Apphud.subscriptions() ?? []
168183
let array: Array = subs.map { DataTransformer.apphudSubscription(subscription: $0) }
169184
resolve(array as NSArray)
170185
}
171186

172-
@objc(isNonRenewingPurchaseActive:withResolver:withRejecter:)
187+
@MainActor @objc(isNonRenewingPurchaseActive:withResolver:withRejecter:)
173188
func isNonRenewingPurchaseActive(productIdentifier: String, resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
174189
resolve(
175190
Apphud.isNonRenewingPurchaseActive(productIdentifier: productIdentifier)
176191
);
177192
}
178193

179-
@objc(nonRenewingPurchases:withRejecter:)
194+
@MainActor @objc(nonRenewingPurchases:withRejecter:)
180195
func nonRenewingPurchases(resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
181196
let purchases = Apphud.nonRenewingPurchases() ?? []
182197
let array: Array = purchases.map { DataTransformer.nonRenewingPurchase(nonRenewingPurchase: $0) }
183198
resolve(array)
184199
}
185200

186-
@objc(restorePurchases:withRejecter:)
201+
@MainActor @objc(restorePurchases:withRejecter:)
187202
func restorePurchases(resolve: @escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
188203
Apphud.restorePurchases { (subscriptions, purchases, error) in
189204
resolve([
@@ -200,7 +215,7 @@ class ApphudSdk: NSObject {
200215
}
201216
}
202217

203-
@objc(userId:withRejecter:)
218+
@MainActor @objc(userId:withRejecter:)
204219
func userId(resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
205220
resolve(
206221
Apphud.userID()
@@ -229,6 +244,17 @@ class ApphudSdk: NSObject {
229244

230245
Apphud.addAttribution(data: data, from: provider, identifer: identifier) { _ in }
231246
}
247+
248+
@MainActor @objc(attributeFromWeb:withResolver:withRejecter:)
249+
func attributeFromWeb(options: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
250+
guard let options = options as? [String: Any] else {
251+
reject("Invalid argument", "options must be a dictionary", nil)
252+
return
253+
}
254+
Apphud.attributeFromWeb(data: options) { result, user in
255+
resolve(["result": result, "user_id": user?.userId ?? "", "is_premium": Apphud.hasPremiumAccess()])
256+
}
257+
}
232258

233259
@objc(setUserProperty:)
234260
func setUserProperty(options: NSDictionary) {
@@ -248,7 +274,7 @@ class ApphudSdk: NSObject {
248274
Apphud.incrementUserProperty(key: _key, by: by)
249275
}
250276

251-
@objc(syncPurchasesInObserverMode:withRejecter:)
277+
@MainActor @objc(syncPurchasesInObserverMode:withRejecter:)
252278
func syncPurchasesInObserverMode(resolve: @escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
253279
Apphud.restorePurchases { _, _, _ in
254280
resolve(true)
@@ -257,12 +283,12 @@ class ApphudSdk: NSObject {
257283

258284
@objc(setAdvertisingIdentifier:)
259285
func setAdvertisingIdentifier(idfa: String) {
260-
Apphud.setAdvertisingIdentifier(idfa)
286+
Apphud.setDeviceIdentifiers(idfa: idfa, idfv: UIDevice.current.identifierForVendor?.uuidString)
261287
}
262288

263289
@objc(enableDebugLogs)
264290
func enableDebugLogs() {
265-
Apphud.enableDebugLogs()
291+
ApphudUtils.enableAllLogs()
266292
}
267293

268294
@objc(optOutOfTracking)

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apphud/react-native-apphud-sdk",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "Apphud SDK for react native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
@@ -143,5 +143,6 @@
143143
}
144144
]
145145
]
146-
}
146+
},
147+
"packageManager": "yarn@4.6.0+sha512.5383cc12567a95f1d668fbe762dfe0075c595b4bfff433be478dbbe24e05251a8e8c3eb992a986667c1d53b6c3a9c85b8398c35a960587fbd9fa3a0915406728"
147148
}

react-native-apphud-sdk.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ Pod::Spec.new do |s|
1818

1919

2020
s.dependency "React-Core"
21-
s.dependency "ApphudSDK", "3.1.4"
21+
s.dependency "ApphudSDK", "3.5.9"
2222
end

0 commit comments

Comments
 (0)