Gathering detailed insights and metrics for @fivvy/cordova-plugin-contextual-profiler
Gathering detailed insights and metrics for @fivvy/cordova-plugin-contextual-profiler
Gathering detailed insights and metrics for @fivvy/cordova-plugin-contextual-profiler
Gathering detailed insights and metrics for @fivvy/cordova-plugin-contextual-profiler
npm install @fivvy/cordova-plugin-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
No dependencies detected.
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.
1cordova plugin add @fivvy/cordova-plugin-contextual-profiler 2
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'
}
}
make sure you have the Maven repository URL on 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}
and the implementation dependency on 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 2 implementation 'androidx.appcompat:appcompat:1.4.0' 3 implementation 'androidx.work:work-runtime:2.8.0' 4 implementation 'com.google.code.gson:gson:2.8.9' 5 implementation 'com.squareup.okhttp3:okhttp:4.9.2' 6 implementation 'androidx.security:security-crypto-ktx:1.1.0-alpha04' 7 implementation 'com.scottyab:rootbeer-lib:0.1.1'
Necesary to add this xmlns:tools insde the tag manifest on AndroidManifest.xml insde android/app/src/main folder.
1<manifest 2 xmlns:tools="http://schemas.android.com/tools" 3>
Need to add these permissions in the AndroidManifes.xml file inside android/app/src/main before aplication tag.
1<manifest> 2 <!-- others aplications tags --> 3 <uses-permission android:name="android.permission.INTERNET" /> 4</manifest>
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.
1document.addEventListener('deviceready', onDeviceReady, false); 2 3function onDeviceReady() { 4 console.log('Running cordova-' + cordova.platformId + '@' + cordova.version); 5 document.getElementById('deviceready').classList.add('ready'); 6} 7const customerId = 'customer-id-01'; // Represents an identifier of the current user 8const days = 30; // Integer that represents the last days to recollect the app usage information of the user. Recommended default value: 30 9const API_KEY = 'XXXXXXX'; // ApiKey of Fivvy's API 10const API_SECRET = 'XXXXXXX'; // ApiSecret of Fivvy's API - ENVIRONMENT VARIABLE 11const AUTH_API_URL = 'https://XXXXXXXXXXX'; // URL of the Fivvy's Auth API: https://api.fivvyforbusiness.com/b2b-auth/auth/v1/users/login 12const SEND_DATA_API_URL = 'https://XXXXXXXXXXX'; // URL of the Fivvy's Analytics Data API: https://api.fivvyforbusiness.com/b2b-intake/intake/v2/context 13 14function testSendData() { 15 cordova.plugins.ContextualProfilerPlugin.initContextualDataCollection(customerId, API_KEY, API_SECRET, AUTH_API_URL,SEND_DATA_API_URL,days, function(result) { 16 console.log('Success: ' + result); 17 }, function(error) { 18 console.log('Error: ' + error); 19 }); 20} 21document.getElementById('sendData').addEventListener('click', testSendData);
Methods | Params value | Return value | Description |
---|---|---|---|
initContextualDataCollection | (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` 2 InitConfig { 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 } 32 `getAppsInstalled return object interface` 33 IInstalledApps { 34 appName?: string; 35 packageName: string; 36 category?: string; 37 installTime?: string; 38 lastUpdateTime?: string; 39 versionCode?: string; 40 versionName?: string; 41 }
To enable and properly use the debug mode, follow these steps:
The project must have the BuildConfig
class generated, which is standard in Cordova 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.
1 async function convertImageToByteArray(imagePath) { 2 try { 3 const response = await fetch(imagePath); 4 const blob = await response.blob(); 5 6 return new Promise((resolve, reject) => { 7 const reader = new FileReader(); 8 reader.onloadend = () => { 9 const arrayBuffer = reader.result; 10 const byteArray = new Uint8Array(arrayBuffer); 11 resolve(Array.from(byteArray)); 12 }; 13 reader.onerror = reject; 14 reader.readAsArrayBuffer(blob); 15 }); 16 } catch (error) { 17 console.error("Error converting image to byte array: ", error); 18 } 19 }
1 async function testOpenUsageSettings() { 2 const lang = "ES"; // lang could be ES, EN, PR at the moment 3 const appName = "appname"; // string value with your app name 4 const appDescription = "app description"; // optional description text. Recommended length: 3 or 4 words 5 const imagePath = await convertImageToByteArray('/img/logo.png'); // Make sure the path to your image is correct. 6 const imageView: 1;// integer value, 0: no image; 1: default image, 2: app logo 7 const buttonRadius: 25.0;// float value, set button border radius 8 const modalRadius: 25.0;// float value, set modal border radius 9 const color: '#50C7FA';// hex color value, set color of dialog title, accept background color and cancel button text color 10 const modalText = "modal text"; // optional modal text. Recommended length: 3 or 4 words 11 const title = "titulo"; // Title of the dialog displayed to the user before redirecting to the settings screen for permissions. 12 const message1 = "mensaje 1"; // Custom Message of the dialog displayed to the user before redirecting to the settings screen for permissions. 13 const message2 = "mensaje 2";// Other custom Message of the dialog displayed to the user before redirecting to the settings screen for permissions. 14 const blacklist = null // - 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: 15 16 //- Pass `null`: This will apply a default list of manufacturers known to have this issue. 17 // - 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. 18 //- Pass an empty array `[]`: This will allow the settings to be accessed on all devices without any restrictions. 19 20 if (imagePath && imagePath.length > 0) { 21 cordova.plugins.ContextualProfilerPlugin.openUsageSettings(lang, appName, appDescription, imagePath, imageView, buttonRadius, modalRadius, color, modalText, title, message1, message2, blacklist, function(result) { 22 console.log('Success: ' + result); 23 document.getElementById('openUsageSettingsResult').innerText = 'Success: ' + result; 24 }, function(error) { 25 console.log('Error: ' + error); 26 document.getElementById('openUsageSettingsResult').innerText = 'Error: ' + error; 27 }); 28 } else { 29 document.getElementById('openUsageSettingsResult').innerText = 'Image path array is empty or not valid.'; 30 } 31}
If you prefer to open the usage settings directly without a custom dialog, follow these steps:
Include the method in your component and use it to open the usage settings directly.
1function testOpenUsageSettingsDirectly() { 2 cordova.plugins.ContextualProfilerPlugin.openUsageSettingsDirectly(blacklist, function(result) { 3 console.log('Success: ' + result); 4 document.getElementById('openUsageSettingsDirectlyResult').innerText = 'Success: ' + result; 5 }, function(error) { 6 console.log('Error: ' + error); 7 document.getElementById('openUsageSettingsDirectlyResult').innerText = 'Error: ' + error; 8 }); 9}
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: Int , buttonRadius: Float , modalRadius: Float , color: String , dialogTitle: String , dialogMessage1: String , dialogMessage2: String , blacklist: [] | null} | Boolean |
openUsageAccessSettingsDirectly | (blacklist: [] | null) | Boolean |
Here you can find the interfaces that sdk uses
1 `getAppUsage return object interface` 2 IAppUsage { 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.