Flutter SDK
Koah Flutter SDK allows you to integrate ads into your Flutter application.
Installation
Koah SDK should be available for install soon via the pub.dev package manager.
Configuration
To start, add koah_flutter
to your pubspec.yaml
:
dependencies:
flutter:
sdk: flutter
koah_flutter: ^1.0.0
Then complete the set up for each platform:
Android
Add your Koah configuration to your AndroidManifest.xml
file location in the android/app/src/main
directory:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourapp">
<application>
<meta-data android:name="com.koah.api_key" android:value="<YOUR_API_KEY>" />
</application>
</manifest>
And setup the SDK manually,
Future<void> main() async {
// initialize WidgetsFlutterBinding if not yet
WidgetsFlutterBinding.ensureInitialized();
final config = KoahConfig("<YOUR_API_KEY>");
await Koah.initialize(config);
runApp(MyApp());
}
In all cases, you will need to update the minimum SDK version to 21 or higher in your android/app/build.gradle
file.
defaultConfig {
minSdkVersion 21
// ...
}
iOS
You will need to have Cocoapods installed. Add your Koah configuration to your ios/Runner/Info.plist
file:
<key>com.koah.api_key</key>
<string>YOUR_API_KEY</string>
Or setup the SDK manually,
Future<void> main() async {
// initialize WidgetsFlutterBinding if not yet
WidgetsFlutterBinding.ensureInitialized();
final config = KoahConfig("<YOUR_API_KEY>");
await Koah.initialize(config);
runApp(MyApp());
}
In both cases, you will need to update the minimum iOS deployment target to 13.0 or higher in your Podfile.
platform :ios, '13.0'
# ...
Web
For web, add your Web snippet
in the <head>
section of your index.html
file:
<head>
<script src="https://cdn.jsdelivr.net/npm/koah-flutter@latest/dist/koah_flutter.js"></script>
</head>
For more information on the web setup, see the Web SDK documentation.
Inject ads
Use the SDK to get AI responses with contextually relevant ads injected:
// The response will contain markdown with injected ads
final enrichedResponse = await Koah.process(
question: "What are some good machine learning libraries?",
response: "I recommend using Python for this project since it has great machine learning libraries and extensive documentation for data science applications.",
adFormat: "suffix",
);
// Example response with injected ad:
// "I recommend using Python for this project since it has great machine learning libraries
// { Check out TensorFlow Pro - The #1 ML Framework for Python }
// and extensive documentation for data science applications."
// Display the response using a markdown widget
return MarkdownBody(
data: enrichedResponse,
onTapLink: (text, href, title) {
// Ad clicks are automatically tracked by the SDK
// You can add additional handling here if needed
},
);
The SDK automatically handles:
- Contextual ad injection into AI responses
- Ad impression tracking
- Ad click tracking
- Analytics reporting