Flutter demo app for Screeb
This project is a starting point for a all developers who wish to integrate native Android & iOS Screeb sdk in a Flutter project.
For Android you need to add the Screeb sdk dependency in the Android build.gradle of the app, you'll find the instructions on the repo of the Android demo app.
For iOS you need to add the Screeb sdk dependency in the Podfile of the app, you'll find the instructions on the repo of the iOs sdk.
Like in the Android demo app, the access point of the SDK must be created in a custom Application class,
see DemoApplication.kt
. You should create a Screeb instance using the builder and reference it in a
static variable to be used later in your app.
At this point, the SDK is installed and configured and can be used without any more operation. But you'll probably need to communicate with it and send tracking information, declaring user's properties or set user's identity.
To access these commands of the Screeb.kt
class, we need to create a MethodChannel
to configure
the interface between flutter code and Android specific functions.
In MainActivity.kt
a MethodChannel with name "screeb/commands" is configured to call Screeb functions
setIdentity()
, trackEvent()
, trackScreen()
and setVisitorProperties()
.
when (call.method) {
"setIdentity" -> {
val userId = call.argument<String>("userId")
userId?.let {
DemoApplication.screeb.setIdentity(it)
result.success(true)
} ?: result.error(
"MISSING_ARGUMENT",
"setIdentity function needs a userId parameter",
null
)
}
}
The initialization point of the SDK must be created in the AppDelegate class,
see AppDelegate.swift
in the Runner
module. You should call the method Screeb.init(...) with a valid channelId
in parameter.
At this point, the SDK is installed and configured and can be used without any more operation. But you'll probably need to communicate with it and send tracking information, declaring user's properties or set user's identity.
To access these commands of the Screeb.swift
class, we need to create a MethodChannel
to configure
the interface between flutter code and iOS specific functions.
In AppDelegate.swift
a MethodChannel with name "screeb/commands" is configured to call Screeb functions
setIdentity()
, trackEvent()
, trackScreen()
and setVisitorProperties()
.
switch call.method {
case "setIdentity":
guard let args = call.arguments else { return }
if let myArgs = args as? [String: Any], let userId = myArgs["userId"] as? String {
Screeb.setIdentity(uniqueVisitorId: userId)
result(true)
} else {
result(FlutterError(code: "-1",
message: "iOS could not extract flutter arguments in method: \(call.method)",
details: nil))
}
// (...)
}
Then, to call these functions, you'll find in main.dart
some examples using platform.invokeMethod()
:
static const platform = MethodChannel('screeb/commands');
void identity() {
platform.invokeMethod(
'setIdentity', <String, dynamic>{'userId': '[email protected]'});
}
To remove warning from the Android SDK, just set a theme that inherits from Theme.AppCompat
. In this project,
the theme Theme.AppCompat.Light.NoActionBar
is used and should have no impact on the flutter UI styling.
In case of problem, feel free to contact us or create an issue in this repository.