diff --git a/.gitignore b/.gitignore index 165daa9..2885637 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ .history .svn/ migrate_working_dir/ +.vscode # IntelliJ related *.iml diff --git a/README.md b/README.md index 57cf0d9..39c1404 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,15 @@ -# Posthog plugin +# PostHog plugin -![Pub Version](https://img.shields.io/pub/v/posthog_flutter) +[![Package on pub.dev][pubdev_badge]][pubdev_link] Flutter plugin to support iOS, Android and Web sources at https://posthog.com. -- Using PostAndroid 3.0.0-beta.3 -- Using PostIOS 3.0.0-alpha.5 ## Usage -To use this plugin, add `posthog_flutter` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/). +To use this plugin, add `posthog_flutter` as a [dependency in your pubspec.yaml file](https://pub.dev/packages/posthog_flutter/install). ### Supported methods @@ -45,10 +43,11 @@ void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - Posthog().screen( - screenName: 'Example Screen', - ); return MaterialApp( + navigatorObservers: [ + // The PosthogObserver records screen views + PosthogObserver(), + ], home: Scaffold( appBar: AppBar( title: Text('Posthog example app'), @@ -68,10 +67,7 @@ class MyApp extends StatelessWidget { }, ), ), - ), - navigatorObservers: [ - PosthogObserver(), - ], + ) ); } } diff --git a/android/build.gradle b/android/build.gradle index 92c4a48..6e7d17c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,14 +2,14 @@ group 'com.example.posthog_flutter' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.7.10' + ext.kotlin_version = '1.8.10' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' + classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -52,7 +52,7 @@ android { dependencies { testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation 'org.mockito:mockito-core:5.0.0' - implementation 'com.posthog:posthog-android:3.+' + implementation 'com.posthog:posthog-android:3.0.0-beta.6' } testOptions { diff --git a/android/src/main/kotlin/com/example/posthog_flutter/PosthogFlutterPlugin.kt b/android/src/main/kotlin/com/example/posthog_flutter/PosthogFlutterPlugin.kt index ee2dd7d..188c652 100644 --- a/android/src/main/kotlin/com/example/posthog_flutter/PosthogFlutterPlugin.kt +++ b/android/src/main/kotlin/com/example/posthog_flutter/PosthogFlutterPlugin.kt @@ -180,7 +180,7 @@ class PosthogFlutterPlugin : FlutterPlugin, MethodCallHandler { private fun identify(call: MethodCall, result: Result) { try { - val userId: String? = call.argument("userId") + val userId = call.argument("userId") as? String val propertiesData: HashMap? = call.argument("properties") val optionsData: HashMap? = call.argument("options") PostHog.identify(userId!!, propertiesData, optionsData) diff --git a/ios/Classes/PosthogFlutterPlugin.swift b/ios/Classes/PosthogFlutterPlugin.swift index d426484..75e6904 100644 --- a/ios/Classes/PosthogFlutterPlugin.swift +++ b/ios/Classes/PosthogFlutterPlugin.swift @@ -11,9 +11,9 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { } public static func initPlugin(){ - // Initialise Poshog + // Initialise PostHog let postHogApiKey = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.API_KEY") as? String ?? "" - let postHogHost = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.POSTHOG_HOST") as? String ?? "" + let postHogHost = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.POSTHOG_HOST") as? String ?? "https://app.posthog.com" let postHogCaptureLifecyleEvents = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.TRACK_APPLICATION_LIFECYCLE_EVENTS") as? Bool ?? false let config = PostHogConfig( @@ -76,7 +76,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let featureFlagKey = args["key"] as? String { let value = PostHogSDK.shared.getFeatureFlag(featureFlagKey) result(value) @@ -89,7 +89,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let featureFlagKey = args["key"] as? String { let value : Bool = PostHogSDK.shared.isFeatureEnabled(featureFlagKey) result(value) @@ -102,7 +102,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let featureFlagKey = args["key"] as? String { let value : Any? = PostHogSDK.shared.getFeatureFlagPayload(featureFlagKey) result(value) @@ -115,7 +115,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let featureFlagKey = args["key"] as? String { let status : Any? = PostHogSDK.shared.getFeatureFlag(featureFlagKey) let payload : Any? = PostHogSDK.shared.getFeatureFlagPayload(featureFlagKey) @@ -142,7 +142,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let userId = args["userId"] as? String, let propertiesData = args["properties"] as? Dictionary { PostHogSDK.shared.identify( @@ -159,7 +159,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let eventName = args["eventName"] as? String, let propertiesData = args["properties"] as? Dictionary { PostHogSDK.shared.capture( @@ -177,7 +177,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let screenName = args["screenName"] as? String, let propertiesData = args["properties"] as? Dictionary { PostHogSDK.shared.screen( @@ -195,7 +195,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let alias = args["alias"] as? String { PostHogSDK.shared.alias(alias) result(true) @@ -250,7 +250,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let groupType = args["groupType"] as? String, let groupKey = args["groupKey"] as? String, let groupProperties = args["groupProperties"] as? Dictionary{ @@ -265,7 +265,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { _ call: FlutterMethodCall, result: @escaping FlutterResult ){ - if let args = call.arguments as? Dictionary, + if let args = call.arguments as? [String: Any], let key = args["key"] as? String, let value = args["value"] { PostHogSDK.shared.register([key: value]) diff --git a/ios/posthog_flutter.podspec b/ios/posthog_flutter.podspec index c761bed..60665b5 100644 --- a/ios/posthog_flutter.podspec +++ b/ios/posthog_flutter.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |s| s.name = 'posthog_flutter' s.version = '0.0.1' - s.summary = 'Postog flutter plugin' + s.summary = 'A new flutter plugin project.' s.description = <<-DESC Postog flutter plugin DESC diff --git a/pubspec.yaml b/pubspec.yaml index a3edfd5..c0a4f56 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,8 +7,8 @@ issue_tracker: https://github.com/posthog/posthog-flutter/issues documentation: https://github.com/posthog/posthog-flutter#readme environment: - sdk: ">=3.1.5 <4.0.0" - flutter: ">=3.3.0" + sdk: ">=2.17.0 <4.0.0" + flutter: ">=3.0.0" dependencies: flutter: