Skip to content

Commit

Permalink
Merge pull request #17 from superwall/develop
Browse files Browse the repository at this point in the history
1.3.3.
  • Loading branch information
ianrumac authored Oct 14, 2024
2 parents 8cb2c28 + dd29368 commit 8663875
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 40 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

The changelog for `Superwall`. Also see the [releases](https://github.com/superwall/react-native-superwall/releases) on GitHub.

## 1.3.3

### Enhancements

- Upgrades Android SDK to 1.3.0 [View Android SDK release notes](https://github.com/superwall-me/Superwall-Android/releases/tag/1.3.0)
- Upgrades iOS SDK to 3.10.1 [View iOS SDK release notes](https://github.com/superwall-me/Superwall-iOS/releases/tag/3.10.1)
- Adds `passIdentifiersToPlayStore` to `SuperwallOptions` which allows you to pass user identifiers to the Play Store purchases as account identifiers. This is useful for tracking user purchases in the Play Store console.
- Adds `confirmAllAssignments` method to `Superwall` which confirms assignments for all placements and returns an array of all confirmed experiment assignments. Note that the assignments may be different when a placement is registered due to changes in user, placement, or device parameters used in audience filters.

### Fixes

- Fixes issue with the `Experiment` inside `PaywallInfo` being `null` in the `handleSuperwallEvent` delegate for iOS.

## 1.3.2

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation "com.superwall.sdk:superwall-android:1.2.9"
implementation "com.superwall.sdk:superwall-android:1.3.0"
implementation 'com.android.billingclient:billing:6.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,18 @@ class SuperwallReactNativeModule(private val reactContext: ReactApplicationConte
promise.resolve(null)
}
}

@ReactMethod
fun confirmAllAssignments(promise: Promise) {
CoroutineScope(Dispatchers.IO).launch {
val result = Superwall.instance.confirmAllAssignments()
val array = Arguments.createArray()
result.forEach { assignment ->
array.pushMap(assignment.toJson())
}
launch(Dispatchers.Main) {
promise.resolve(array)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.superwallreactnative.models

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableMap

import com.superwall.sdk.models.triggers.Experiment
import com.superwall.sdk.models.assignment.ConfirmedAssignment

fun ConfirmedAssignment.toJson(): ReadableMap {
val assignmentMap = Arguments.createMap()
assignmentMap.putString("experimentId", this.experimentId)
assignmentMap.putMap("variant", this.variant.toJson())
return assignmentMap
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import com.superwall.sdk.paywall.presentation.internal.state.PaywallSkippedReaso
class Experiment {
companion object {
fun toJson(experiment: Experiment): ReadableMap {
val variantMap = Arguments.createMap()
variantMap.putString("id",experiment.variant.id)
variantMap.putString("type", experiment.variant.type.toString())
variantMap.putString("paywallId", experiment.variant.paywallId)
val variantMap = experiment.variant.toJson()

val experimentMap = Arguments.createMap()
experimentMap.putString("id", experiment.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ class SuperwallEvent {
is SuperwallEvent.ConfigFail -> {
map.putString("event", "configFail")
}
is SuperwallEvent.ConfirmAllAssignments -> {
map.putString("event", "confirmAllAssignments")
}
}
return map
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SuperwallOptions {
options.localeIdentifier = json.getString("localeIdentifier")
options.isExternalDataCollectionEnabled = json.getBoolean("isExternalDataCollectionEnabled")
options.isGameControllerEnabled = json.getBoolean("isGameControllerEnabled")
options.passIdentifiersToPlayStore = json.getBoolean("passIdentifiersToPlayStore")

val networkEnvironment = when (json.getString("networkEnvironment")) {
"release" -> SuperwallOptions.NetworkEnvironment.Release()
Expand Down
15 changes: 15 additions & 0 deletions android/src/main/java/com/superwallreactnative/models/Variant.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.superwallreactnative.models

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableMap
import com.superwall.sdk.models.triggers.Experiment


fun Experiment.Variant.toJson(): ReadableMap {
val variantMap = Arguments.createMap()
variantMap.putString("id", this.id)
variantMap.putString("type", this.type.toString())
variantMap.putString("paywallId", this.paywallId)

return variantMap
}
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,8 @@ PODS:
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- SuperwallKit (= 3.10.0)
- SuperwallKit (3.10.0)
- SuperwallKit (= 3.10.1)
- SuperwallKit (3.10.1)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -1389,8 +1389,8 @@ SPEC CHECKSUMS:
RevenueCat: 7be0d7bde9efb2fc1ebd1888522c55bb4f9feb18
RNPurchases: 06957eb2f35bd7bb336d32fccf3534d45a3fda8a
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
superwall-react-native: 056b4dde47a30405c1c688bee51aa374a21ca552
SuperwallKit: e2d162d30c5e0a464f111b32950d54dc827a9d1b
superwall-react-native: 9092fa4e0d385c480e835a032132b46a3c13b2bc
SuperwallKit: 89cfaba57c139f97a578efc6bbb1f3963d2aa6b2
Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312

PODFILE CHECKSUM: 76fced934770e056b70a3087a2bc377b3556bae1
Expand Down
11 changes: 11 additions & 0 deletions ios/Json/ConfirmedAssignments+Json.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation
import SuperwallKit

extension ConfirmedAssignment {
func toJson() -> [String: Any] {
return [
"experimentId": experimentId,
"variant": variant.toJson(),
]
}
}
8 changes: 1 addition & 7 deletions ios/Json/Experiment+Json.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ import SuperwallKit

extension Experiment {
func toJson() -> [String: Any] {
var variant: [String: Any] = [
"id": variant.id,
"type": variant.type.rawValue,
"paywallId": variant.paywallId
]

return [
"id": id,
"groupId": groupId,
"variant": variant
"variant": variant.toJson()
]
}
}
2 changes: 1 addition & 1 deletion ios/Json/PaywallInfo+Json.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension PaywallInfo {
map["name"] = self.name
map["url"] = self.url.absoluteString
if let experiment = self.experiment {
map["experiment"] = Experiment.toJson(experiment)
map["experiment"] = experiment.toJson()
}
map["triggerSessionId"] = triggerSessionId

Expand Down
22 changes: 22 additions & 0 deletions ios/Json/Variant+Json.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SuperwallKit

extension Experiment.Variant {
func toJson() -> [String: Any] {
return [
"id": self.id,
"type": self.type.toJson(),
"paywallId": self.paywallId,
]
}
}

extension Experiment.Variant.VariantType {
func toJson() -> String {
switch self {
case .treatment:
return "TREATMENT"
case .holdout:
return "HOLDOUT"
}
}
}
5 changes: 5 additions & 0 deletions ios/SuperwallReactNative.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ @interface RCT_EXTERN_MODULE(SuperwallReactNative, NSObject)
withRejecter:(RCTPromiseRejectBlock)reject
)

RCT_EXTERN_METHOD(
confirmAllAssignments:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject
)

+ (BOOL)requiresMainQueueSetup
{
return NO;
Expand Down
56 changes: 35 additions & 21 deletions ios/SuperwallReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SuperwallReactNative: RCTEventEmitter {
"didDismissPaywall",
"didPresentPaywall",
"paywallWillOpenDeepLink",
"handleLog"
"handleLog",
]
}

Expand Down Expand Up @@ -87,38 +87,42 @@ class SuperwallReactNative: RCTEventEmitter {
handler = PaywallPresentationHandler()

handler?.onPresent { [weak self] paywallInfo in
let data = [
"paywallInfoJson": paywallInfo.toJson(),
"method": "onPresent",
"handlerId": handlerId
] as [String : Any]
let data =
[
"paywallInfoJson": paywallInfo.toJson(),
"method": "onPresent",
"handlerId": handlerId,
] as [String: Any]
self?.sendEvent(withName: "paywallPresentationHandler", body: data)
}

handler?.onDismiss { [weak self] paywallInfo in
let data = [
"paywallInfoJson": paywallInfo.toJson(),
"method": "onDismiss",
"handlerId": handlerId
] as [String : Any]
let data =
[
"paywallInfoJson": paywallInfo.toJson(),
"method": "onDismiss",
"handlerId": handlerId,
] as [String: Any]
self?.sendEvent(withName: "paywallPresentationHandler", body: data)
}

handler?.onError { [weak self] error in
let data = [
"method": "onError",
"errorString": error.localizedDescription,
"handlerId": handlerId
] as [String : Any]
let data =
[
"method": "onError",
"errorString": error.localizedDescription,
"handlerId": handlerId,
] as [String: Any]
self?.sendEvent(withName: "paywallPresentationHandler", body: data)
}

handler?.onSkip { [weak self] reason in
let data = [
"method": "onSkip",
"skippedReason": reason.toJson(),
"handlerId": handlerId
] as [String : Any]
let data =
[
"method": "onSkip",
"skippedReason": reason.toJson(),
"handlerId": handlerId,
] as [String: Any]
self?.sendEvent(withName: "paywallPresentationHandler", body: data)
}
}
Expand Down Expand Up @@ -214,4 +218,14 @@ class SuperwallReactNative: RCTEventEmitter {
resolve(nil)
}
}

@objc(confirmAllAssignments:withRejecter:)
func confirmAllAssignments(
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock
) {
Superwall.shared.confirmAllAssignments { assignments in
resolve(assignments.map { $0.toJson() })
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superwall/react-native-superwall",
"version": "1.3.2",
"version": "1.3.3",
"description": "The React Native package for Superwall",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
9 changes: 9 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NativeEventEmitter } from 'react-native';
import { IdentityOptions } from './public/IdentityOptions';
import { EventEmitter } from 'events';
import { ConfigurationStatus } from './public/ConfigurationStatus';
import { ConfirmedAssignment } from './public/ConfirmedAssigments';
const { version } = require('../package.json');

const LINKING_ERROR =
Expand Down Expand Up @@ -319,6 +320,14 @@ export default class Superwall {
);
}

async confirmAllAssignments(): Promise<ConfirmedAssignment[]> {
await this.awaitConfig();
const assignments = await SuperwallReactNative.confirmAllAssignments();
return assignments.map((assignment: any) =>
ConfirmedAssignment.fromJson(assignment)
);
}

async getConfigurationStatus(): Promise<ConfigurationStatus> {
const configurationStatusString =
await SuperwallReactNative.getConfigurationStatus();
Expand Down
18 changes: 18 additions & 0 deletions src/public/ConfirmedAssigments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Variant } from './Experiment';

export class ConfirmedAssignment {
experimentId: String;
variant: Variant;

constructor(experimentId: String, variant: Variant) {
this.experimentId = experimentId;
this.variant = variant;
}

static fromJson(json: any): ConfirmedAssignment {
return new ConfirmedAssignment(
json.experimentId,
Variant.fromJson(json.variant)
);
}
}
2 changes: 2 additions & 0 deletions src/public/SuperwallOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class SuperwallOptions {
isGameControllerEnabled: boolean = false;
logging: LoggingOptions = new LoggingOptions();
collectAdServicesAttribution: boolean = false;
passIdentifiersToPlayStore: boolean = false;

// Optionally, add a constructor for customization or methods for manipulation
constructor(init?: Partial<SuperwallOptions>) {
Expand All @@ -47,6 +48,7 @@ export class SuperwallOptions {
isGameControllerEnabled: this.isGameControllerEnabled,
logging: this.logging.toJson(),
collectAdServicesAttribution: this.collectAdServicesAttribution,
passIdentifiersToPlayStore: this.passIdentifiersToPlayStore,
};
}
}
2 changes: 1 addition & 1 deletion superwall-react-native.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/superwall-me/Superwall-React-Native.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,swift}"
s.dependency "SuperwallKit", '3.10.0'
s.dependency "SuperwallKit", '3.10.1'

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
Expand Down

0 comments on commit 8663875

Please sign in to comment.