Repository navigation
feat: add Flutter framework support #942
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
Merged
edwinyjlim
merged 3 commits into
PostHog:main
from
peter-trost:feat/flutter-framework-support
Aug 3, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* Flutter wizard using posthog-agent with PostHog MCP */ | ||
| import type { WizardRunOptions } from '@utils/types'; | ||
| import type { FrameworkConfig } from '@lib/framework-config'; | ||
| import { Integration } from '@lib/constants'; | ||
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import { pubPackageManager } from '@lib/detection/package-manager'; | ||
|
|
||
| /** Platform subtrees `flutter create` scaffolds; each needs its own setup notes. */ | ||
| const FLUTTER_PLATFORM_DIRS = [ | ||
| 'android', | ||
| 'ios', | ||
| 'web', | ||
| 'macos', | ||
| 'linux', | ||
| 'windows', | ||
| ] as const; | ||
|
|
||
| type FlutterContext = { | ||
| platforms?: string[]; | ||
| }; | ||
|
|
||
| function readPubspec(installDir: string): string | undefined { | ||
| const pubspecPath = path.join(installDir, 'pubspec.yaml'); | ||
| if (!fs.existsSync(pubspecPath)) return undefined; | ||
| return fs.readFileSync(pubspecPath, 'utf-8'); | ||
| } | ||
|
|
||
| export const FLUTTER_AGENT_CONFIG: FrameworkConfig<FlutterContext> = { | ||
| metadata: { | ||
| name: 'Flutter', | ||
| integration: Integration.flutter, | ||
| docsUrl: 'https://posthog.com/docs/libraries/flutter', | ||
| gatherContext: (options: WizardRunOptions) => { | ||
| const platforms = FLUTTER_PLATFORM_DIRS.filter((dir) => | ||
| fs.existsSync(path.join(options.installDir, dir)), | ||
| ); | ||
| return Promise.resolve({ platforms }); | ||
| }, | ||
| }, | ||
|
|
||
| detection: { | ||
| packageName: 'posthog_flutter', | ||
| packageDisplayName: 'Flutter', | ||
| usesPackageJson: false, | ||
| getVersion: () => undefined, | ||
| detectPackageManager: pubPackageManager, | ||
| // A pubspec.yaml alone is any Dart project; depending on the Flutter SDK | ||
| // (`sdk: flutter`) is what makes it a Flutter app. Anchored to a key/value | ||
| // line so comments (`# sdk: flutter`) don't match. | ||
| detect: (options) => { | ||
| const pubspec = readPubspec(options.installDir); | ||
| return Promise.resolve(/^\s*sdk:\s*flutter\s*$/m.test(pubspec ?? '')); | ||
| }, | ||
| }, | ||
|
|
||
| environment: { | ||
| uploadToHosting: false, | ||
| getEnvVars: (apiKey: string, host: string) => ({ | ||
| POSTHOG_PROJECT_TOKEN: apiKey, | ||
| POSTHOG_HOST: host, | ||
| }), | ||
| }, | ||
|
|
||
| analytics: { | ||
| getTags: (context) => ({ | ||
| ...(context.platforms?.length | ||
| ? { platforms: context.platforms.join(',') } | ||
| : {}), | ||
| }), | ||
| }, | ||
|
|
||
| prompts: { | ||
| projectTypeDetection: | ||
| 'This is a Flutter project. Look for pubspec.yaml declaring a dependency on the Flutter SDK (flutter: sdk: flutter) and a lib/ directory with Dart source files to confirm.', | ||
| packageInstallation: | ||
| 'Add the PostHog Flutter SDK with `flutter pub add posthog_flutter`. Do not edit pubspec.yaml by hand; the pub tool updates it and resolves the version automatically.', | ||
| getAdditionalContextLines: (context) => { | ||
| const lines = [ | ||
| 'Framework docs ID: flutter (use posthog://docs/frameworks/flutter for documentation)', | ||
| 'Prefer manual initialization in Dart (PostHogConfig + Posthog().setup) over the platform auto-init so configuration lives in one place; when doing so, disable auto-init in the Android manifest and iOS Info.plist per the docs.', | ||
| ]; | ||
|
|
||
| if (context.platforms?.length) { | ||
| lines.push( | ||
| `Enabled target platforms: ${context.platforms.join( | ||
| ', ', | ||
| )}. Apply the platform-specific setup steps from the docs for each (e.g. AndroidManifest.xml on Android, Info.plist on iOS/macOS, the JS snippet in web/index.html for web).`, | ||
| ); | ||
| } | ||
|
|
||
| return lines; | ||
| }, | ||
| }, | ||
|
|
||
| ui: { | ||
| successMessage: 'PostHog integration complete', | ||
| estimatedDurationMinutes: 5, | ||
| getOutroChanges: () => [ | ||
| 'Analyzed your Flutter project structure', | ||
| 'Added the posthog_flutter SDK to your pubspec', | ||
| 'Configured PostHog initialization', | ||
| 'Added event capture and user identification', | ||
| ], | ||
| getOutroNextSteps: () => [ | ||
| 'Run your app to see PostHog in action', | ||
| 'Visit your PostHog dashboard to see incoming events', | ||
| 'Check out the PostHog Flutter docs for session replay, feature flags, and more', | ||
| ], | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.