Skip to content

ghas-results/data-collector-sdk-android

 
 

Repository files navigation

DataCollector Android SDK

The DataCollector SDK collects and sends device information to improve fraud detection accuracy, and identify devices. Lightweight library with only 134KB AAR file size.

Table of Contents

  1. Requirements
  2. App permissions
  3. Installation
  4. How to use
  5. Testing the integration
  6. Java Example
  7. Sample App
  8. Cross-platform frameworks
  9. Report Issues
  10. License

Requirements

  • Android Studio 4.1+
  • Supports API versions from 21 and higher.

App permissions

android.permission.INTERNET (Optional)
android.permission.ACCESS_WIFI_STATE (Optional)
android.permission.ACCESS_NETWORK_STATE (Optional)

Installation

New releases of the DataCollector Android SDK are published via Maven Repository. The latest version is available via mavenCentral().

Add mavenCentral() to the project level build.gradle file's repositories section, if you don't have it already:

repositories {
    mavenCentral()
    ...
}

Add DataCollector SDK dependency to the application's build.gradle file:

dependencies {
    ...
    implementation 'com.dlocal.android:data-collector:1.0.3'
    ...
}

How to use

1) Configure SDK

Create an Application file if you haven't already and initialize the sdk calling setUp method and passing your API key:

import com.dlocal.datacollector.DLCollector
import com.dlocal.datacollector.api.DLSettings

class MainApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        // Setup for DLocal Data Collector SDK
        DLCollector.setUp(this, DLSettings("API KEY"))
    }
}

Optionally you can configure the environment and the desired log level in the attributes of the DLSettings object:

import com.dlocal.datacollector.DLCollector
import com.dlocal.datacollector.api.DLEnvironment
import com.dlocal.datacollector.api.DLLogLevel
import com.dlocal.datacollector.api.DLSettings

class MainApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        val settings = DLSettings(
            apiKey = "API KEY",
            environment = DLEnvironment.SANDBOX,
            logLevel = DLLogLevel.VERBOSE
        )
        DLCollector.setUp(this, settings)
    }
}

Replacing apiKey with your key.

See the SampleApplication for a detailed example.

2) Start Session

Start session will gather device information, and generate a sessionId.

This step can be done any time, but it's recommended to call it as soon as a session is present in your application state.:

DLCollector.startSession()

You can also associate additional data related to each session to improve the fraud prevention score. The following example shows how to pass the user reference ID inside DLAdditionalData object.

val additionalData = DLAdditionalData(userReference = "user-id")
DLCollector.startSession(additionalData)

NOTE: This method runs in a background thread and doesn't block the main thread.

See the SampleApp SampleActivity for a detailed example.

3) Link the session to the transaction

When the user starts the checkout transaction, gather the session id like so:

val sessionId: String? = DLCollector.getSessionId()

Submit this value in the payment request within the additional_risk_data.device.event_uuid parameter. The method can return null if a session is not available or an error occurred.

Testing the integration

Once integrated, you can use the DLLogLevel.VERBOSE log level to see if the SDK is working. This can be done by changing the setup settings like so:

val settings = DLSettings(apiKey = "SBX API KEY", environment = DLEnvironment.SANDBOX, logLevel = DLLogLevel.VERBOSE)

And looking at the console, when startSession is run, we should see the following logs if everything is working:

I/DLDataCollector [SANDBOX]: Collected 57 data points in 646 milliseconds
I/DLDataCollector [SANDBOX]: POST success with sessionId 177eb063-bf2d-4247-8db2-66b87409419e

Switching environments

We strongly recommend that you use the SANDBOX environment when testing, and only use PRODUCTION in production ready builds.

To do so, you can use the setup and DLCollectorSettings to configure a different environment, i.e:

val settings = if (BuildConfig.DEBUG) {
    DLSettings(
        apiKey = "SBX API KEY",
        environment = DLEnvironment.SANDBOX,
        logLevel = DLLogLevel.VERBOSE
    )
} else {
    DLSettings(
        apiKey = "PROD API KEY",
        environment = DLEnvironment.PRODUCTION,
        logLevel = DLLogLevel.SILENT
    )
}

Replacing the apiKey with yours for each environment.

Java Examples

You can use the SDK from Java due to the interoperability between Java and Kotlin, checkout the sample app's Java examples.

Sample App

In this repository there's a sample app to showcase how to use the SDK, please refer to the code for more detailed examples.

Cross-platform frameworks

This SDK can be included in any native app, we also made available the following plugins for cross-platform frameworks:

Report Issues

If you have a problem or find an issue with the SDK please contact us at mobile-dev@dlocal.com.

License

    MIT License

    Copyright (c) 2022 DLOCAL

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 57.5%
  • Java 42.5%