npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fivvy/contextual-profiler

v2.0.0

Published

Contextual Profiler SDK for React Native. Recommended for 0.69.X or higher React Native versions.

Downloads

1,081

Readme

Getting started Fivvy contextual-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.

⚠️ 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.

See the full API for more methods.

Recommendations

  • REACT NATIVE VERSION: >= 0.69.0 (we recommend 0.72.X or above)
  • ANDROID API LEVEL: 21 a 34 (We recommend 34)
  • MIN JAVA VERSION: jdk11 (we recommend jdk17)

Installation

Please read this entire section.

npm

npm install @fivvy/contextual-profiler

yarn

yarn add @fivvy/contextual-profiler

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:2.0.0@aar'

Permissions

AndroidManifest

Necesary to add this xmlns:tools insde the tag manifest on AndroidManifest inside android/app/src/main folder.

<manifest xmlns:tools="http://schemas.android.com/tools">

Need to add these permissions in the AndroidManifest inside android/app/src/main folder.

<uses-permission  android:name="android.permission.INTERNET" />
<uses-permission  android:name="android.permission.PACKAGE_USAGE_STATS"  tools:ignore="ProtectedPermissions" />

<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>

Android Permission Request

On Android, you must request permissions beforehand to check the app's usage. We recommend creating a logic with AsyncStorage to remember if the user doesn't want to give access to this permission.

Get User Permission to Check App Usage

We have a pre-made modal with instructions that can be used for this purpose. Here is an example of how to implement it:

import { getAppUsage, openUsageAccessSettings } from 'contextual-profiler';

 openUsageAccessSettings({
      appName: 'Fivvy', // string value with your app name
      imagePath: 'logo',// this image should be in android/app/src/main/res/drawable/logo.png
      ln: "EN", // 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.
      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.
      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:

      //- Pass `null`: This will apply a default list of manufacturers known to have this issue.
      // - 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.
      //- Pass an empty array `[]`: This will allow the settings to be accessed on all devices without any restrictions.

    });

Direct Access to Settings

If you prefer not to display any modal and want to go directly to the settings screen, you can use

openUsageAccessSettingsDirectly(blacklist); // - 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:

      //- Pass `null`: This will apply a default list of manufacturers known to have this issue.
      // - 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.
      //- Pass an empty array `[]`: This will allow the settings to be accessed on all devices without any restrictions.

blacklist Parameter

The 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:

  • Array with specific manufacturers: If the array contains manufacturer names, the function will be disabled on devices from those brands. Example:
blacklist: ["xiaomi", "huawei"]
  • Empty Array: The feature will work on any manufacturer device. Example:
  blacklist: []
  • Null value: The feature will use a default blacklist, here are the default blacklisted manufacturers: ["xiaomi", "huawei", "oppo", "vivo", "realme", "lenovo", "meizu", "oneplus", "zte", "nubia"]
 blacklist: null

Here's a full list of manufacturers names in Android: Android manufacturer names

Device manufacturer

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.

getDeviceManufacturer().then((data) => {
      console.log(data.manufacturer);
    })

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.

Every time this useEffect run, the data will be send to the Fyvvy's API.

  useEffect(() => {
    const contextualConfigObj = {
      customerId: customerId, // Represents an identifier of the current user
      apiKey: API_KEY, // ApiKey of Fivvy's API
      apiSecret: API_SECRET, // ApiSecrey of Fivvy's API
      appUsageDays: DAYS, // Integer that represents the last days to recollect the app usage information of the user
      authApiUrl: AUTH_API_URL, // URL of the Fivvy's Auth API
      sendDataApiUrl: SEND_DATA_API_URL, // URL of the Fivvy's Analytics Data API
      forceInit: BOOLEAN  // Boolean parameter that controls the data submission and collection process. If set to `false`, data will not be re-sent or collected until 24 hours have passed since the last submission. If set to `true`, this condition will be ignored, and data will be sent or collected immediately, regardless of the time elapsed.
    }
    await initContextualDataCollection(contextualConfigObj);
},[])

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, forceInit: boolean} | 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. | Returns null if the user doesnt brings access to the App Usage or an IAppUsage Array for the all used aplications. | | getAppsInstalled | Empty | Promise<IInstalledApps[]> | Returns an IInstalledApps Array for all the queries in AndroidManifest that user had install in his phone. | | openUsageAccessSettings | UsageSettings {ln: string, appDescription: string, appName: string, imagePath: string, modalText: string, dialogTitle: string, dialogMessage1: string, dialogMessage2: string, blacklist: Array[] | null | Boolean | Open settings view with a modal helper to grant app usage permission. | | openUsageAccessSettingsDirectly | blacklist: Array[] | null | Open settings view without pre-built modal to grant app usage permission. | | getManufacturer | Empty | Promise<{ manufacturer: string } | Get the device manufacturer |

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
    forceInit: boolean
 }
`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;
  }
  `openUsageAccessSettings params object`
  UsageSettings {
        ln: string,
        appDescription: string,
        appName: string,
        imagePath: string,
        modalText: string,
        dialogTitle: string,
        dialogMessage1: string,
        dialogMessage2: string,
        blacklist: [] | null,
        }

Example

Getting the installed apps

Recovery of applications installed on the user's device.

getAppsInstalled().then(data =>  console.log('Installed apps:', data));
//  expected output
  Installed Apps: [{"appName": "WhatsApp", "category": "Social", "icon": "iVBORw0KGgoAAAANSUhEUg", "installTime": "2023.02.15 20:07:35", "lastUpdateTime": "2023.08.16 14:52:12", "packageName": "com.whatsapp", "versionCode": "231676002", "versionName": "2.23.16.76"}]

General Information

⚠️ 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.

Terms of use

All content here is the property of Fivvy, it should not be used without their permission.