Skip to content

Commit

Permalink
Migrate to the new SDKs (PostHog#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Jan 5, 2024
1 parent 15e2dc0 commit 0bd822f
Show file tree
Hide file tree
Showing 82 changed files with 2,132 additions and 1,336 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@ jobs:
- uses: subosito/flutter-action@v2
with:
channel: 'stable'

- name: SDK format check
run: dart format --set-exit-if-changed ./

- name: Install dependencies
working-directory: ./example
run: flutter pub get

- name: Build iOS
working-directory: ./example
run: flutter build ios --simulator --no-codesign

- name: Build Android
working-directory: ./example
run: flutter build apk

- name: Build Web
working-directory: ./example
run: flutter build web
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/
.vscode

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
### Customs ###
ios/Flutter/flutter_export_environment.sh
.idea/**
Expand Down Expand Up @@ -599,3 +630,6 @@ lib/example/generated_plugin_registrant.dart
.fvm/

posthog_flutter.iml

# pod files
Podfile.lock
30 changes: 28 additions & 2 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@
# This file should be version controlled and should not be manually edited.

version:
revision: 20e59316b8b8474554b38493b8ca888794b0234a
channel: stable
revision: "d211f42860350d914a5ad8102f9ec32764dc6d06"
channel: "stable"

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
- platform: android
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
- platform: ios
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
- platform: web
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- "lib/main.dart"
- "ios/Runner.xcodeproj/project.pbxproj"
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
## Next

- Migrate to the new SDKs and latest tooling [#70](https://github.com/PostHog/posthog-flutter/pull/70)
- Added missing features such as feature flags payloads, debug, and more

### Breaking changes

- Android minSdkVersion 21
- iOS min version 13.0
- Flutter min version 3.3.0
- Upgraded PostHog Android SDK to [v3](https://github.com/PostHog/posthog-android/blob/main/USAGE.md)
- Upgraded PostHog iOS SDK to [v3 preview](https://github.com/PostHog/posthog-ios/blob/main/USAGE.md)
- Upgraded PostHog JS SDK to the latest version
- PostHog Flutter Plugins are written in Kotlin and Swift

### Acknowledgements

Thanks @nehemiekoffi for the initial PR!

## 3.3.0

- Migrate to Java 8 and minSdkVersion 19 [#54](https://github.com/PostHog/posthog-flutter/pull/54)
Expand Down Expand Up @@ -74,4 +91,4 @@

## 1.9.0

- Posthog client library for Flutter is released!
- PostHog client library for Flutter is released!
72 changes: 32 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ To use this plugin, add `posthog_flutter` as a [dependency in your pubspec.yaml

### Supported methods

| Method | Android | iOS | Web |
| ------------------ | ------- | --- | --- |
| `identify` | X | X | X |
| `capture` | X | X | X |
| `screen` | X | X | X |
| `alias` | X | X | X |
| `getAnonymousId` | X | X | X |
| `reset` | X | X | X |
| `disable` | X | X | |
| `enable` | X | X | |
| `debug` | X\* | X | X |
| `setContext` | X | X | |
| `isFeatureEnabled` | X | X | X |
| `reloadFeatureFlags`| X | X | X |

\* Debugging must be set as a configuration parameter in `AndroidManifest.xml` (see below). The official posthog library does not offer the debug method for Android.
| Method | Android | iOS | Web |
| ------------------------- | ------- | --- | --- |
| `identify` | X | X | X |
| `capture` | X | X | X |
| `screen` | X | X | X |
| `alias` | X | X | X |
| `getDistinctId` | X | X | X |
| `reset` | X | X | X |
| `disable` | X | X | X |
| `enable` | X | X | X |
| `debug` | X | X | X |
| `register` | X | X | X |
| `register` | X | X | X |
| `reloadFeatureFlags` | X | X | X |
| `getFeatureFlag` | X | X | X |
| `group` | X | X | X |
| `getFeatureFlagPayload` | X | X | X |

### Example

Expand Down Expand Up @@ -62,7 +63,7 @@ class MyApp extends StatelessWidget {
},
),
),
),
)
);
}
}
Expand All @@ -80,7 +81,7 @@ Remember that the application lifecycle events won't have any special context se
#### AndroidManifest.xml

```xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.posthog.posthog_flutter_example">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.posthog_flutter_example">
<application>
<activity>
[...]
Expand Down Expand Up @@ -114,7 +115,7 @@ Remember that the application lifecycle events won't have any special context se
</plist>
```

For `debug` mode on iOS, you can use the following snippet:
For `debug` mode on Android, iOS and Web, you can use the following snippet:

```dart
PostHog().debug(true);
Expand All @@ -125,21 +126,21 @@ PostHog().debug(true);
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>example</title>
</head>
<body>
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init("YOUR_WRITE_KEY_GOES_HERE", {api_host: 'https://app.posthog.com'});
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
<head>
...
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init('YOUR_WRITE_KEY_GOES_HERE', {api_host: 'https://app.posthog.com'})
</script>
</head>

<body>
...
</body>
</html>
```

For more informations please check: https://posthog.com/docs/integrations/js-integration
For more informations please check the [docs](https://posthog.com/docs/libraries/js).

## Issues

Expand All @@ -149,15 +150,6 @@ Please file any issues, bugs, or feature requests in the [GitHub repo](https://g

If you wish to contribute a change to this repo, please send a [pull request](https://github.com/posthog/posthog-flutter/pulls).

## Deploying to pub.dev

- [Developing and publishing packages & plugins](https://flutter.dev/docs/development/packages-and-plugins/developing-packages#publish)
- [Publishing packages](https://dart.dev/tools/pub/publishing)

## Questions?

### [Join our Slack community.](https://join.slack.com/t/posthogusers/shared_invite/enQtOTY0MzU5NjAwMDY3LTc2MWQ0OTZlNjhkODk3ZDI3NDVjMDE1YjgxY2I4ZjI4MzJhZmVmNjJkN2NmMGJmMzc2N2U3Yjc3ZjI5NGFlZDQ)


[pubdev_badge]: https://img.shields.io/pub/v/posthog_flutter
[pubdev_link]: https://pub.dev/packages/posthog_flutter
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
.DS_Store
/build
/captures
.cxx

/.settings
53 changes: 37 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,50 +1,71 @@
group 'com.posthog.posthog_flutter'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdk 33

// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace 'com.posthog.posthog_flutter'
}

defaultConfig {
minSdkVersion 19
compileSdkVersion 33

ndk {
// Flutter does not currently support building for x86 Android (See Issue 9253).
abiFilters("armeabi-v7a", "x86_64", "arm64-v8a")
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
disable 'InvalidPackage'
kotlinOptions {
jvmTarget = '1.8'
languageVersion = "1.6"
apiVersion = "1.6"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}

defaultConfig {
minSdkVersion 21
}

dependencies {
api 'com.posthog.android:posthog:2.0.3'
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.mockito:mockito-core:5.0.0'
implementation 'com.posthog:posthog-android:3.0.1'
}

testOptions {
unitTests.all {
useJUnitPlatform()

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen { false }
showStandardStreams = true
}
}
}
}
3 changes: 1 addition & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
org.gradle.jvmargs=-Xmx1536M

org.gradle.jvmargs=-Xmx4G
1 change: 0 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.posthog.posthog_flutter">
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Loading

0 comments on commit 0bd822f

Please sign in to comment.