Legacy — Vanilla
How to install and configure the Sophonz Android Vanilla SDK v1.1.
TIP — Add project > Add app > Obtain key
Log in to the Sophonz console, add a project under Project Management, then add an app to it with Add App. Take the issued app key from App Management, and install using the registered project name and app key.
Sophonz Android Vanilla SDK Requirements
| Item | Requirement |
|---|---|
| Java version | 1.8 or higher |
| min SDK | 19 or higher |
| Support Language | Java, Kotlin |
Installing the Sophonz Android Vanilla SDK
The Sophonz SDK is designed to collect runtime data from your application. Follow the steps below to install it.
1. Gradle Configuration
1-1. Direct AAR installation
Create a libs directory under your application directory, copy the sophonz-vanilla-android-sdk-version-release.aar file into it, then add the Sophonz SDK to the dependencies section.
Groovy DSL
dependencies {
implementation files('libs/sophonz-vanilla-android-sdk-1.1.0-release.aar')
}Kotlin DSL
dependencies {
implementation(files("libs/sophonz-vanilla-android-sdk-1.1.0-release.aar"))
}2. Application Class Setup
The Sophonz SDK is initialized inside the Application class. Add the initialization code to the onCreate() method of your Application class.
- Register the Application class
Set the
android:nameattribute in yourAndroidManifest.xmlto point to yourApplicationclass. Skip this step if anApplicationclass already exists.
<application
android:name=".Application"
...
>
</application>- Write the SDK initialization code
Add the following code to the
onCreate()method of yourApplicationclass:
Kotlin
import com.sophonz.android.sdk.core.Sophonz
import com.sophonz.android.sdk.core.SophonzOption
import com.sophonz.android.sdk.core.SophonzOption.Environment
//import com.sophonz.android.sdk.core.SophonzOption.DeviceIdType
class Application : android.app.Application() {
override fun onCreate() {
super.onCreate()
val options = SophonzOption()
options.setDefault()
options.setCollectorURL("Enter the collector URL here.")
options.setAppKey("Enter the app key here.")
options.setSampleRate("Enter a sampling rate (0.0–1.0).") // default=1.0
options.setProject("Namespace")
//options.setRemoteCollectionControlEnable(true)
//options.setEnvironment(Environment.DEVELOPMENT)
//options.setUserEventEnable(true)
//options.setDeviceIdType(DeviceIdType.UUID)
Sophonz.setup(options)
Sophonz.initialize(this.applicationContext, this)
}
}Java
import com.sophonz.android.sdk.core.Sophonz;
import com.sophonz.android.sdk.core.SophonzOption;
import com.sophonz.android.sdk.core.SophonzOption.Environment;
//import com.sophonz.android.sdk.core.SophonzOption.DeviceIdType;
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
SophonzOption options = new SophonzOption();
options.setDefault();
options.setCollectorURL("Enter the collector URL here.");
options.setAppKey("Enter the app key here.");
options.setSampleRate("Enter a sampling rate (0.0–1.0)."); // default=1.0
options.setProject("Namespace");
//options.setRemoteCollectionControlEnable(true);
//options.setEnvironment(Environment.DEVELOPMENT);
//options.setUserEventEnable(true);
//options.setDeviceIdType(DeviceIdType.UUID);
Sophonz.setup(options);
Sophonz.initialize(this.getApplicationContext(), this);
}
}setCollectorURL: URL of the server that collects data.setAppKey: The app key issued from the console.
(Settings > App Management > App Key)- (optional)
setSampleRate: Sampling rate. Default is 1.0 (100%).- Accepts a value between 0.0 and 1.0. (0.0: no collection, 1.0: 100% collection)
setProject: The namespace entered when adding the project in the dashboard.
(Project Management > Project Name) or (App Management > Project)- (optional)
setEnvironment: Deployment environment (default: .PRODUCTION) - (optional)
setUserEventEnable: Auto click event collection for XML UI (default=false) - (optional)
setRemoteCollectionControlEnable: Enable remote collection control (default=false)- The SDK applies server-side settings delivered via API.
- On/Off (default=on)
- Auto-stop policy on transmission failure (default=false)
- Failure count threshold for auto-stop policy (default=5)
- (optional)
setDeviceIdType: Device ID type setting (default=ANDROID_ID)- ANDROID_ID: Android system identifier (SSAID)
- UUID: Random identifier generated internally by the SDK (regenerated after app reinstall)
3. HTTPS Configuration
- HttpClient Setup
To collect XHR data from HttpClient, configure setSophonzInterceptor.
Kotlin
import com.sophonz.android.sdk.network.httpclient.HttpClientInterceptor;
...
// Add HttpClientInterceptor to DefaultHttpClient
val httpClient : DefaultHttpClient = DefaultHttpClient()
HttpClientInterceptor.setSophonzInterceptor(httpClient)
...Java
import com.sophonz.android.sdk.network.httpclient.HttpClientInterceptor;
...
// Add HttpClientInterceptor to DefaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpClientInterceptor.setSophonzInterceptor(httpClient);
...- Retrofit / OkHttp
To collect XHR data from Retrofit or OkHttp network requests, add HttpInterceptor as shown below.
Kotlin
import com.sophonz.android.sdk.network.okhttp.HttpInterceptor;
...
val client = OkHttpClient.Builder()
.addInterceptor(HttpInterceptor()) // add
.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
...Java
import com.sophonz.android.sdk.network.okhttp.HttpInterceptor;
...
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HttpInterceptor()) // add
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.example.com/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
...- HttpURLConnection Setup
To collect XHR data from HttpURLConnection-based network requests, wrap the connection as shown below.
Kotlin
import com.sophonz.android.sdk.network.urlconnection.ConnectionWrapper;
...
// Wrap the HttpsURLConnection object with ConnectionWrapper
var url : URL = URL("https://some.host.com")
var conn : HttpsURLConnection =
ConnectionWrapper.wrap(
url.openConnection() as HttpsURLConnection
) as HttpsURLConnection
...Java
import com.sophonz.android.sdk.network.urlconnection.ConnectionWrapper;
...
// Wrap the HttpsURLConnection object with ConnectionWrapper
URL url = new URL("https://some.host.com");
HttpsURLConnection conn = (HttpsURLConnection)
ConnectionWrapper.wrap((HttpsURLConnection) url.openConnection());
...4. Verification
To confirm that Sophonz is working correctly, trigger a sample error and verify that the log is transmitted. Add the following code to an appropriate location in your application.
Kotlin
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exception
import com.sophonz.android.sdk.log.SophonzLog
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
try {
throw Exception("Test error")
} catch (e: Exception) {
SophonzLog.error("TestTag", "This is a test error", e);
}
}
}Java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.lang.Exception;
import com.sophonz.android.sdk.log.SophonzLog;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
throw new Exception("Test error");
} catch (Exception e) {
SophonzLog.error("TestTag", "This is a test error", e);
}
}
}Sophonz Android SDK Configuration
Custom User ID
Set a custom user ID to identify individual users during session analysis. Typically, set it on successful login and clear it with an empty string ("") on logout. Must be called after Sophonz.initialize.
Kotlin
import com.sophonz.android.sdk.core.Sophonz
Sophonz.setCustomUserId("customer-user-id")Java
import com.sophonz.android.sdk.core.Sophonz;
Sophonz.setCustomUserId("customer-user-id");Custom Event Tracking
Send an event notification when a specific button or tab is clicked.
Sophonz.sendClickEvent(view: View, isNetworkRequest: Boolean = false)
- view: the clicked target, isNetworkRequest: whether a data request follows
For a simple screen navigation button click:
Kotlin
import com.sophonz.android.sdk.core.Sophonz
binding.button.setOnClickListener {
Sophonz.sendClickEvent(binding.button, false)
}Java
import com.sophonz.android.sdk.core.Sophonz;
binding.button.setOnClickListener(v -> {
Sophonz.sendClickEvent(v, false);
});When the button click triggers a server data request:
Kotlin
binding.button.setOnClickListener {
Sophonz.sendClickEvent(it, true)
service.getHello().enqueue(object : retrofit2.Callback<Data> {
override fun onFailure(call: Call<Data>, t: Throwable) {
t.printStackTrace()
}
override fun onResponse(call: Call<Data>, response: Response<Data>) {
response.body()?.let { data ->
SophonzLog.debug("MainActivity", "Data: " + data.toString());
}
}
})
}Java
binding.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Sophonz.sendClickEvent(v, true);
service.getHello().enqueue(new Callback<Data>() {
@Override
public void onResponse(Call<Data> call, Response<Data> response) {
Data data = response.body();
if (data != null) {
SophonzLog.debug("MainActivity", "Data: " + data.toString());
}
}
@Override
public void onFailure(Call<Data> call, Throwable t) {
t.printStackTrace();
}
});
}
});WebView Interface Setup
To combine a native app session with a WebView page session, call JavaScriptInjector.injectSession(view) before calling webView.loadUrl(serverUrl).
Kotlin
import com.sophonz.android.sdk.webview.JavaScriptInjector
JavaScriptInjector.injectSession(webView) // add
webView.loadUrl(serverUrl)Java
import com.sophonz.android.sdk.webview.JavaScriptInjector;
// ... omitted ...
JavaScriptInjector.injectSession(webView); // add
webView.loadUrl(serverUrl);
// ... omitted ...Custom Attribute Setup
Add custom user attributes. The prefix custom. is automatically prepended to the key.
Kotlin
import com.sophonz.android.sdk.core.Sophonz
Sophonz.getCustomAttributes().setAttribute("key", "value")Java
import com.sophonz.android.sdk.core.Sophonz;
Sophonz.getCustomAttributes().setAttribute("key", "value");Custom Logging
Use the SophonzLog API to collect custom user logs when needed. Log levels are debug, info, warn, and error.
WARNING — Custom logging caution
Use custom logging only when necessary. Excessive logging can degrade app performance and increase storage usage due to additional collected data.
TIP — Trace critical logic and transactions
Leave custom messages to identify problem patterns and exceptions in your service.
Kotlin
import com.sophonz.android.sdk.log.SophonzLog
SophonzLog.debug("TAG", "message")
SophonzLog.info("TAG", "message")
SophonzLog.warn("TAG", "message")
SophonzLog.error("TAG", "message", RuntimeException("exception"))Java
import com.sophonz.android.sdk.log.SophonzLog;
SophonzLog.debug("TAG", "message");
SophonzLog.info("TAG", "message");
SophonzLog.warn("TAG", "message");
SophonzLog.error("TAG", "message", new RuntimeException("exception"));