Skip to content

Commit 7d2bc52

Browse files
authoredJun 4, 2024
Merge pull request #63 from apphud/feature/2.1.0
add paywallShown and paywallClosed methods
2 parents cd1a66f + 5341b7e commit 7d2bc52

File tree

13 files changed

+69
-15
lines changed

13 files changed

+69
-15
lines changed
 

‎android/src/main/java/com/reactnativeapphudsdk/ApphudDataTransformer.kt

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class ApphudDataTransformer {
5252

5353
fun getApphudPaywallMap(paywall: ApphudPaywall): WritableNativeMap {
5454
val result: WritableNativeMap = WritableNativeMap()
55-
Apphud.enableDebugLogs()
5655
result.putString("identifier", paywall.identifier)
5756
result.putBoolean("isDefault", paywall.default)
5857
result.putString("experimentName", paywall.experimentName)

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

+19-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
2222

2323
init {
2424
HeadersInterceptor.X_SDK = "reactnative"
25-
HeadersInterceptor.X_SDK_VERSION = "2.0.0"
25+
HeadersInterceptor.X_SDK_VERSION = "2.1.0"
2626
listener = ApphudListenerHandler(reactContext)
2727
listener?.let { Apphud.setListener(it) }
2828
}
@@ -73,6 +73,22 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
7373
}
7474
}
7575

76+
@ReactMethod
77+
fun paywallShown(identifier: String) {
78+
val paywall = Apphud.paywalls().firstOrNull { it.identifier == identifier }
79+
paywall?.let {
80+
Apphud.paywallShown(it)
81+
}
82+
}
83+
84+
@ReactMethod
85+
fun paywallClosed(identifier: String) {
86+
val paywall = Apphud.paywalls().firstOrNull { it.identifier == identifier }
87+
paywall?.let {
88+
Apphud.paywallClosed(it)
89+
}
90+
}
91+
7692
@ReactMethod
7793
fun purchase(args: ReadableMap, promise: Promise) {
7894
val productId = args.getString("productId")
@@ -96,7 +112,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
96112

97113
val isSub = product?.productDetails?.productType?.lowercase() == "subs"
98114
val offerToken = args.getString("offerToken")
99-
val isConsumable = args.getBoolean("isConsumable")
115+
val isConsumable = if (args.hasKey("isConsumable")) args.getBoolean("isConsumable") else false
100116

101117
if (product == null) {
102118
promise.reject("Error", "Product not found")
@@ -270,6 +286,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
270286
Apphud.collectDeviceIdentifiers()
271287
}
272288

289+
273290
@ReactMethod
274291
fun enableDebugLogs() {
275292
Apphud.enableDebugLogs()

‎example/ios/.xcode.env

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

‎example/ios/ApphudSdkExample.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@
399399
);
400400
runOnlyForDeploymentPostprocessing = 0;
401401
shellPath = /bin/sh;
402-
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
402+
shellScript = "export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
403403
};
404404
2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = {
405405
isa = PBXShellScriptBuildPhase;

‎example/ios/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,4 @@ SPEC CHECKSUMS:
580580

581581
PODFILE CHECKSUM: 47a16e2930bdcf8baadcf3fe4873c7f378dc927c
582582

583-
COCOAPODS: 1.14.2
583+
COCOAPODS: 1.15.2

‎example/src/screens/ActionsScreen.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,13 @@ export default function ActionsScreen({ navigation }: Props) {
4444
const [paywalls, setPaywalls] = React.useState<Array<ApphudPaywall>>();
4545

4646
const callAll = () => {
47-
// ApphudSdk.enableDebugLogs();
47+
ApphudSdk.enableDebugLogs();
4848

4949
// ApphudSdk.setAdvertisingIdentifier('42ed88fd-b446-4eb1-81ae-83e3025c04cf')
5050

5151
// ApphudSdk.userId().then((userId) => console.log(`Apphud: userId: ${userId}`));
52-
// ApphudSdk.hasActiveSubscription().then((hasActiveSubscription) =>
53-
// console.log(`Apphud: hasActiveSubscription: ${hasActiveSubscription}`)
54-
// );
55-
// ApphudSdk.hasPremiumAccess().then((hasPremiumAccess) =>
56-
// console.log(`Apphud: hasPremiumAccess: ${hasPremiumAccess}`)
57-
// );
52+
ApphudSdk.hasActiveSubscription().then((active) => console.log('START Has Active Subscription: = ' + active));
53+
5854

5955
// ApphudSdk.setUserProperty({key: 'some_string_key2', value: 'some_string_valueee', setOnce: true})
6056
// ApphudSdk.setUserProperty({key: 'some_float_key3', value: 1.45, setOnce: true})

‎example/src/screens/LoginScreen.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export default function LoginScreen({ navigation }: Props) {
2020

2121
const onStartHandler = () => {
2222
ApphudSdk.start({ apiKey, userId, deviceId, observerMode: false })
23+
24+
// ApphudSdk.hasActiveSubscription().then((active) => console.log('START Has Active Subscription: = ' + hasActive));
25+
2326
navigation.navigate('Actions')
2427
}
2528

‎example/src/screens/PaywallScreen.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default function PaywallScreen({ route, navigation}: { route: any, naviga
5353
for (const paywall of paywalls) {
5454
if (paywall.identifier === route.params.paywallId) {
5555
setCurrentPaywall(paywall);
56+
await ApphudSdk.paywallShown(paywall.identifier);
5657
const productsPropsList: ProductProps[] = preparedProducts(paywall.products);
5758
setProductsProps(productsPropsList);
5859
return paywall;

‎ios/.xcode.env

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

‎ios/ApphudSdk.m

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ @interface RCT_EXTERN_MODULE(ApphudSdk, NSObject)
4646

4747
RCT_EXTERN_METHOD(collectDeviceIdentifiers)
4848
RCT_EXTERN_METHOD(setAdvertisingIdentifier:(NSString*)idfa)
49+
RCT_EXTERN_METHOD(paywallShown:(NSString*)identifier)
50+
RCT_EXTERN_METHOD(paywallClosed:(NSString*)identifier)
4951
RCT_EXTERN_METHOD(optOutOfTracking)
5052
RCT_EXTERN_METHOD(enableDebugLogs)
5153
RCT_EXTERN_METHOD(logout:(RCTPromiseResolveBlock)resolve)

‎ios/ApphudSdk.swift

+23-1
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.0.0";
9+
ApphudHttpClient.shared.sdkVersion = "2.1.0";
1010
}
1111

1212
@objc(start:)
@@ -15,6 +15,9 @@ class ApphudSdk: NSObject {
1515
let userID = options["userId"] as? String;
1616
let observerMode = options["observerMode"] as? Bool ?? true;
1717
DispatchQueue.main.async {
18+
#if DEBUG
19+
ApphudUtils.enableAllLogs()
20+
#endif
1821
Apphud.start(apiKey: apiKey, userID: userID, observerMode: observerMode);
1922
}
2023
}
@@ -130,6 +133,25 @@ class ApphudSdk: NSObject {
130133
}
131134
}
132135

136+
@objc(paywallShown:)
137+
func paywallShown(identifier: String) {
138+
print("Paywall Shown: \(identifier)")
139+
Task {
140+
if let paywall = await Apphud.paywalls().first(where: { $0.identifier == identifier }) {
141+
Apphud.paywallShown(paywall)
142+
}
143+
}
144+
}
145+
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+
}
154+
133155
@objc(subscription:withRejecter:)
134156
func subscription(resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
135157
guard let subscription = Apphud.subscription() else {

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apphud/react-native-apphud-sdk",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Apphud SDK for react native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

‎src/ApphudSdkType.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ export type ApphudSdkType = {
3434
* Method returns immediately if paywalls are cached or already loaded.
3535
* @returns paywalls configured in Apphud Dashboard > Product Hub > Paywalls.
3636
*/
37-
paywalls(): Promise<Array<ApphudPaywall>>;
37+
paywalls(): Promise<Array<ApphudPaywall>>;
38+
39+
/**
40+
* Available on iOS and Android
41+
* Logs a "Paywall Shown" (Paywall View) event which is required for A/B Testing Analytics.
42+
*/
43+
paywallShown(identifier: string): void;
44+
45+
/**
46+
* Available on iOS and Android
47+
* Logs a "Paywall Closed" event. Optional.
48+
*/
49+
paywallClosed(identifier: string): void;
3850

3951
/**
4052
* Available on iOS and Android.

0 commit comments

Comments
 (0)
Please sign in to comment.