Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: allow manual initialization of the SDK #117

Merged
merged 13 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

- chore: change host to new address ([#106](https://github.com/PostHog/posthog-flutter/pull/106))
- chore: allow manual initialization of the SDK ([#117](https://github.com/PostHog/posthog-flutter/pull/117))

## 4.5.0

Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: formatKotlin formatSwift formatDart

# brew install ktlint
# TODO: add ktlint steps in CI
formatKotlin:
ktlint --format

# brew install swiftlint
# TODO: add swiftlint steps in CI
formatSwift:
swiftformat ios/Classes --swiftversion 5.3
swiftlint ios/Classes --fix

formatDart:
dart format .
dart analyze .
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ To use this plugin, add `posthog_flutter` as a [dependency in your pubspec.yaml

| Method | Android | iOS/macOS | Web |
| ------------------------- | ------- | --------- | --- |
| `setup` | X | X | |
| `identify` | X | X | X |
| `capture` | X | X | X |
| `screen` | X | X | X |
Expand All @@ -29,6 +30,7 @@ To use this plugin, add `posthog_flutter` as a [dependency in your pubspec.yaml
| `getFeatureFlag` | X | X | X |
| `getFeatureFlagPayload` | X | X | X |
| `group` | X | X | X |
| `close` | X | X | |

### Example

Expand Down Expand Up @@ -80,9 +82,9 @@ Remember that the application lifecycle events won't have any special context se

### Android

#### AndroidManifest.xml
Automatically:

```xml
```xml file=AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.posthog_flutter_example">
<application>
<activity>
Expand All @@ -97,11 +99,40 @@ Remember that the application lifecycle events won't have any special context se
</manifest>
```

Or manually, disable the auto init:

```xml file=AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.posthog_flutter_example">
<application>
<activity>
[...]
</activity>
<meta-data android:name="com.posthog.posthog.AUTO_INIT" android:value="false" />
</application>
</manifest>
```

And setup the SDK manually:

```dart
Future<void> main() async {
// init WidgetsFlutterBinding if not yet
WidgetsFlutterBinding.ensureInitialized();
final config = PostHogConfig('YOUR_API_KEY_GOES_HERE');
config.debug = true;
config.captureApplicationLifecycleEvents = true;
// or EU Host: 'https://eu.i.posthog.com'
config.host = 'https://us.i.posthog.com';
await Posthog().setup(config);
runApp(MyApp());
}
```

### iOS/macOS

#### Info.plist
Automatically:

```xml
```xml file=Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
Expand All @@ -121,9 +152,40 @@ Remember that the application lifecycle events won't have any special context se
</plist>
```

Or manually, disable the auto init:

```xml file=Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
[...]
<key>com.posthog.posthog.AUTO_INIT</key>
<false/>
[...]
</dict>
</plist>
```

And setup the SDK manually:

```dart
Future<void> main() async {
// init WidgetsFlutterBinding if not yet
WidgetsFlutterBinding.ensureInitialized();
final config = PostHogConfig('YOUR_API_KEY_GOES_HERE');
config.debug = true;
config.captureApplicationLifecycleEvents = true;
// or EU Host: 'https://eu.i.posthog.com'
config.host = 'https://us.i.posthog.com';
await Posthog().setup(config);
runApp(MyApp());
}
```

### Web

```html
```html file=index.html
<!DOCTYPE html>
<html>
<head>
Expand Down
Loading