Android
The SDK is available as an AAR (recommended) and JAR library. The library is available in the MavenCentral and GitHub repository.
Attention!
From the SDK version
com.devtodev:android-analytics:'2.2.3'
and above you need to add com.devtodev:android-google:'1.0.0'.
In the Project
build.gradle
file, declare the mavenCentral
repository:repositories {
//.. other repositories
mavenCentral()
}
If you use Gradle for building apps specify the following dependencies in the application
build.gradle
file. dependencies {
// Requirement
implementation 'com.google.code.gson:gson:*.*.*'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:*.*.*'
implementation 'com.google.android.gms:play-services-base:*.*.*'
implementation 'com.google.android.gms:play-services-ads-identifier:*.*.*'
// Starting from version 2.2.3 and above, it is required
implementation 'com.devtodev:android-google:*.*.*'
// if you use AAR (recommended) or JAR downloaded from GitHub, please add:
implementation fileTree(dir: "libs", include: ["*.aar"])
// or just add the dependency, get the latest version from
// https://mvnrepository.com/artifact/com.devtodev/android-analytics
implementation 'com.devtodev:android-analytics:*.*.*'
// Optional (recommended)
implementation 'com.android.installreferrer:installreferrer:*.*.*'
}
If you use Gradle for compiling apps, declare the following dependencies in the build.gradle file in the dependency block:
repositories {
//.. other repositories
mavenCentral()
maven { url 'https://developer.huawei.com/repo/' }
}
allprojects {
repositories {
//.. other repositories
mavenCentral()
// Configure the Maven repository address for the HMS Core SDK.
maven {url 'https://developer.huawei.com/repo/'}
}
}
In the Project
build.gradle
file declare the agconnect plugindependencies {
classpath 'com.huawei.agconnect:agcp:*.*.*'
}
In the application build.gradle file declare the following dependencies:
dependencies {
// Requirement
implementation 'com.google.code.gson:gson:*.*.*'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:*.*.*'
implementation 'com.huawei.agconnect:agconnect-core:*.*.*'
implementation 'com.huawei.hms:ads-identifier:*.*.*'
implementation 'com.huawei.hms:opendevice:*.*.*'
// Starting from version 2.2.3 and above, it is required
implementation 'com.devtodev.android-huawei:*.*.*'
// if you use AAR (recommended) or JAR downloaded from GitHub, please add:
implementation fileTree(dir: "libs", include: ["*.aar"])
// or just add the dependency, get the latest version from
// https://mvnrepository.com/artifact/com.devtodev/android-analytics
implementation 'com.devtodev:android-analytics:*.*.*'
}
And add a plugin:
plugins {
//.. other plugins
id 'com.huawei.agconnect'
}
After taking all the steps described above, open the ‘App information’ section and download agconnect-services.json. You need to place this file in the app folder (read more).
Use the following way to initialize the library in the first Activity
onCreate()
method:Kotlin
Java
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val analyticsConfiguration = DTDAnalyticsConfiguration()
analyticsConfiguration.logLevel = DTDLogLevel.Error
DTDAnalytics.initialize("appKey", analyticsConfiguration, context)
}
}
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DTDAnalyticsConfiguration configuration = new DTDAnalyticsConfiguration();
configuration.setLogLevel(DTDLogLevel.Error);
DTDAnalytics.INSTANCE.initialize("App ID", configuration, context);
}
}
- You can find the App ID in the settings of the respective app in devtodev (Settings → SDK → Integration → Credentials).
config
- is aDTDAnalyticsConfiguration
object instance that is used for specifying additional properties during initialization.
DTDAnalyticsConfiguration
Parameter | Type | Description |
currentLevel | Integer | The player level at the moment of devtodev SDK initialization. It’s optional but we recommend using it for improving data accuracy. |
userId | String | A custom user ID assigned by the developer. In the case of default calculation by device IDs, the identifier can be used for searching users in devtodev. In case the project uses calculation by user IDs, the parameter is mandatory because it becomes the principal calculation ID in devtodev. |
trackingAvailability | DTDTrackingStatus (enum) | The property allows or disallows devtodev tracking of the user. By default, it is set to DTDTrackingStatus.enable . SDK stores the previously assigned value. Pass DTDTrackingStatus.disable if the user opted out of tracking in line with GDPR. |
logLevel | DTDLogLevel (enum) | The level of logging the SDK activity. The DTDLogLevel.no value is used by default. For troubleshooting during integration it is recommended to set it to DTDLogLevel.debug , and either switch it off DTDLogLevel.no . Use DTDLogLevel.no in the release version. |
Example:
Kotlin
Java
val config = DTDAnalyticsConfiguration()
config.currentLevel = 1
config.userId = "CustomUserID"
config.trackingAvailability = DTDTrackingStatus.Enable
config.logLevel = DTDLogLevel.No
DTDAnalytics.initialize("appKey", config, context)
DTDAnalyticsConfiguration config = new DTDAnalyticsConfiguration();
config.setCurrentLevel(1);
config.setUserId("CustomUserID");
config.setTrackingAvailability(DTDTrackingStatus.Enable);
config.setLogLevel(DTDLogLevel.No);
DTDAnalytics.INSTANCE.initialize("appKey", config, context);
Add the following strings to the
proguard-rules.pro
file of your app-keep class com.devtodev.** { *; }
-dontwarn com.devtodev.**
// For Google Mobile Services
-keep class com.google.android.gms.** { *; }
// For Huawei Mobile Services
-keep class com.huawei.hms.**{*;}
When developing and publishing apps targeted at children under 13 years old, you need to ensure special conditions for data processing. Any mobile app aimed at children or intended for users in a region with strict regulations on child online protection, must comply with current laws.
Please study the following requirements:
If your app has to comply with the legal requirements (COPPA), use the following recommendations:
- 1.Implement the
coppaControlEnable
method. The method disables collection of ad IDs and vendor IDs. - 2.If your app is using Google services, remove the following dependencies from gradle:'com.google.android.gms:play-services-ads-identifier''com.devtodev:android-google'
- 3.If your app is using Huawei services, remove the following dependencies from gradle:'com.huawei.hms:ads-identifier''com.huawei.hms:opendevice''com.devtodev.android-huawei'
Call the
coppaControlEnable
method before SDK initialization. If the method was not called, the SDK will work as before.Kotlin
Java
DTDAnalytics.coppaControlEnable()
DTDAnalytics.initialize("appKey", config, context)
DTDAnalytics.INSTANCE.coppaControlEnable();
DTDAnalytics.INSTANCE.initialize("appKey", config, context);
Last modified 2mo ago