Gathering detailed insights and metrics for @fivvy/ionic-contextual-profiler
Gathering detailed insights and metrics for @fivvy/ionic-contextual-profiler
Gathering detailed insights and metrics for @fivvy/ionic-contextual-profiler
Gathering detailed insights and metrics for @fivvy/ionic-contextual-profiler
npm install @fivvy/ionic-contextual-profiler
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
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.
⚠️ Important Notice: This library does not support iOS devices.
Please be aware that this library is currently only available for Android. It will not work on iOS devices. Ensure that your project is intended for Android platforms before integrating this library.
Please read this entire section.
npm install @fivvy/ionic-contextual-profiler
yarn add @fivvy/ionic-contextual-profiler
npx cap sync
the terminal will log the name of the plugin
√ Updating Android plugins in 9.74ms
[info] Found 5 Capacitor plugins for android:
@capacitor/app@5.0.6
@capacitor/haptics@5.0.6
@capacitor/keyboard@5.0.7
@capacitor/status-bar@5.0.6
@fivvy/ionic-contextual-profiler
If you have any obfucastion tool in your project, you'll need to exclude this package to work as intended in release builds.
Create a new file called proguard-rules.pro in /android/app with this content:
-keep class com.fivvy.profiler.** { *; }
-keep class * extends com.fivvy.profiler.** { *; }
-keepclassmembers class com.fivvy.profiler.** {
*;
}
-keepattributes *Annotation*
Add the following settings in build.gradle within /android/app
buildTypes {
release {
...
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Necessary to add this xmlns:tools inside the tag manifest in the AndroidManifest inside android/app/src/main folder.
1<manifest xmlns:tools="http://schemas.android.com/tools">
Need to add these permissions in the AndroidManifest inside android/app/src/main folder.
1<uses-permission android:name="android.permission.INTERNET" />
Add the Maven repository URL to your project-level build.gradle
file:
1allprojects { 2 repositories { 3 google() 4 mavenCentral() 5 maven { 6 url "https://gitlab.com/api/v4/projects/58175283/packages/maven" 7 } 8 } 9}
Add the implementation dependency to your app-level build.gradle file:
1dependencies { 2 (...) 3 implementation 'com.fivvy:fivvy-lib:3.2.6@aar' 4}
make sure you also have:
1 implementation 'androidx.appcompat:appcompat:1.4.0' 2 implementation 'androidx.work:work-runtime:2.8.0' 3 implementation 'com.google.code.gson:gson:2.8.9' 4 implementation 'com.squareup.okhttp3:okhttp:4.9.2' 5 implementation 'androidx.security:security-crypto-ktx:1.1.0-alpha04' 6 implementation 'com.scottyab:rootbeer-lib:0.1.1'
1import { ContextualProfiler } from '@fivvy/ionic-contextual-profiler ';
2
3const { initContextualDataCollection } = ContextualProfiler;
4
5const sendData = async () => {
6 const res = await initContextualDataCollection({
7 customerId: "ionic-user-2", // Represents an identifier of the current user
8 apiKey: ENV.API_KEY, // ApiKey of Fivvy's API - ENVIRONMENT VARIABLE
9 apiSecret: ENV.API_SECRET, // ApiSecret of Fivvy's API - ENVIRONMENT VARIABLE
10 appUsageDays: 30, // Integer that represents the last days to recollect the app usage information of the user. Recommended default value: 30
11 authApiUrl: ENV.AUTH_API_URL, // URL of the Fivvy's Auth API: https://api.fivvyforbusiness.com/b2b-auth/auth/v1/users/login
12 sendDataApiUrl: ENV.SEND_DATA_API_URL // URL of the Fivvy's Analytics Data API: https://api.fivvyforbusiness.com/b2b-intake/intake/v2/context
13 });
14 console.log("response: ", res); // RESPONSE IS CONTEXTUAL DATA OBJECT
15};
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. |
getAppsInstalled | Empty | Promise<IInstalledApps[]> | Returns an IInstalledApps Array for all the queries in AndroidManifest that user had install in his phone. |
Here you can find the interfaces that sdk uses
1`initContextualCollectionData param object interface` 2InitConfig { 3 customerId: string, 4 apiUsername: string, 5 apiPassword: string, 6 appUsageDays: number, 7 authApiUrl: string, 8 sendDataApiUrl: string 9} 10`getDeviceInformation return interface` 11IHardwareAttributes { 12 api_level: string; 13 device_id: string; 14 device: string; 15 hardware: string; 16 brand: string; 17 manufacturer: string; 18 model: string; 19 product: string; 20 tags: string; 21 type: string; 22 base: string; 23 id: string; 24 host: string; 25 fingerprint: string; 26 incremental_version: string; 27 release_version: string; 28 base_os: string; 29 display: string; 30 battery_status: number; 31 publicIP: string 32 } 33`getAppsInstalled return object interface` 34IInstalledApps { 35 appName?: string; 36 packageName: string; 37 category?: string; 38 installTime?: string; 39 lastUpdateTime?: string; 40 versionCode?: string; 41 versionName?: string; 42}
Recovery of applications installed on the user's device.
1getAppsInstalled().then(data => console.log('Installed apps:', data)); 2// expected output 3 Installed Apps: [{"appName": "WhatsApp", "category": "Social", "installTime": "2023.02.15 20:07:35", "lastUpdateTime": "2023.08.16 14:52:12", "packageName": "com.whatsapp", "versionCode": "231676002", "versionName": "2.23.16.76"}] 4
To enable and properly use the debug mode, follow these steps:
The project must have the BuildConfig
class generated, which is standard in Ionic projects configured for Android. If your project does not generate BuildConfig
, proceed to step 2.
If BuildConfig
is not automatically generated or does not include the required property:
build.gradle
file located at /android/app
.1android { 2 ... 3 buildFeatures { 4 buildConfig true 5 } 6}
⚠️ Important: The applicationId and namespace in your project must be identical. Debug mode will not work properly if these values are different.
⚠️ Important Notice: iOS Compatibility
This library is not compatible with iOS devices. It is specifically designed for Android platforms, and no support for iOS is provided. Please refrain from using this library in iOS-based projects, as it will not function as intended.
On android you must request permissions beforehand. This part is divided into two sections to show how to open the usage settings on Android using a custom modal dialog or directly without a modal.
Need to add these permissions in the AndroidManifest inside android/app/src/main folder.
1<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
To open the usage settings with a custom dialog and an image from the assets folder, follow these steps:
Create a method to read an image from the assets folder and convert it to a byte array.
1async function convertImageToByteArray(imagePath: string): Promise<number[]> { 2 const response = await fetch(imagePath); 3 const blob = await response.blob(); 4 5 return new Promise((resolve, reject) => { 6 const reader = new FileReader(); 7 reader.onloadend = () => { 8 const arrayBuffer = reader.result as ArrayBuffer; 9 const byteArray = new Uint8Array(arrayBuffer); 10 resolve(Array.from(byteArray)); 11 }; 12 reader.onerror = reject; 13 reader.readAsArrayBuffer(blob); 14 }); 15} 16
Include the method in your Ionic component and use it to open the usage settings WITH a custom dialog.
1import { Plugins } from '@capacitor/core'; 2const { ContextualProfiler } = Plugins; 3 4async function showUsageSettingsDialog() { 5 try { 6 // Make sure the path to your image is correct. Note If the image does not open, check that the image is in the build/dist folder to be accessible 7 const imagePath = await convertImageToByteArray('assets/example.png'); 8 // ln could be ES, EN, PR at the moment 9 await ContextualProfiler.createOpenUsageSettingsUseCase({ 10 ln: 'ES', 11 appName: 'AppDemo', 12 appDescription: 'Some Description', 13 modalText: 'Some guide text', 14 imagePath: imagePath || [0,0,0], 15 imageView: 1,// integer value, 0: no image; 1: default image, 2: app logo 16 buttonRadius: 25.0,// float value, set button border radius 17 modalRadius: 25.0,// float value, set modal border radius 18 color: '#50C7FA',// hex color value, set color of dialog title, accept background color and cancel button text color 19 dialogTitle: 'Custom Usage Information Title', 20 dialogMessage1: 'Custom message 1 about usage permissions.', 21 dialogMessage2: 'Custom message 2 about privacy and data collection.', 22 blacklist: null // (Optional) List of device manufacturers for which the usage settings should be avoided. On some devices, especially from certain manufacturers as Xiaomi, a system warning might be displayed when attempting to access the usage settings. To prevent this action on those devices, you can: 23 24 //- Pass `null`: This will apply a default list of manufacturers known to have this issue. 25 // - Provide a custom list of manufacturers as an array (`["manufacturer1", "manufacturer2"]`): This will prevent the settings from being accessed only on devices from those specific brands. 26 //- Pass an empty array `[]`: This will allow the settings to be accessed on all devices without any restrictions. 27 28 }); 29 } catch (e) { 30 console.error('Error opening usage settings', e); 31 } 32}
If you prefer to open the usage settings directly without a custom dialog, follow these steps:
Include the method in your Ionic component and use it to open the usage settings directly.
1import { Plugins } from '@capacitor/core'; 2const { ContextualProfiler } = Plugins; 3 4async function showUsageSettings() { 5 try { 6 await ContextualProfiler.createOpenUsageSettingsDirectlyUseCase({blacklist: ['samsung']});// - blacklist (Optional) List of device manufacturers for which the usage settings should be avoided. On some devices, especially from certain manufacturers as Xiaomi, a system warning might be displayed when attempting to access the usage settings. To prevent this action on those devices, you can: 7 8 //- Pass `null`: This will apply a default list of manufacturers known to have this issue. 9 // - Provide a custom list of manufacturers as an array (`["manufacturer1", "manufacturer2"]`): This will prevent the settings from being accessed only on devices from those specific brands. 10 //- Pass an empty array `[]`: This will allow the settings to be accessed on all devices without any restrictions. 11 12 } catch (e) { 13 console.error('Error opening usage settings', e); 14 } 15}
blacklist
ParameterThe blacklist
parameter is an array of strings containing the names of device manufacturers for which you want to disable a certain function. If the device is from a manufacturer listed in this array, the function will not perform any action.
blacklist
Behavior:1blacklist: ["xiaomi", "huawei"]
1blacklist: []
1blacklist: null
This fucntion will return the current device manufacturer, this could be useful if you need to implement more complex logic in your app regarding the device manufacturer.
1const result = await ContextualProfiler.logDeviceManufacturer(); 2console.log("Device Manufacturer:", result.message);
Here's a full list of manufacturers names in Android: Android manufacturer names
By following these steps, you can either use a custom dialog to guide the user or open the usage settings directly without additional prompts.
Methods | Params value | Return value | Description |
---|---|---|---|
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. |
openUsageAccessSettings | {ln: String, appName: String, appDescription: String, modalText: String, imagePath: byte[], imageView: number, buttonRadius: Float, modalRadius: Float, color: String, dialogTitle: String, dialogMessage1: String, dialogMessage2: String} | Boolean | Open settings with pre-built modal view to grant app usage permission. |
openUsageAccessSettingsDirectly | Empty | Boolean | Open settings view without pre-built modal to grant app usage permission. |
Here you can find the interfaces that sdk uses
1`getAppUsage return object interface` 2IAppUsage { 3 appName: string; 4 usage: number; 5 packageName: string; 6}
All content here is the property of Fivvy, it should not be used without their permission.
No vulnerabilities found.
No security vulnerabilities found.