SDK Android

Last updated: August 30th, 2024

Introduction

The purpose of this manual is to provide all the necessary information for installing and using the tool in applications developed for the Android platform.

This SDK collects data (information and location) from the device and sends it to ClearSale. All collected information is related only to the device, with no relation to the integrated application.

The geolocation information depends on the permission granted by the device user, Geolocation in this case, it is necessary for the application to request access to the user's location information (the SDK does not request permission). If the application does not request access or the user does not grant permission for location, the GeoLocation information will not be captured.

The SDK respects Google's privacy policy for capturing device data and the level of permission granted by the user (device user).

The purpose of this manual is to provide all the necessary information for installing and using the tool in applications developed for the Android platform.

This SDK collects data from the device and sends it to ClearSale. All collected information is related only to the device, with no relation to the integrated application.

The SDK respects Google's privacy policy for capturing device data and the level of permission granted by the user (device user).

Checksum

Package Digest
sdk-behavior SHA256: 438240202C4248D0201149F376C5D2C776B81AE9F616317F07F67185F90BB997

To verify the checksum of dependencies in Gradle 6.2 or higher, follow the instructions at this link: Dependency Verification

Checksum

Package Digest
sdk-behavior SHA256: ABCCC91058E7005BC7B47A3A242E77575B0086224D18E9C75E85B0AE0ED1C54D

To verify the checksum of dependencies in Gradle 7.0 or higher, follow the instructions at this link: Dependency Verification

Checksum

Package Digest
sdk-behavior SHA256: F67C436798EFAB2C50446090B39101C75217D724B654713AA8758CF498B51687

To verify the checksum of dependencies in Gradle 7.0 or higher, follow the instructions at this link: Dependency Verification

Checksum

Package Digest
sdk-behavior SHA256: 9E55E1A8C668B028481C891ECAB4186281CD725F1BC7700D1E82939D9BA6C433

Para verificar o checksum das dependencias no Gradle 7.0 ou superior, siga as instruções desse link: Dependency Verification

Version Upgrade

Version Upgrade

To upgrade from version 3.0.2 to version 6.x.x or higher, follow these steps:

  1. Remove the dependency com.google.code.gson:gson if it is not used in your project.
  2. Replace the plugin play-services-ads with the plugin play-services-ads-identifier:18.0.1.
  3. Update the version of the plugin play-services-location to version 21.0.1.
Package Installation

Package Installation

  • Gradle (We recommend using Gradle 7.0.2 or higher)

The package is available in a private repository. To use it, you need to add the following repository to the root file:


maven {
    url 'https://pkgs.dev.azure.com/CS-PublicPackages/Behavior/_packaging/BehaviorAnalytics.SDK/maven/v1'
    name 'BehaviorAnalytics.SDK.Android'
}

Package Installation

  • Gradle (We recommend using Gradle 6.2 or higher)

The package is available in a private repository. To use it, you need to add the following repository to the root file:


maven {
    url 'https://pkgs.dev.azure.com/CS-PublicPackages/Behavior/_packaging/BehaviorAnalytics.SDK/maven/v1'
    name 'BehaviorAnalytics.SDK.Android'
}

Project Configuration

You need to use the following dependencies in your project:

  • play-services-ads-identifier

To do this, in the dependencies section, add the following information to your project's Gradle file:


dependencies {
// Other project dependencies.
//...

// Required Dependencies:
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation 'sale.clear.behavior:sdk-behavior:7.0.0'
}
    

Project Configuration

You need to use the following dependencies in your project:

  • play-services-location
  • play-services-ads-identifier

To do this, in the dependencies section, add the following information to your project's Gradle file:


dependencies {
// Other project dependencies.
//...

// Required Dependencies:
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation 'sale.clear.behavior:sdk-behavior:6.0.8'
api 'com.google.android.gms:play-services-location:21.0.1'
}
    

dependencies {
// Other project dependencies.
//...

// Required Dependencies:
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation 'sale.clear.behavior:sdk-behavior:6.0.0'
api 'com.google.android.gms:play-services-location:21.0.1'
}       

Project Configuration

You need to use the following dependencies in your project:

  • play-services-location
  • play-services-ads
  • gson

To do this, in the dependencies section, add the following information to your project's Gradle file:


dependencies {
// Other project dependencies.
//...

// Required Dependencies:
implementation 'com.google.android.gms:play-services-ads:18.3.0'
api 'com.google.code.gson:gson:2.8.6'
implementation 'sale.clear.behavior:sdk-behavior:3.0.2'

// Optional Dependencies:
api 'com.google.android.gms:play-services-location:17.0.0'
}           

Learn more:

The optional dependency 'com.google.android.gms:play-services-location:17.0.0' should be used whenever it is necessary to collect geolocation information.

Learn more:

  • The dependency 'com.google.android.gms:play-services-ads-identifier:18.0.1' is used to obtain the device's advertising identifier information.
  • The dependency 'com.google.android.gms:play-services-location:21.0.1' should be used whenever it is necessary to collect geolocation information from the device.

Learn more:

  • The dependency 'com.google.android.gms:play-services-ads-identifier:18.0.1' is used to obtain the device's advertising identifier information.

Proguard

Include this rule if you are using Proguard:

-keep class sale.clear.behavior.** { *; }

App Permissions

To use the SDK, it is necessary to request some permissions in the manifest file. They are:


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

Attention: For applications targeting version 26 or higher of Android, and that wish to capture geolocation information, it is necessary, in addition to adding the permissions ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION in the manifest, to also request user permission to collect geolocation data. To do this, follow this Android recommendation.

For applications targeting version 33 (Android 13) or higher, it will be necessary to include the AD_ID permission to capture information related to the advertisingID.

App Permissions

To use the SDK, it is necessary to request some permissions in the manifest file. They are:


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

For applications targeting version 33 (Android 13) or higher, it will be necessary to include the AD_ID permission to capture information related to the advertisingID.

Privacy

Play Store Privacy

If the user has consented to the collection of geolocation and the list of applications, the methods allowGeoLocation() allowAppList() should be called before the start() method, as shown in the example below:


@Override
public void onResume() {
super.onResume();
try {
    mBehavior.allowGeoLocation(); // Enables geolocation capture
    mBehavior.allowAppList(); //Enables the capture of information from applications installed on the device
    mBehavior.start(); //Initialization of information capture.
        
        String sessionId = mBehavior.generateSessionID();

        //Only on screens where you want to send the collected data to ClearSale
        mBehavior.collectDeviceInformation(sessionId); //Preferably after some user interaction time.
}
catch (CaptureWasStartedException e) {
        //This error occurs when the start() method was called more than once without using the stop() method.
        //Each capture (which starts with the start method) needs to be ended (with the stop method call)
    }
}
        

Behavior Class

Behavior is the class responsible for collecting information.

Constructors: this class does not have public constructors. The instance must be created through a static method.


  • Static Method
Method Name Description
Behavior.getInstance(String app, Integer consentFlags) :Behavior Gets the instance of the Behavior class for an AppKey.
It is necessary to pass the AppKey (value provided by ClearSale) as a parameter. It is necessary to pass the Flags parameter indicating if the user consented to the collection of sensitive information.
  • Other Methods
Method Name Description
start() :void Starts collecting information about the device and the screen.
Exceptions:
  • CaptureWasStartedException - thrown when a previous capture was not stopped.
generateSessionID() :String Generates and returns a session identifier.
This value must be stored and sent to ClearSale at the time of order integration (it is the parameter used in the collectDeviceInformation method call).
collectDeviceInformation(String sessionID) :void Collects device information linking it to the Session value.
It is necessary to pass the SessionId as a parameter (this value must be unique per session).
(*) If you do not have a value, use the method. generateSessionID().
(**) The minimum length of the SessionID to be used is 6 characters and the maximum length is 128 characters.
Exceptions:
  • SessionIDAlreadyUsedException - thrown when the same session value is used more than once.
stop() :void Ends the data capture process.
allowAppList() :void Allows the collection of information about the apps installed on the device.
allowGeoLocation() :void Allows the collection of geolocation.
sendEvent(UserEventType eventType, String sessionID) :void Allows sending user events to the event manager, identifying the event type and user session (beta version).
Examples

Examples

There are two ways to initialize the SDK. This depends on the type of screen that will be used. If the screen is an Activity, initialization should be done in the onCreate() method. If it is a Fragment, initialization should be done in the onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) method.

Note: In both cases (Activity or Fragment), if the stop() method is not called within the onStop() method of one of the screens, since it is a singleton, the next screen when start() is called will throw the exception CaptureWasStartedException.

In all examples, the following variables are assumed to exist:

  • mBehavior which represents the instance of the Behavior class. It can be replaced by Behavior.getInstance(context, CLEAR_SALE_APP).
  • CLEAR_SALE_APP a string variable, the value of this variable must be provided by ClearSale.

To initialize the call when the screen is a Fragment.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
    // To get the Context in a Fragment.
    View rootView = inflater.inflate(R.layout.fragment_login, container, false);
    Context context = rootView.getContext();
    //CLEAR_SALE_APP is a unique identification value that must be provided by ClearSale.
    mBehavior = Behavior.getInstance(context, CLEAR_SALE_APP);
    return rootView;
}

When the screen is an Activity
@Override
public void onCreate() {
    //CLEAR_SALE_APP is a unique identification value that must be provided by ClearSale.
    mBehavior = Behavior.getInstance(this, CLEAR_SALE_APP);
}

To start the capture:

@Override
public void onResume() {
    super.onResume();
    try {
        mBehavior.start(); //Initialization of information capture.
        String sessionId = mBehavior.generateSessionID();
        //Only on screens where you want to send the collected data to ClearSale
        mBehavior.collectDeviceInformation(sessionId); //Preferably after some user interaction time.
    } catch (CaptureWasStartedException e) {
        //This indicates that the mBehavior.start() method has already been called previously and
        //the collection was not properly finalized using the mBehavior.stop() method.
    } catch (SessionIDAlreadyUsedException e) {
        //The same sessionId was used previously. The SessionID must be unique per collection.
    }
}

The methods start() and stop() should be implemented only on the screen where the information capture will be performed. The collectDeviceInformation(SESSION_ID) method should be called when you want to send the collected information to ClearSale, on the same screen where the previous methods were implemented.

Note: The collectDeviceInformation method must be called after the start() method has been executed.

We recommend that these methods be implemented on a "finalization" screen where there is user interaction for at least 3 seconds.

To end the capture:
@Override
public void onStop() {
    super.onStop();
    mBehavior.stop(); //Finalization of information capture.
}                         

Complete implementation example:

public class ExampleImplementationActivity extends AppCompatActivity {

    private Behavior mBehavior;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //CLEAR_SALE_APP is a unique identification value that must be provided by ClearSale.
        mBehavior = Behavior.getInstance(this, "CLEAR_SALE_APP");
    }

    @Override
    public void onResume() {
        super.onResume();
        try {
            mBehavior.start(); //Initialization of information capture.
            String sessionId = mBehavior.generateSessionID();

            //Only on the screen where you want to send the collected data to ClearSale
            mBehavior.collectDeviceInformation(sessionId); //Preferably after some user interaction time.
        } catch (CaptureWasStartedException e) {
            //This indicates that the mBehavior.start() method has already been called previously and
            //the collection was not properly finalized using the mBehavior.stop() method.
        } catch (SessionIDAlreadyUsedException e) {
            //The same sessionId was used previously. The SessionID must be unique per collection.
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        mBehavior.stop(); //Finalization of information capture.
    }
}
Example Project

Example Project

You can view the SDK implementation in an example project by clicking here.

FAQ

FAQ

Click here to access our FAQ

Privacy Details

Data usage

All information collected by ClearSale's SDK are exclusively for the purpose of fraud prevention and user protection, adherent to the security and privacy policies of Google and Apple platfoms and the LGPD. Therefore, this information must be in the application privacy policy.

Data Type Collected

ClearSale's SDK collects the following device information:

  • Precise location (when allowed by user);
  • Device advertising identification (when allowed by user);
  • Device physical/hardware characteristics (such as display, battery, keyboard, disk space, model, device name);
  • Device software characteristics (such as version, language, build, parental control);
  • Network information (such as connections, IP);
  • SimCard carrier.

Google Privacy Policy
Apple Privacy Policy
License

Use License

By downloading and using our SDK you are agreeing to the following license.

Copyright © 2024 ClearSale

All rights are reserved, permission is granted to use the software as is, and no modification or copying for any purpose is permitted. The Software is licensed in its current configuration “as is” and without warranty of any kind, either express or implied, including, but not limited to, warranties of merchantability, fitness for a particular purpose and non-infringement of patented rights. Under no circumstances may the Copyright holders be held liable for damages, losses, causes of action, whether in contract or tort, or other tortious action arising from the use of the Software or other actions related to this Software without the prior written authorization of the Copyright holder.