Getting started profiler
Contextual Profiler SDK offers a comprehensive and efficient solution for collecting valuable information about your users. With this powerful tool, you will be able to gather relevant data that will allow you to conduct in-depth analysis and gain a clear understanding of your users' behavior, preferences, and needs.
See the full API for more methods.
Recommendations
- FLUTTER: >= 3.3.0
- ANDROID API LEVEL: 21 to 33 (we recommend 24 to 33)
- MIN JAVA VERSION: jdk11
- GRADLE DISTRIBUTION: gradle-7.5.1
Installation
Please read this entire section.
Android
you MUST add this line to build.gradle (proyect)
allprojects {
repositories {
google()
mavenCentral()
maven {
url "https://gitlab.com/api/v4/projects/58175283/packages/maven"
}
}
}
and in build.gradle (app)
implementation 'com.fivvy:fivvy-lib:1.1.1@aar'
make sure you also have:
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.work:work-runtime:2.8.0'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
Permissions
AndroidManifest
Necesary to add this xmlns:tools insde the tag manifest on AndroidManifest.xml insde android/app/src/main folder.
<manifest
<!-- Others manifest properties -->
xmlns:tools="http://schemas.android.com/tools"
>
Need to add these permissions in the AndroidManifes.xml file inside android/app/src/main before aplication tag.
<manifest>
<!-- others aplications tags -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
<!-- List of apps that you want to check on customer device -->
<queries>
<!-- List of package's [Max 100] -->
<package android:name="com.whatsapp"/> <!-- WhatsApp Messenger -->
<package android:name="com.facebook.katana"/> <!-- Facebook -->
<package android:name="com.mercadopago.android"/> <!-- Mercado Pago -->
</queries>
<application>
<!-- ... -->
</application>
</manifest>
Integration in App
On android you must request permissions beforehand
Init of plugin
First of all, you will need to instantiated previously the ContextualProfiler plugin on the Widget where you will use the methods.
import 'package:profiler/plugin/contextual_profiler.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// ADD THIS LINE
final _profilerPlugin = ContextualProfiler();
// Your Code
}
Get user permission to check the app's usage
This is an exclusive custom dialog that you can invoke in your app to get bring a easy way to request access usage permission from the user.
First you need to add a function to transform an image to a byte array.
Future<Uint8List> loadImageBytes(String assetPath) async {
final ByteData data = await rootBundle.load(assetPath);
return data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
}
then implement this method:
Future<void> openAccessUsageSettings() async {
String platformVersion;
final Uint8List imageBytes = await loadImageBytes("assets/images/logo.png");
final usageSetting = UsageSetting(
language: "ES", // If selected, the default texts will be set on the modal for EN, ES, or PR.
// If using the ln value, it is recommended not to use the parameters below as the ln sets default texts in the right language.
appName: 'Fivvy', // string value with your app name
imagePath:
imageBytes, // this image should be in android/app/src/main/res/drawable/logo.png
appDescription: 'Activate the permission', // optional description text. Recommended length: 3 or 4 words
modalText: 'Lorem ipsum text', // optional modal text. Recommended length: 3 or 4 words
dialogTitle: "Dialog Title", // Title of the dialog displayed to the user before redirecting to the settings screen for permissions.
dialogMessage1: "Dialog message 1", // Custom Message of the dialog displayed to the user before redirecting to the settings screen for permissions.
dialogMessage2: "Dialog message 2" // Other custom Message of the dialog displayed to the user before redirecting to the settings screen for permissions.
);
try {
await _profilerPlugin.openUsageAccessSettings(usageSetting);
platformVersion = 'opened successfully';
} on PlatformException {
platformVersion = 'Failed to open Access Usage Settings.';
}
if (!mounted) return;
setState(() {
_response = platformVersion;
});
}
also add to .yaml file the asset:
flutter:
assets:
- assets/images/logo.png
Another option
However, there is a separate function in case you want to create a custom dialog that best suits your application.
Consider having the ContextualProfiler here as _profilerPlugin plugin instantiated previously.
Future<void> openAccessUsageSettingsDirectly() async {
String platformVersion;
try {
await _profilerPlugin.openUsageAccessSettingsDirectly();
platformVersion = 'opened successfully';
} on PlatformException {
platformVersion = 'Failed to open Access Usage Settings.';
}
if (!mounted) return;
setState(() {
_response = platformVersion;
});
}
Send data to Fivvy's analytics service
This function will allow your app to send the information of each user to the Fivvy Analytic's API. You must add on some view or loading component that can send the data at least 1 time a day.
Future<void> initContextualDataCollection() async {
String response;
ContextualCredential initConfig = ContextualCredential(
customerId: customerId,
apiPassword: apiSecret,
apiUsername: apiKey,
authApiUrl: authApiUrl,
sendDataApiUrl: sendDataApiUrl);
try {
await _profilerPlugin.initContextualDataCollection(initConfig);
response = 'Send data successfully';
} on PlatformException {
response = 'Something went wrong.';
}
if (!mounted) return;
setState(() {
this._response = response;
});
}
API
All the information about the package and how to use functions.
| Methods | Params value | Return value | Description |
|---|---|---|---|
initContextualDataCollection |
InitConfig {customerId: String, apiKey: String, apiSecret: String, appUsageDays: Int, authApiUrl: String, sendDataApiUrl: String} |
ContextualData |
Initiates data collection, sending it to the Fivvy's Analytics Data API. |
getDeviceInformation |
Empty | Promise<IHardwareAttributes> |
Returns the device hardware information of the customer. |
getAppUsage |
Int days. Represent the last days to get the usage of each app. |
Promise<IAppUsage[]> |
Returns an IAppUsage Array for all the queries in AndroidManifest that user had install in his phone or null if user doesn’t bring usage access. |
getAppsInstalled |
Empty | Promise<IInstalledApps[]> |
Returns an IInstalledApps Array for all the queries in AndroidManifest that user had install in his phone. |
openUsageAccessSettings |
Empty | Boolean |
Open settings view to grant app usage permission. |
Interfaces
Here you can find the interaces that sdk uses
`initContextualCollectionData param object interface`
InitConfig {
customerId: string,
apiUsername: string,
apiPassword: string,
appUsageDays: number,
authApiUrl: string,
sendDataApiUrl: string
}
`getDeviceInformation return interface`
IHardwareAttributes {
api_level: string;
device_id: string;
device: string;
hardware: string;
brand: string;
manufacturer: string;
model: string;
product: string;
tags: string;
type: string;
base: string;
id: string;
host: string;
fingerprint: string;
incremental_version: string;
release_version: string;
base_os: string;
display: string;
battery_status: number;
}
`getAppUsage return object interface`
IAppUsage {
appName: string;
usage: number;
packageName: string;
}
`getAppsInstalled return object interface`
IInstalledApps {
appName?: string;
packageName: string;
category?: string;
icon?: string;
installTime?: string;
lastUpdateTime?: string;
versionCode?: string;
versionName?: string;
}
`openUsageSettings param object interface`
IUsageSetting {
String? language;
Uint8List? imagePath;
String? appName;
String? appDescription;
String? modalText;
String? dialogTitle;
String? dialogMessage1;
String? dialogMessage2;
}
Terms of use
All content here is the property of Fivvy, it should not be used without their permission.