From 7fee2c97d666f234d257f5429e42ac04bfabadfc Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 9 Jan 2024 16:18:40 +0100 Subject: [PATCH 01/12] changelog --- CHANGELOG.md | 4 ++++ README.md | 2 +- example/lib/main.dart | 6 +++++- lib/src/posthog.dart | 15 ++++++++------- lib/src/posthog_observer.dart | 7 ++++++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0057433..aff8627 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Next +- Record the root view as `root ("/")` instead of not recording at all [#70](https://github.com/PostHog/posthog-flutter/pull/70) +- Do not mutate the given properties when calling capture [#70](https://github.com/PostHog/posthog-flutter/pull/70) + - Thanks @lukepighetti for the [PR](https://github.com/PostHog/posthog-flutter/pull/66)! + ## 4.0.0-alpha.2 - Internal changes only diff --git a/README.md b/README.md index 1fddae3..b3c1a00 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( navigatorObservers: [ - // The PosthogObserver records screen views + // The PosthogObserver records screen views automatically PosthogObserver(), ], home: Scaffold( diff --git a/example/lib/main.dart b/example/lib/main.dart index 13ea349..f92768a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -25,6 +25,10 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( + navigatorObservers: [ + // The PosthogObserver records screen views automatically + PosthogObserver() + ], home: Scaffold( appBar: AppBar( title: const Text('PostHog Flutter App'), @@ -52,7 +56,7 @@ class _MyAppState extends State { "foo": "bar", }); }, - child: const Text("Capture Screen"), + child: const Text("Capture Screen manually"), ), ElevatedButton( onPressed: () { diff --git a/lib/src/posthog.dart b/lib/src/posthog.dart index 2cd4cad..d2e3f3b 100644 --- a/lib/src/posthog.dart +++ b/lib/src/posthog.dart @@ -27,15 +27,17 @@ class Posthog { required String eventName, Map? properties, }) { + final propertiesCopy = properties == null ? null : {...properties}; + final currentScreen = _currentScreen; - if (properties != null && - !properties.containsKey('\$screen_name') && + if (propertiesCopy != null && + !propertiesCopy.containsKey('\$screen_name') && currentScreen != null) { - properties['\$screen_name'] = currentScreen; + propertiesCopy['\$screen_name'] = currentScreen; } return _posthog.capture( eventName: eventName, - properties: properties, + properties: propertiesCopy, ); } @@ -43,9 +45,8 @@ class Posthog { required String screenName, Map? properties, }) { - if (screenName != '/') { - _currentScreen = screenName; - } + _currentScreen = screenName; + return _posthog.screen( screenName: screenName, properties: properties, diff --git a/lib/src/posthog_observer.dart b/lib/src/posthog_observer.dart index b804a16..be81ab8 100644 --- a/lib/src/posthog_observer.dart +++ b/lib/src/posthog_observer.dart @@ -13,8 +13,13 @@ class PosthogObserver extends RouteObserver> { final ScreenNameExtractor _nameExtractor; void _sendScreenView(PageRoute route) { - final String? screenName = _nameExtractor(route.settings); + String? screenName = _nameExtractor(route.settings); if (screenName != null) { + // if the screen name is the root route, we send it as root ("/") instead of only "/" + if (screenName == '/') { + screenName = 'root ("/")'; + } + Posthog().screen(screenName: screenName); } } From 8dfa82452a4045cabc0d76c009f01375b7180ba3 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 9 Jan 2024 16:20:06 +0100 Subject: [PATCH 02/12] fix pr id --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aff8627..f37a8cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Next -- Record the root view as `root ("/")` instead of not recording at all [#70](https://github.com/PostHog/posthog-flutter/pull/70) -- Do not mutate the given properties when calling capture [#70](https://github.com/PostHog/posthog-flutter/pull/70) +- Record the root view as `root ("/")` instead of not recording at all [#74](https://github.com/PostHog/posthog-flutter/pull/74) +- Do not mutate the given properties when calling capture [#74](https://github.com/PostHog/posthog-flutter/pull/74) - Thanks @lukepighetti for the [PR](https://github.com/PostHog/posthog-flutter/pull/66)! ## 4.0.0-alpha.2 From 3c1d368dc897cc50c83bd9f025d42eac400f9391 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:41:22 +0100 Subject: [PATCH 03/12] fix name --- lib/src/posthog_observer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/posthog_observer.dart b/lib/src/posthog_observer.dart index be81ab8..e973924 100644 --- a/lib/src/posthog_observer.dart +++ b/lib/src/posthog_observer.dart @@ -17,7 +17,7 @@ class PosthogObserver extends RouteObserver> { if (screenName != null) { // if the screen name is the root route, we send it as root ("/") instead of only "/" if (screenName == '/') { - screenName = 'root ("/")'; + screenName = 'root (\'/\')'; } Posthog().screen(screenName: screenName); From b3ed87408ee1f5df0bf573d3272929bcc7024519 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:41:55 +0100 Subject: [PATCH 04/12] fix config name --- ios/Classes/PosthogFlutterPlugin.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/PosthogFlutterPlugin.swift b/ios/Classes/PosthogFlutterPlugin.swift index 4642a01..f428d13 100644 --- a/ios/Classes/PosthogFlutterPlugin.swift +++ b/ios/Classes/PosthogFlutterPlugin.swift @@ -20,7 +20,7 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { } let host = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.POSTHOG_HOST") as? String ?? PostHogConfig.defaultHost - let postHogCaptureLifecyleEvents = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.TRACK_APPLICATION_LIFECYCLE_EVENTS") as? Bool ?? false + let postHogCaptureLifecyleEvents = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS") as? Bool ?? false let config = PostHogConfig( apiKey: apiKey, From c1912991737823ccf3237985a71b18587131e2a2 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:42:34 +0100 Subject: [PATCH 05/12] add version name to the example --- example/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 603a731..0cfab4c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,6 +3,7 @@ description: Demonstrates how to use the posthog_flutter plugin. # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev +version: 1.0.0+1 environment: sdk: '>=2.18.0 <4.0.0' From d8ee202e7febb83fda9950e0cdbf7ba5497c50e0 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:43:01 +0100 Subject: [PATCH 06/12] upgrade android sdk to 3.1.0 --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 33be9d5..d0d0227 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -54,7 +54,7 @@ android { dependencies { testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation 'org.mockito:mockito-core:5.0.0' - implementation 'com.posthog:posthog-android:3.0.1' + implementation 'com.posthog:posthog-android:3.1.0' } testOptions { From 716566cdb1f145fb5e1fc34ddfde3d150a1e6c81 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:44:31 +0100 Subject: [PATCH 07/12] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f37a8cf..f38b1f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Record the root view as `root ("/")` instead of not recording at all [#74](https://github.com/PostHog/posthog-flutter/pull/74) - Do not mutate the given properties when calling capture [#74](https://github.com/PostHog/posthog-flutter/pull/74) - Thanks @lukepighetti for the [PR](https://github.com/PostHog/posthog-flutter/pull/66)! +- Fix `CAPTURE_APPLICATION_LIFECYCLE_EVENTS` typo for iOS [#74](https://github.com/PostHog/posthog-flutter/pull/74) ## 4.0.0-alpha.2 From 74f6805c9cb04e8a3f13e8aa612018c373a13da4 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:49:14 +0100 Subject: [PATCH 08/12] improved examples --- CHANGELOG.md | 2 +- README.md | 6 +++--- example/android/app/src/main/AndroidManifest.xml | 10 +--------- example/ios/Runner/Info.plist | 2 +- ios/Classes/PosthogFlutterPlugin.swift | 2 ++ 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f38b1f9..80aca4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Next -- Record the root view as `root ("/")` instead of not recording at all [#74](https://github.com/PostHog/posthog-flutter/pull/74) +- Record the root view as `root ('/')` instead of not recording at all [#74](https://github.com/PostHog/posthog-flutter/pull/74) - Do not mutate the given properties when calling capture [#74](https://github.com/PostHog/posthog-flutter/pull/74) - Thanks @lukepighetti for the [PR](https://github.com/PostHog/posthog-flutter/pull/66)! - Fix `CAPTURE_APPLICATION_LIFECYCLE_EVENTS` typo for iOS [#74](https://github.com/PostHog/posthog-flutter/pull/74) diff --git a/README.md b/README.md index b3c1a00..bad4623 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,8 @@ Remember that the application lifecycle events won't have any special context se - - + + ``` @@ -109,7 +109,7 @@ Remember that the application lifecycle events won't have any special context se com.posthog.posthog.POSTHOG_HOST https://app.posthog.com com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS - + [...] diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 681221c..b6a9954 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -42,17 +42,9 @@ android:value="https://app.posthog.com" /> + android:value="true" /> - diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index 6d13ee0..ec8acb8 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -46,7 +46,7 @@ com.posthog.posthog.API_KEY _6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS - + CADisableMinimumFrameDurationOnPhone UIApplicationSupportsIndirectInputEvents diff --git a/ios/Classes/PosthogFlutterPlugin.swift b/ios/Classes/PosthogFlutterPlugin.swift index f428d13..585720c 100644 --- a/ios/Classes/PosthogFlutterPlugin.swift +++ b/ios/Classes/PosthogFlutterPlugin.swift @@ -21,12 +21,14 @@ public class PosthogFlutterPlugin: NSObject, FlutterPlugin { let host = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.POSTHOG_HOST") as? String ?? PostHogConfig.defaultHost let postHogCaptureLifecyleEvents = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS") as? Bool ?? false + let postHogDebug = Bundle.main.object(forInfoDictionaryKey: "com.posthog.posthog.DEBUG") as? Bool ?? false let config = PostHogConfig( apiKey: apiKey, host: host ) config.captureApplicationLifecycleEvents = postHogCaptureLifecyleEvents + config.debug = postHogDebug config.captureScreenViews = false // Update SDK name and version From 0d7fec55f586b1c0faa27de6896c175eb056ab86 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:49:54 +0100 Subject: [PATCH 09/12] fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80aca4e..37f31e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Do not mutate the given properties when calling capture [#74](https://github.com/PostHog/posthog-flutter/pull/74) - Thanks @lukepighetti for the [PR](https://github.com/PostHog/posthog-flutter/pull/66)! - Fix `CAPTURE_APPLICATION_LIFECYCLE_EVENTS` typo for iOS [#74](https://github.com/PostHog/posthog-flutter/pull/74) +- Added iOS support for the `DEBUG` config [#74](https://github.com/PostHog/posthog-flutter/pull/74) ## 4.0.0-alpha.2 From 1d816d0774f520edeb9b45e51dd66a85bbaafc30 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 10 Jan 2024 14:51:43 +0100 Subject: [PATCH 10/12] more --- README.md | 2 ++ example/ios/Runner/Info.plist | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index bad4623..6f23925 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ Remember that the application lifecycle events won't have any special context se https://app.posthog.com com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS + com.posthog.posthog.DEBUG + [...] diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index ec8acb8..d4438bb 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -47,6 +47,8 @@ _6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI com.posthog.posthog.CAPTURE_APPLICATION_LIFECYCLE_EVENTS + com.posthog.posthog.DEBUG + CADisableMinimumFrameDurationOnPhone UIApplicationSupportsIndirectInputEvents From f779743be36123755e4aefaf7a66aff7a0953457 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 11 Jan 2024 11:30:28 +0100 Subject: [PATCH 11/12] upgrade ios sdk --- ios/posthog_flutter.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/posthog_flutter.podspec b/ios/posthog_flutter.podspec index 0229a8e..9640afe 100644 --- a/ios/posthog_flutter.podspec +++ b/ios/posthog_flutter.podspec @@ -15,7 +15,7 @@ Postog flutter plugin s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' - s.dependency 'PostHog', '~> 3.0.0-beta.2' + s.dependency 'PostHog', '~> 3.0.0-beta.3' s.platform = :ios, '13.0' # Flutter.framework does not contain a i386 slice. From 66761c74c2a6bdbfab1e2713b03f53a68c17bebb Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Thu, 11 Jan 2024 11:31:44 +0100 Subject: [PATCH 12/12] add new changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f31e0..bf7eef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Thanks @lukepighetti for the [PR](https://github.com/PostHog/posthog-flutter/pull/66)! - Fix `CAPTURE_APPLICATION_LIFECYCLE_EVENTS` typo for iOS [#74](https://github.com/PostHog/posthog-flutter/pull/74) - Added iOS support for the `DEBUG` config [#74](https://github.com/PostHog/posthog-flutter/pull/74) +- Upgrade iOS SDK that fixes missing `Application Opened` events [#74](https://github.com/PostHog/posthog-flutter/pull/74) ## 4.0.0-alpha.2