The purpose of this manual is to provide all the necessary information for the installation and use of the tool in applications developed for the React Native platform.
This Plugin collects data (information and location) from the device and sends it to ClearSale. All collected information is related only to the device, without any relation to the integrated application.
The geolocation information depends on the permission granted by the user of the device, in this case is necessary that the application requests the access of the user location information (the SDK doesn't requests permission). If the application doesn't request the access or the user doesn't grant permission, for location, the GeoLocation information will not be captured.
The Plugin respects Apple and Google's privacy policies for capturing device data and the permission level assigned by the user (device user).
Package | Digest |
---|---|
clear.sale/behavior-analytics-react-native-sdk | sha1-6VAoJWwE2O4R28Z30FtagJOu/jY= |
To check the checksum of the artifact check the package.json.lock, after executing the command npm install in your project.
Package | Digest |
---|---|
clear.sale/behavior-analytics-react-native-sdk | sha1-e3lWDWX5cE43JPQc/riruiX4sDg= |
To check the checksum of the artifact check the package.json.lock, after executing the command npm install in your project.
Package | Digest |
---|---|
clear.sale/behavior-analytics-react-native-sdk | sha1-NjDR2LR86fxl7Wg5tJyt3CSN0MA= |
To check the checksum of the artifact check the package.json.lock, after executing the command npm install in your project.
- Node >= 10.19.0
- React Native >= 0.63.2
- Node >= 20.11.1
- React Native >= 0.73.4
If you have an active installation with the .npmrc configured, it will be necessary to:
The package is available in a public repository, and for its use follow the example bellow:
Npm:
npm install @clear.sale/behavior-analytics-react-native-sdk@2.5.2
Yarn:
yarn add @clear.sale/behavior-analytics-react-native-sdk@2.5.2
The package is available in a private repository, and for its use follow the example bellow:
1. Add your project in a .npmrc file in the same directory where the package.json is located.
2. In the .npmrc include the following snippet:
@clear.sale:registry=https://pkgs.dev.azure.com/CS-PublicPackages/Behavior/_packaging/BehaviorAnalytics.SDK/npm/registry
always-auth=true
3. Add ClearSale's SDK React Native to your installation, as per example:
"dependencies": {
"@clear.sale/behavior-analytics-react-native-sdk": "1.0.1-rc.2",
...
},
4. Execute the command npm install.
Npm:
npm install @clear.sale/behavior-analytics-react-native-sdk@1.0.1-rc.2
Yarn:
yarn add @clear.sale/behavior-analytics-react-native-sdk@1.0.1-rc.2
It's necessary to add the SDK repository to the project's build.gradle file.
maven {
url 'https://pkgs.dev.azure.com/CS-PublicPackages/Behavior/_packaging/BehaviorAnalytics.SDK/maven/v1'
name 'BehaviorAnalytics.SDK.Android'
}
It will also be necessary to use the following dependencies in your project: play-services-location, play-services-ads-identifier. To do this, add the following information to your project's Gradle file, in the dependencies section.
dependencies {
// Other dependencies of your project.
//...
// Required dependencies:
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
implementation 'sale.clear.behavior:sdk-behavior:5.6.7'
api 'com.google.android.gms:play-services-location:21.0.1'
}
dependencies {
// Other dependencies of your project.
//...
// 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'
}
The dependency 'com.google.android.gms:play-services-ads-identifier:18.0.1' is used to obtain information about the device's advertising identifier.
On the other hand, 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.
To use the SDK 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"/>
For applications that use Android version 26 or above as Target, and wishes to capture geolocation information, it's necessary, in addition to adding the ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions to the manifest, to request permission from the user to collect geolocation data, following this Android recommendation.
Note: For applications that uses version 33 (Android 13) or above as Target be able to capture information regarding advertisingID, it will be necessary to include the permission below:
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
In the app's build.gradle file, add the code to enable the multidex.
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
In the app's class MainActivity.java add the method to enable the multidex in Android versions previous to 5.0.
First import the multidex:
import android.content.Context;
import androidx.multidex.MultiDex;
After add the method inside the class:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
In the class MainApplication.java import:
import androidx.multidex.MultiDexApplication;
After change the inheritance from Application to MultiDexApplication.
To learn morem, check out the documentations:
Configuration.
Add the ClearSale's native iOS library in your project pod:
source 'https://dev.azure.com/CS-PublicPackages/Behavior/_git/BehaviorAnalytics.SDK.IOS.Specs'
target 'PROJECT_NAME' do
pod 'CSBehavior', '3.0.1'
end
source 'https://dev.azure.com/CS-PublicPackages/Behavior/_git/BehaviorAnalytics.SDK.IOS.Specs'
target 'PROJECT_NAME' do
...
While in your project's pod add the following option in post_install:
post_install |installer|
...
installer.pods_project.targets.each do |t|
t.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
Inside the project folder, access the folder ios and execute the command pod install:
pod install
Case the error Error: EMFILE: too many open files - React Native CLI is shown, install the watchman.
Execute the following commands on the command prompt:
brew update
$ brew install watchman
Add the following option on your plist and after in the xcode Menu Build -> Clean and Build Folder.
<dict>
<key>NSAllowsArbitraryLoads</key>
<true />
<key>NSExceptionDomains</key>
<dict>
<key>clearsale.com.br</key>
<dict>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
</dict>
</dict>
</dict>
Provides all methods that communicate with the SDK, all methods return a Promise.
Method name | Plataform | Description |
---|---|---|
Promise<String> generateSessionId(appKey) | Android / iOS | Generates and returns a session identifier. This method should only be used if the application does not generate unique identifiers for each collection. |
Promise<void> collectDeviceInformation(appKey, sessionId) | Android / iOS |
Collects device information by linking it to the Session value. It is necessary to pass the SessionId, session value, as a parameter.
Notes:
|
Promise<void> start(appKey, success, failure) | Android | Starts collecting device and screen information, Exception: CaptureWasStartedException - thrown when a previous capture was not stopped. |
Promise<void> stop(appKey, sessionId, success, failure) | Android | Ends the data capture process. |
Promise<void> allowAppList() | Android | Activates the collection of information about the applications installed on the device. |
Promise<void> allowGeoLocation() | Android | Activates the collection of geolocation. |
Plugin usage example
import ClearSaleModule from 'behavior-analytics-react-native-sdk'
Using the methods start and stop suring the component lifecycle (React Hooks):
useEffect(() => {
if (Platform.OS === 'android') {
...
ClearSaleModule.start(appKey)
ClearSaleModule.allowAppList()
ClearSaleModule.allowGeoLocation()
return () => {
...
ClearSaleModule.stop(appKey)
}
}
}, [])
To utilize the generateSessionId and collectDeviceInformation funcions is necessary that the method start() has been executed.
If the method start has been executed without the stop method execution, it will be thrown a CaptureWasStartedException exception.
Method generateSessionId returns the sessionId.
const loadPage = async () => {
...
await verifyLocationPermissions()
const sessionId = await ClearSaleModule.generateSessionId(state.token)
setState({
...state,
sessionId: sessionId
})
...
}
Method collectDeviceInformation starts the data collection with an existing sessionId.
useFocusEffect(
React.useCallback(() => {
loadPage()
return () => {
unloadPage()
};
}, [])
);
const loadPage = async () => {
ClearSaleModule.collectDeviceInformation(state.token, state.sessionId).then(() => {
console.log('id com sucesso', state.sessionId)
setLoading(false)
setSend(true)
}).catch(() => {
setLoading(false)
setSend(false)
})
}
const getSessionId = () => {
ClearSaleModule.generateSessionId(appKey).then(sessionId => {
...
setSessionId(sessionId)
}).catch(err => {
...
})
}
It's possible to visualize the SDK implementation in a example project clicking here.
npm uninstall @clear.sale/behavior-analytics-react-native-sdk
npm uninstall @clear.sale/behavior-analytics-react-native-sdk
yarn remove @clear.sale/behavior-analytics-react-native-sdk
yarn remove @clear.sale/behavior-analytics-react-native-sdk
Click here to access our FAQ
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.
ClearSale's SDK collects the following device information:
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 tortuous action arising from the use of the Software or other actions related to this Software without the prior written authorization of the Copyright holder.