From 3024f4e136de200a96ae52a95479c08dfad5f6be Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:34:39 +0200 Subject: [PATCH] chore: ios plugin (#2) --- .github/actions/setup/action.yml | 4 +- .github/workflows/ci.yml | 47 +++++---------- .gitignore | 2 + .../project.pbxproj | 57 +++++++++++++++--- ...ogReactNativeSessionReplayExample.xcscheme | 2 +- .../contents.xcworkspacedata | 10 ++++ .../PrivacyInfo.xcprivacy | 8 +-- ios/PosthogReactNativeSessionReplay.mm | 17 ++++++ ios/PosthogReactNativeSessionReplay.swift | 59 +++++++++++++++++++ package.json | 2 +- posthog-react-native-session-replay.podspec | 3 + 11 files changed, 162 insertions(+), 49 deletions(-) create mode 100644 example/ios/PosthogReactNativeSessionReplayExample.xcworkspace/contents.xcworkspacedata diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index fb98c79..60df308 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -5,13 +5,13 @@ runs: using: composite steps: - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version-file: .nvmrc - name: Cache dependencies id: yarn-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | **/node_modules diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c7ff3c..ab4f1b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup uses: ./.github/actions/setup @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup uses: ./.github/actions/setup @@ -42,7 +42,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup uses: ./.github/actions/setup @@ -56,13 +56,13 @@ jobs: TURBO_CACHE_DIR: .turbo/android steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup uses: ./.github/actions/setup - name: Cache turborepo for Android - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.TURBO_CACHE_DIR }} key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }} @@ -79,7 +79,7 @@ jobs: - name: Install JDK if: env.turbo_cache_hit != 1 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: '17' @@ -91,7 +91,7 @@ jobs: - name: Cache Gradle if: env.turbo_cache_hit != 1 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/wrapper @@ -108,35 +108,16 @@ jobs: build-ios: runs-on: macos-14 - env: - TURBO_CACHE_DIR: .turbo/ios steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup uses: ./.github/actions/setup - - name: Cache turborepo for iOS - uses: actions/cache@v3 - with: - path: ${{ env.TURBO_CACHE_DIR }} - key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }} - restore-keys: | - ${{ runner.os }}-turborepo-ios- - - - name: Check turborepo cache for iOS - run: | - TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status") - - if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then - echo "turbo_cache_hit=1" >> $GITHUB_ENV - fi - - name: Cache cocoapods - if: env.turbo_cache_hit != 1 id: cocoapods-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | **/ios/Pods @@ -145,13 +126,15 @@ jobs: ${{ runner.os }}-cocoapods- - name: Install cocoapods - if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true' + if: steps.cocoapods-cache.outputs.cache-hit != 'true' run: | cd example/ios pod install env: NO_FLIPPER: 1 - - name: Build example for iOS - run: | - yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" + # - name: Build example for iOS + # run: | + # cd example/ios + # gem install xcpretty + # set -o pipefail && xcrun xcodebuild -workspace PosthogReactNativeSessionReplayExample.xcworkspace -configuration Debug -scheme posthog-react-native-session-replay -destination generic/platform=ios | xcpretty diff --git a/.gitignore b/.gitignore index cfe2bb4..390910d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ DerivedData *.ipa *.xcuserstate project.xcworkspace +.xcode.env.local # Android/IJ # @@ -43,6 +44,7 @@ android.iml # Cocoapods # example/ios/Pods +Podfile.lock # Ruby example/vendor/ diff --git a/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/project.pbxproj b/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/project.pbxproj index 7d0caad..172291e 100644 --- a/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/project.pbxproj +++ b/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; + 6AE94712C2517FF64114CB47 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 97ACBB0B8F3EDAFE9A9DFB21 /* PrivacyInfo.xcprivacy */; }; 7699B88040F8A987B510C191 /* libPods-PosthogReactNativeSessionReplayExample-PosthogReactNativeSessionReplayExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-PosthogReactNativeSessionReplayExample-PosthogReactNativeSessionReplayExampleTests.a */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ @@ -44,6 +45,7 @@ 5DCACB8F33CDC322A6C60F78 /* libPods-PosthogReactNativeSessionReplayExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PosthogReactNativeSessionReplayExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = PosthogReactNativeSessionReplayExample/LaunchScreen.storyboard; sourceTree = ""; }; 89C6BE57DB24E9ADA2F236DE /* Pods-PosthogReactNativeSessionReplayExample-PosthogReactNativeSessionReplayExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PosthogReactNativeSessionReplayExample-PosthogReactNativeSessionReplayExampleTests.release.xcconfig"; path = "Target Support Files/Pods-PosthogReactNativeSessionReplayExample-PosthogReactNativeSessionReplayExampleTests/Pods-PosthogReactNativeSessionReplayExample-PosthogReactNativeSessionReplayExampleTests.release.xcconfig"; sourceTree = ""; }; + 97ACBB0B8F3EDAFE9A9DFB21 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = PosthogReactNativeSessionReplayExample/PrivacyInfo.xcprivacy; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -94,6 +96,7 @@ 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 13B07FB71A68108700A75B9A /* main.m */, 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */, + 97ACBB0B8F3EDAFE9A9DFB21 /* PrivacyInfo.xcprivacy */, ); name = PosthogReactNativeSessionReplayExample; sourceTree = ""; @@ -161,8 +164,8 @@ 00E356EA1AD99517003FC87E /* Sources */, 00E356EB1AD99517003FC87E /* Frameworks */, 00E356EC1AD99517003FC87E /* Resources */, - C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */, F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */, + E0C97A31E11FCB40DE643CC5 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -183,8 +186,8 @@ 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, - 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */, E235C05ADACE081382539298 /* [CP] Copy Pods Resources */, + 511E6835ECE733F99C3FA970 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -201,7 +204,7 @@ 83CBB9F71A601CBA00E9B192 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1210; + LastUpgradeCheck = 1600; TargetAttributes = { 00E356ED1AD99517003FC87E = { CreatedOnToolsVersion = 6.2; @@ -245,6 +248,7 @@ files = ( 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, + 6AE94712C2517FF64114CB47 /* PrivacyInfo.xcprivacy in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -267,7 +271,7 @@ shellPath = /bin/sh; shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n"; }; - 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = { + 511E6835ECE733F99C3FA970 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -328,7 +332,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */ = { + E0C97A31E11FCB40DE643CC5 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -431,8 +435,13 @@ "-lc++", "$(inherited)", ); - PRODUCT_BUNDLE_IDENTIFIER = "posthogreactnativesessionreplay.example"; + PRODUCT_BUNDLE_IDENTIFIER = posthogreactnativesessionreplay.example; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = 1; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PosthogReactNativeSessionReplayExample.app/PosthogReactNativeSessionReplayExample"; }; name = Debug; @@ -455,8 +464,13 @@ "-lc++", "$(inherited)", ); - PRODUCT_BUNDLE_IDENTIFIER = "posthogreactnativesessionreplay.example"; + PRODUCT_BUNDLE_IDENTIFIER = posthogreactnativesessionreplay.example; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = 1; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PosthogReactNativeSessionReplayExample.app/PosthogReactNativeSessionReplayExample"; }; name = Release; @@ -480,10 +494,15 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "posthogreactnativesessionreplay.example"; + PRODUCT_BUNDLE_IDENTIFIER = posthogreactnativesessionreplay.example; PRODUCT_NAME = PosthogReactNativeSessionReplayExample; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = 1; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -506,9 +525,14 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "posthogreactnativesessionreplay.example"; + PRODUCT_BUNDLE_IDENTIFIER = posthogreactnativesessionreplay.example; PRODUCT_NAME = PosthogReactNativeSessionReplayExample; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = 1; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; @@ -517,6 +541,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CC = ""; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++20"; CLANG_CXX_LIBRARY = "libc++"; @@ -544,6 +569,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + CXX = ""; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; @@ -563,6 +589,8 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 13.4; + LD = ""; + LDPLUSPLUS = ""; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, "$(inherited)", @@ -582,7 +610,11 @@ "-DFOLLY_CFG_NO_COROUTINES=1", "-DFOLLY_HAVE_CLOCK_GETTIME=1", ); + OTHER_LDFLAGS = "$(inherited) "; + REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG"; + USE_HERMES = true; }; name = Debug; }; @@ -590,6 +622,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CC = ""; CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++20"; CLANG_CXX_LIBRARY = "libc++"; @@ -617,6 +650,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; + CXX = ""; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; @@ -629,6 +663,8 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 13.4; + LD = ""; + LDPLUSPLUS = ""; LD_RUNPATH_SEARCH_PATHS = ( /usr/lib/swift, "$(inherited)", @@ -647,7 +683,10 @@ "-DFOLLY_CFG_NO_COROUTINES=1", "-DFOLLY_HAVE_CLOCK_GETTIME=1", ); + OTHER_LDFLAGS = "$(inherited) "; + REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; SDKROOT = iphoneos; + USE_HERMES = true; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/xcshareddata/xcschemes/PosthogReactNativeSessionReplayExample.xcscheme b/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/xcshareddata/xcschemes/PosthogReactNativeSessionReplayExample.xcscheme index 91b26b3..e799b6e 100644 --- a/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/xcshareddata/xcschemes/PosthogReactNativeSessionReplayExample.xcscheme +++ b/example/ios/PosthogReactNativeSessionReplayExample.xcodeproj/xcshareddata/xcschemes/PosthogReactNativeSessionReplayExample.xcscheme @@ -1,6 +1,6 @@ + + + + + + diff --git a/example/ios/PosthogReactNativeSessionReplayExample/PrivacyInfo.xcprivacy b/example/ios/PosthogReactNativeSessionReplayExample/PrivacyInfo.xcprivacy index 41b8317..bad3276 100644 --- a/example/ios/PosthogReactNativeSessionReplayExample/PrivacyInfo.xcprivacy +++ b/example/ios/PosthogReactNativeSessionReplayExample/PrivacyInfo.xcprivacy @@ -6,18 +6,18 @@ NSPrivacyAccessedAPIType - NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPICategoryUserDefaults NSPrivacyAccessedAPITypeReasons - C617.1 + CA92.1 NSPrivacyAccessedAPIType - NSPrivacyAccessedAPICategoryUserDefaults + NSPrivacyAccessedAPICategoryFileTimestamp NSPrivacyAccessedAPITypeReasons - CA92.1 + C617.1 diff --git a/ios/PosthogReactNativeSessionReplay.mm b/ios/PosthogReactNativeSessionReplay.mm index 40687bb..3b8f454 100644 --- a/ios/PosthogReactNativeSessionReplay.mm +++ b/ios/PosthogReactNativeSessionReplay.mm @@ -6,6 +6,23 @@ @interface RCT_EXTERN_MODULE(PosthogReactNativeSessionReplay, NSObject) withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) +RCT_EXTERN_METHOD(start:(NSString)sessionId + withSdkOptions:(NSDictionary)sdkOptions + withSdkReplayConfig:(NSDictionary)sdkReplayConfig + withDecideReplayConfig:(NSDictionary)decideReplayConfig + withResolver:(RCTPromiseResolveBlock)resolve + withRejecter:(RCTPromiseRejectBlock)reject) + +RCT_EXTERN_METHOD(startSession:(NSString)sessionId + withResolver:(RCTPromiseResolveBlock)resolve + withRejecter:(RCTPromiseRejectBlock)reject) + +RCT_EXTERN_METHOD(isEnabled:(RCTPromiseResolveBlock)resolve + withRejecter:(RCTPromiseRejectBlock)reject) + +RCT_EXTERN_METHOD(endSession:(RCTPromiseResolveBlock)resolve + withRejecter:(RCTPromiseRejectBlock)reject) + + (BOOL)requiresMainQueueSetup { return NO; diff --git a/ios/PosthogReactNativeSessionReplay.swift b/ios/PosthogReactNativeSessionReplay.swift index 4d5cca6..3c61e8f 100644 --- a/ios/PosthogReactNativeSessionReplay.swift +++ b/ios/PosthogReactNativeSessionReplay.swift @@ -1,3 +1,5 @@ +import PostHog + @objc(PosthogReactNativeSessionReplay) class PosthogReactNativeSessionReplay: NSObject { @@ -5,4 +7,61 @@ class PosthogReactNativeSessionReplay: NSObject { func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { resolve(a*b) } + + @objc(start:withSdkOptions:withSdkReplayConfig:withDecideReplayConfig:withResolver:withRejecter:) + func start(sessionId: String, sdkOptions: [String: Any], sdkReplayConfig: [String: Any], decideReplayConfig: [String: Any], resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) { + let apiKey = sdkOptions["apiKey"] as? String ?? "" + let host = sdkOptions["host"] as? String ?? PostHogConfig.defaultHost + let debug = sdkOptions["debug"] as? Bool ?? false + + PostHogSessionManager.shared.setSessionId(sessionId) + + let config = PostHogConfig(apiKey: apiKey, host: host) + config.sessionReplay = true + config.captureApplicationLifecycleEvents = false + config.captureScreenViews = false + config.debug = debug + config.sessionReplayConfig.screenshotMode = true + + let maskAllTextInputs = sdkReplayConfig["maskAllTextInputs"] as? Bool ?? false + config.sessionReplayConfig.maskAllTextInputs = maskAllTextInputs + + let maskAllImages = sdkReplayConfig["maskAllImages"] as? Bool ?? false + config.sessionReplayConfig.maskAllImages = maskAllImages + + let iOSdebouncerDelayMs = sdkReplayConfig["iOSdebouncerDelayMs"] as? Int ?? 1000 + let timeInterval: TimeInterval = Double(iOSdebouncerDelayMs) / 1000.0 + config.sessionReplayConfig.debouncerDelay = timeInterval + + let captureNetworkTelemetry = sdkReplayConfig["captureNetworkTelemetry"] as? Bool ?? false + config.sessionReplayConfig.captureNetworkTelemetry = captureNetworkTelemetry + + let endpoint = decideReplayConfig["endpoint"] as? String ?? "" + if !endpoint.isEmpty { + config.snapshotEndpoint = endpoint + } + + PostHogSDK.shared.setup(config) + + resolve(nil) + } + + @objc(startSession:withResolver:withRejecter:) + func startSession(sessionId: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { + PostHogSessionManager.shared.setSessionId(sessionId) + PostHogSDK.shared.startSession() + resolve(nil) + } + + @objc(isEnabled:withRejecter:) + func isEnabled(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { + let isEnabled = PostHogSDK.shared.isSessionReplayActive() + resolve(isEnabled) + } + + @objc(endSession:withRejecter:) + func endSession(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { + PostHogSDK.shared.endSession() + resolve(nil) + } } diff --git a/package.json b/package.json index a1693f3..e526eb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "posthog-react-native-session-replay", - "version": "0.0.11", + "version": "0.0.12", "description": "Session Replay", "source": "./src/index.tsx", "main": "./lib/commonjs/index.js", diff --git a/posthog-react-native-session-replay.podspec b/posthog-react-native-session-replay.podspec index 851727a..1a35394 100644 --- a/posthog-react-native-session-replay.podspec +++ b/posthog-react-native-session-replay.podspec @@ -16,6 +16,9 @@ Pod::Spec.new do |s| s.source_files = "ios/**/*.{h,m,mm,swift}" + # ~> Version 3.0 and the versions up to 4.0, not including 4.0 and higher + s.dependency 'PostHog', '~> 3.0' + # 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. if respond_to?(:install_modules_dependencies, true)