npm package: @sensfrx/sensfrx
Description: Sensfrx
Author: sensfrx
Latest version: 1.0.49

# Sensfrx React Native SDK

![Sensfrx Logo](https://sensfrx.ai/assets/image/footer-logo-white.png)

## Overview

Sensfrx React Native SDK is a comprehensive fraud detection solution tailored to secure mobile applications built with React Native. By collecting real-time device information and tracking user interactions, the SDK helps detect a wide range of fraudulent activities such as app cloning, network evasion, device rooting, and emulator-based attacks.

With AI-driven risk analysis and advanced behavioral analytics, Sensfrx SDK ensures that businesses can protect user accounts, prevent fake registrations, and reduce online transaction fraud. Its lightweight nature ensures minimal impact on app performance while providing strong protection against evolving security threats.

Sensfrx React Native SDK supports only Android platform and works seamlessly with your existing React Native applications.
[Know more about us](https://sensfrx.ai/?utm_source=npm&utm_medium=pflnk&utm_content=kmau)

## Configuration Requirements

- **React Native version:** 0.64+
- **Required Credentials:** Property ID and Property Secret from the Sensfrx Dashboard
- **Supported OS Version: Android:** Android 9.0+ (Pie)

---

## Installation

### Add SDK Dependency

### Step 1: Install Sensfrx SDK using npm or yarn:

```
npm install @sensfrx/sensfrx
or
yarn add @sensfrx/sensfrx
```

Note: Manual linking is not required.

The Sensfrx SDK supports React Native 0.64 and above, which uses autolinking. You do **not** need to run `react-native link`.

### Required Permissions (Optional)

For enhanced security features, request permissions where needed:

**Android:** INTERNET, ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION

---

## Configuration

### Step 2: Initialize the SDK

In your main application file (typically App.js or index.js), initialize the Sensfrx SDK.

To Get Your Property Secret

- Register on the [Sensfrx Dashboard](https://client.sensfrx.ai/?utm_source=npm&utm_medium=pflnk&utm_content=sd).
- After registration, log in to your dashboard.
- Generate your Property ID and Property Secret from the dashboard. These credentials are required to configure the SDK in your app.

#### sandboxMode Parameter

sandboxMode (boolean):

- true: Use this mode for testing. In sandbox mode, the SDK will simulate interactions and data without affecting your production environment.
- false: Set this mode to false when you are ready to deploy the app in a live production environment. This ensures the SDK works with real data and integrates with the live backend services.

```JS
import * as Sensfrx from '@sensfrx/sensfrx';

// Initialize the SDK with your Property ID and Property Secret
Sensfrx.configure({
  sandboxMode: false,  // Set to true for testing,
  propertySecret: 'PropertyID:Secret'
});

```

Make sure to replace `3764534847133568:VGF9TR2qfOnGCEghl` with the Property Secret you obtained from the [Sensfrx Dashboard](https://client.sensfrx.ai/?utm_source=npm&utm_medium=pflnk&utm_content=sd).

---

## Event Tracking

Sensfrx React Native SDK provides various mechanisms to track important events like user interactions, login attempts, registrations, and transactions.

### Click Events

Monitor user interactions with the app by tracking button clicks or any other view clicks. Click events help us read the behavioral data of users, providing insights into how users interact with different elements of your app.
Add this code to track click events on the screens.

```JS
import { TouchableOpacity } from 'react-native';
import * as Sensfrx from '@sensfrx/sensfrx';

 const handleTap = (event: GestureResponderEvent) => {
    Sensfrx.trackClickEvent(event); // full gesture event
  };

  return (
    <Pressable style={styles.container} onPress={handleTap}>
      <Text style={styles.title}>Sensfrx</Text>
      <Text style={styles.status}>.....</Text>
 );
    </Pressable>

```

### Track App State Events

Tracking the app's state allows you to monitor when your app is opened, closed, or moved to the background. This information is crucial for detecting unusual app usage patterns, improving user engagement, and strengthening security measures.

```JS
import * as Sensfrx from '@sensfrx/sensfrx';

Sensfrx.trackAppEvent('OPEN');  // When the app is launched
Sensfrx.trackAppEvent('BACKGROUND');  // When the app moves to background

```

### Screen Change Events

Tracking screen transitions allows you to monitor how users navigate through your app, helping you understand their behavior and detect potential fraud. Sensfrx automatically tracks screen changes and provides valuable insights into user journeys, such as how many screens a user visits and how long they stay on each.
Capture screen transitions:

- User Behavior Analysis: Understanding user navigation patterns allows us to identify normal and abnormal behavior, improving user experience and fraud detection.
- Fraud Detection: Unusual screen change patterns, such as rapid or unexpected transitions, could indicate suspicious activity or attempts to bypass security.

```JS
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import * as Sensfrx from '@sensfrx/sensfrx';

export default function App() {
  const navigationRef = useNavigationContainerRef();

  return (
    <NavigationContainer
      ref={navigationRef}
      onStateChange={() => {
        if (navigationRef) {
          Sensfrx.trackScreenChangeEvent(navigationRef);
        }
      }}
    >
      {/* Your navigators and screens */}
    </NavigationContainer>
  );
}

```

Note: Sensfrx.trackScreenChangeEvent(navigationRef) automatically extracts the current screen name and timestamp, so there's no need to manually provide screen details.

### Login Event

The Login Event is critical for tracking and protecting user logins. By monitoring login attempts and associated behaviors, Sensfrx can detect abnormal patterns that may indicate fraud, such as multiple failed login attempts, IP location changes, and device fingerprint mismatches.

Benefits of Tracking Login Events:

- Account Takeover (ATO) Detection: Identifies fraudulent login attempts and potential account takeovers.
- Fraud Prevention: Detects patterns indicative of credential stuffing, password spraying, or other automated attack techniques.
- Risk Analysis: Provides actionable insights into login behaviors and risks, improving security measures.

Implementation Example

```JS

// Create a login request and send it to your backend
import * as Sensfrx from '@sensfrx/sensfrx';

const loginEvent = (email, password) => {
  const loginData = {
     uex: {
      email: email,
      password: password,
    },
    package: 'com.yourapp',
    request_token: Sensfrx.getRequestToken(),
    d_f: Sensfrx.getDeviceFingerprints(),
  };
};

// You can also pass location for better accuracy or location-based detectors
Sensfrx.getRequestTokenWithLocation(latitude, longitude)
Sensfrx.getDeviceFingerprints(latitude, longitude)
```

For more details checkout the demo application or connect with our [support team](https://sensfrx.ai/contact-us?utm_source=npm&utm_medium=pflnk&utm_content=st).

### Registration Event Tracking

The Registration Event helps track new user registrations. This is essential for preventing fraudulent account creation, such as fake registrations or bot-driven sign-ups. By tracking registration behaviors, Sensfrx can detect suspicious activities like repeated sign-ups from the same IP address, unusual device fingerprints, or unverified user information.

Benefits of Tracking Registration Events:

- Fake Registration Detection: Identifies automated or bot-driven sign-ups that don't match typical user behavior.
- Fraud Prevention: Prevents fake account creation by detecting patterns such as multiple sign-ups with the same email or device fingerprint.
- Risk Analysis: Provides insights into registration behaviors, helping to prevent fraud and improve account security from the start.

Implementation Example

```JS
import * as Sensfrx from '@sensfrx/sensfrx';

const registrationEvent = (name, email, mobile, password) => {
  const registrationData = {
    rfs: {
      name: name,
      email: email,
      phone: mobile,
      password: password,
    },
    package: 'com.yourapp',
    request_token: Sensfrx.getRequestToken(),
    d_f: Sensfrx.getDeviceFingerprints(),
  };

};

// You can also pass location for better accuracy or location-based detectors
Sensfrx.getRequestTokenWithLocation(latitude, longitude)
Sensfrx.getDeviceFingerprints(latitude, longitude)
```

For more details checkout the demo application or connect with our [support team](https://sensfrx.ai/contact-us?utm_source=npm&utm_medium=pflnk&utm_content=st).

### Transaction Event Tracking

The Transaction Event provides insights into user purchases and financial transactions. By monitoring transaction data, Sensfrx can help detect suspicious activities like payment fraud, stolen credit cards, and transaction manipulation, ensuring secure and reliable financial interactions.

Benefits of Tracking Transaction Events:

- Payment Fraud Detection: Identifies abnormal transaction patterns such as high-value transactions, unusual payment methods, or frequent payment failures.
- Risk Management: Helps businesses assess transaction risks and detect compromised accounts or fraudulent payment methods.
- Transaction Integrity: Ensures that only legitimate purchases are processed, protecting both users and merchants from fraud.

```JS
import * as Sensfrx from '@sensfrx/sensfrx';

const transactionEvent = {
  transaction_id: "TXN123456",
  transaction_type: "purchase",
  email: "dummy@example.com",
  first_name: "John",
  last_name: "Doe",
  username: "john_doe123",
  payment_mode: "Credit Card",
  payment_provider: "Visa",
  card_fullname: "John Doe",
  card_bin: "411111",
  card_expire: "12/2026",
  card_last: "1234",
  cvv: "999",
  phone_no: "9998887777",
  transaction_amount: "1500",
  transaction_currency: "INR",
  items: [
    {
      item_id: "101",
      item_name: "Wireless Headphones",
      item_category: "Electronics",
      item_quantity: "1",
      item_price: "1200",
      item_url: "https://example.com/item101"
    },
    {
      item_id: "102",
      item_name: "USB-C Charger",
      item_category: "Accessories",
      item_quantity: "1",
      item_price: "300",
      item_url: "https://example.com/item102"
    }
  ],
  shipping_cost: "50",
  shipping_country: "India",
  shipping_state: "Maharashtra",
  shipping_city: "Mumbai",
  shipping_zip: "400001",
  shipping_phone: "9998887777",
  shipping_fullname: "John Doe",
  shipping_method: "Express",
  billing_country: "India",
  billing_state: "Maharashtra",
  billing_city: "Mumbai",
  billing_zip: "400001",
  billing_phone: "9998887777",
  merchant_name: "Gadget World",
  merchant_category: "Electronics",
  merchant_id: "M123456",
  merchant_country: "India",
  ev: "attempt_succeeded",
  card_type: "Visa",
  tax_amount: "100",
  discount_amount: "50",
  invoice_id: "INV98765",
  d_f: Sensfrx.getDeviceFingerprints(),
  request_token: Sensfrx.getRequestToken(),
  user_id: "user_987654"
};

// Track the transaction event
Sensfrx.trackTransactionEvent(transactionEvent);

// You can also pass location for better accuracy or location-based detectors
Sensfrx.getRequestTokenWithLocation(latitude, longitude)
Sensfrx.getDeviceFingerprints(latitude, longitude)

```

### Transaction Success/Failure Handling

After initiating the payment process with your payment SDK, you can track whether the transaction was successful or failed by utilizing Sensfrx.trackTransactionEvent in your onPaymentSuccess and onPaymentError methods. This helps in tracking the transaction's outcome and improves fraud detection.

```JS
// Called when payment is successful
const onPaymentSuccess = (transactionDetails) => {
  // Set the event to transaction_succeeded
  transactionDetails.ev = "transaction_succeeded";

  // Send the complete transaction details again with updated flag
  Sensfrx.trackTransactionEvent(transactionDetails);
};

// Called when payment fails
const onPaymentError = (errorCode, errorMessage, transactionDetails) => {
  // Set the event to transaction_failed
  transactionDetails.ev = "transaction_failed";

  // Send the complete transaction details again with updated flag
  Sensfrx.trackTransactionEvent(transactionDetails);
};

```

---

## Error Handling

To ensure smooth SDK integration, consider the following common issues:

- **Network Issues:** Ensure the app has internet access and is not blocked by firewalls.
- **Invalid Keys:** Verify the correct secret key.
- **Invalid Package:** Verify the correct package name.

Enable detailed logging using Android Studio Logcat for debugging.

---

## Analytics and Dashboard

After integrating Sensfrx into your app, you can view real-time fraud detection analytics, user behavior, and transaction logs directly on the Sensfrx Dashboard. This allows you to monitor suspicious activities and make data-driven decisions for fraud prevention.

Access your [Sensfrx Dashboard](https://client.sensfrx.ai/?utm_source=npm&utm_medium=pflnk&utm_content=sd)

---

## SDK Publication Details

- **Package Name:** @sensfrx/sensfrx
- **Version:** 1.0.47
- **Repository:** npm (https://www.npmjs.com/package/@sensfrx/sensfrx)
- **License:** Apache License 2.0
- **Project URL:** [https://sensfrx.ai](https://sensfrx.ai)

---

## Support

For assistance, contact our support team at [info@sensfrx.com](mailto:info@Sensfrx.com) or visit our developer portal.

## License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

<p>
  <a href="https://sensfrx.ai" target="_blank">
    <img src="https://forthebadge.com/images/badges/built-with-love.svg" alt="Built with Love">
    <img src="https://forthebadge.com/images/badges/built-for-android.svg" alt="Built for React Native">
  </a>
</p>