Skip to content

Commit

Permalink
Merge pull request #63 from apphud/feature/2.1.0
Browse files Browse the repository at this point in the history
add paywallShown and paywallClosed methods
  • Loading branch information
ren6 authored Jun 4, 2024
2 parents cd1a66f + 5341b7e commit 7d2bc52
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class ApphudDataTransformer {

fun getApphudPaywallMap(paywall: ApphudPaywall): WritableNativeMap {
val result: WritableNativeMap = WritableNativeMap()
Apphud.enableDebugLogs()
result.putString("identifier", paywall.identifier)
result.putBoolean("isDefault", paywall.default)
result.putString("experimentName", paywall.experimentName)
Expand Down
21 changes: 19 additions & 2 deletions android/src/main/java/com/reactnativeapphudsdk/ApphudSdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ

init {
HeadersInterceptor.X_SDK = "reactnative"
HeadersInterceptor.X_SDK_VERSION = "2.0.0"
HeadersInterceptor.X_SDK_VERSION = "2.1.0"
listener = ApphudListenerHandler(reactContext)
listener?.let { Apphud.setListener(it) }
}
Expand Down Expand Up @@ -73,6 +73,22 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
}
}

@ReactMethod
fun paywallShown(identifier: String) {
val paywall = Apphud.paywalls().firstOrNull { it.identifier == identifier }
paywall?.let {
Apphud.paywallShown(it)
}
}

@ReactMethod
fun paywallClosed(identifier: String) {
val paywall = Apphud.paywalls().firstOrNull { it.identifier == identifier }
paywall?.let {
Apphud.paywallClosed(it)
}
}

@ReactMethod
fun purchase(args: ReadableMap, promise: Promise) {
val productId = args.getString("productId")
Expand All @@ -96,7 +112,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ

val isSub = product?.productDetails?.productType?.lowercase() == "subs"
val offerToken = args.getString("offerToken")
val isConsumable = args.getBoolean("isConsumable")
val isConsumable = if (args.hasKey("isConsumable")) args.getBoolean("isConsumable") else false

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


@ReactMethod
fun enableDebugLogs() {
Apphud.enableDebugLogs()
Expand Down
1 change: 1 addition & 0 deletions example/ios/.xcode.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node
2 changes: 1 addition & 1 deletion example/ios/ApphudSdkExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
shellScript = "export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
};
2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 47a16e2930bdcf8baadcf3fe4873c7f378dc927c

COCOAPODS: 1.14.2
COCOAPODS: 1.15.2
10 changes: 3 additions & 7 deletions example/src/screens/ActionsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ export default function ActionsScreen({ navigation }: Props) {
const [paywalls, setPaywalls] = React.useState<Array<ApphudPaywall>>();

const callAll = () => {
// ApphudSdk.enableDebugLogs();
ApphudSdk.enableDebugLogs();

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

// ApphudSdk.userId().then((userId) => console.log(`Apphud: userId: ${userId}`));
// ApphudSdk.hasActiveSubscription().then((hasActiveSubscription) =>
// console.log(`Apphud: hasActiveSubscription: ${hasActiveSubscription}`)
// );
// ApphudSdk.hasPremiumAccess().then((hasPremiumAccess) =>
// console.log(`Apphud: hasPremiumAccess: ${hasPremiumAccess}`)
// );
ApphudSdk.hasActiveSubscription().then((active) => console.log('START Has Active Subscription: = ' + active));


// ApphudSdk.setUserProperty({key: 'some_string_key2', value: 'some_string_valueee', setOnce: true})
// ApphudSdk.setUserProperty({key: 'some_float_key3', value: 1.45, setOnce: true})
Expand Down
3 changes: 3 additions & 0 deletions example/src/screens/LoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default function LoginScreen({ navigation }: Props) {

const onStartHandler = () => {
ApphudSdk.start({ apiKey, userId, deviceId, observerMode: false })

// ApphudSdk.hasActiveSubscription().then((active) => console.log('START Has Active Subscription: = ' + hasActive));

navigation.navigate('Actions')
}

Expand Down
1 change: 1 addition & 0 deletions example/src/screens/PaywallScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function PaywallScreen({ route, navigation}: { route: any, naviga
for (const paywall of paywalls) {
if (paywall.identifier === route.params.paywallId) {
setCurrentPaywall(paywall);
await ApphudSdk.paywallShown(paywall.identifier);
const productsPropsList: ProductProps[] = preparedProducts(paywall.products);
setProductsProps(productsPropsList);
return paywall;
Expand Down
1 change: 1 addition & 0 deletions ios/.xcode.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node
2 changes: 2 additions & 0 deletions ios/ApphudSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ @interface RCT_EXTERN_MODULE(ApphudSdk, NSObject)

RCT_EXTERN_METHOD(collectDeviceIdentifiers)
RCT_EXTERN_METHOD(setAdvertisingIdentifier:(NSString*)idfa)
RCT_EXTERN_METHOD(paywallShown:(NSString*)identifier)
RCT_EXTERN_METHOD(paywallClosed:(NSString*)identifier)
RCT_EXTERN_METHOD(optOutOfTracking)
RCT_EXTERN_METHOD(enableDebugLogs)
RCT_EXTERN_METHOD(logout:(RCTPromiseResolveBlock)resolve)
Expand Down
24 changes: 23 additions & 1 deletion ios/ApphudSdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApphudSdk: NSObject {

override init() {
ApphudHttpClient.shared.sdkType = "reactnative";
ApphudHttpClient.shared.sdkVersion = "2.0.0";
ApphudHttpClient.shared.sdkVersion = "2.1.0";
}

@objc(start:)
Expand All @@ -15,6 +15,9 @@ class ApphudSdk: NSObject {
let userID = options["userId"] as? String;
let observerMode = options["observerMode"] as? Bool ?? true;
DispatchQueue.main.async {
#if DEBUG
ApphudUtils.enableAllLogs()
#endif
Apphud.start(apiKey: apiKey, userID: userID, observerMode: observerMode);
}
}
Expand Down Expand Up @@ -130,6 +133,25 @@ class ApphudSdk: NSObject {
}
}

@objc(paywallShown:)
func paywallShown(identifier: String) {
print("Paywall Shown: \(identifier)")
Task {
if let paywall = await Apphud.paywalls().first(where: { $0.identifier == identifier }) {
Apphud.paywallShown(paywall)
}
}
}

@objc(paywallClosed:)
func paywallClosed(identifier: String) {
Task {
if let paywall = await Apphud.paywalls().first(where: { $0.identifier == identifier }) {
Apphud.paywallClosed(paywall)
}
}
}

@objc(subscription:withRejecter:)
func subscription(resolve: RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
guard let subscription = Apphud.subscription() else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apphud/react-native-apphud-sdk",
"version": "2.0.0",
"version": "2.1.0",
"description": "Apphud SDK for react native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
14 changes: 13 additions & 1 deletion src/ApphudSdkType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ export type ApphudSdkType = {
* Method returns immediately if paywalls are cached or already loaded.
* @returns paywalls configured in Apphud Dashboard > Product Hub > Paywalls.
*/
paywalls(): Promise<Array<ApphudPaywall>>;
paywalls(): Promise<Array<ApphudPaywall>>;

/**
* Available on iOS and Android
* Logs a "Paywall Shown" (Paywall View) event which is required for A/B Testing Analytics.
*/
paywallShown(identifier: string): void;

/**
* Available on iOS and Android
* Logs a "Paywall Closed" event. Optional.
*/
paywallClosed(identifier: string): void;

/**
* Available on iOS and Android.
Expand Down

0 comments on commit 7d2bc52

Please sign in to comment.