Skip to content

Commit

Permalink
Fix requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nehemiekoffi committed Nov 17, 2023
1 parent b4f0067 commit 666f607
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.history
.svn/
migrate_working_dir/
.vscode

# IntelliJ related
*.iml
Expand Down
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

<img src="https://github.com/djamoapp/posthog-flutter/assets/6081388/f35cce89-bb1a-49f4-8f80-6aa47709dff9" width=300 />


## 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

Expand Down Expand Up @@ -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'),
Expand All @@ -68,10 +67,7 @@ class MyApp extends StatelessWidget {
},
),
),
),
navigatorObservers: [
PosthogObserver(),
],
)
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any>? = call.argument("properties")
val optionsData: HashMap<String, Any>? = call.argument("options")
PostHog.identify(userId!!, propertiesData, optionsData)
Expand Down
24 changes: 12 additions & 12 deletions ios/Classes/PosthogFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -76,7 +76,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
result: @escaping FlutterResult
){

if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let featureFlagKey = args["key"] as? String {
let value = PostHogSDK.shared.getFeatureFlag(featureFlagKey)
result(value)
Expand All @@ -89,7 +89,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let featureFlagKey = args["key"] as? String {
let value : Bool = PostHogSDK.shared.isFeatureEnabled(featureFlagKey)
result(value)
Expand All @@ -102,7 +102,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let featureFlagKey = args["key"] as? String {
let value : Any? = PostHogSDK.shared.getFeatureFlagPayload(featureFlagKey)
result(value)
Expand All @@ -115,7 +115,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
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)
Expand All @@ -142,7 +142,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let userId = args["userId"] as? String,
let propertiesData = args["properties"] as? Dictionary<String,Any> {
PostHogSDK.shared.identify(
Expand All @@ -159,7 +159,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let eventName = args["eventName"] as? String,
let propertiesData = args["properties"] as? Dictionary<String,Any> {
PostHogSDK.shared.capture(
Expand All @@ -177,7 +177,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let screenName = args["screenName"] as? String,
let propertiesData = args["properties"] as? Dictionary<String,Any> {
PostHogSDK.shared.screen(
Expand All @@ -195,7 +195,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let alias = args["alias"] as? String {
PostHogSDK.shared.alias(alias)
result(true)
Expand Down Expand Up @@ -250,7 +250,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
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<String,Any>{
Expand All @@ -265,7 +265,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin {
_ call: FlutterMethodCall,
result: @escaping FlutterResult
){
if let args = call.arguments as? Dictionary<String, Any>,
if let args = call.arguments as? [String: Any],
let key = args["key"] as? String,
let value = args["value"] {
PostHogSDK.shared.register([key: value])
Expand Down
2 changes: 1 addition & 1 deletion ios/posthog_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 666f607

Please sign in to comment.