Install Android SDK
Renta suggests using a build system like Gradle to install its library, as it simplifies version upgrades and integration. The library is distributed through Maven Central.
Step 1: Add the dependency to your build
Add the following lines to the project dependencies in Gradle:
dependencies {
// Importing Segment's Analytics library for Kotlin Android
implementation 'com.segment.analytics.kotlin:android:1.13.0'
}
Step 2: Configuring build parameters
This step defines parameters for different types of application builds - debug and release. These parameters will be included in the application configuration file.
buildTypes {
debug {
buildConfigField "String", "URL", "\"https://collect.renta.im/sdk/metadata\""
}
release {
buildConfigField "String", "URL", "\"https://collect.renta.im/sdk/metadata\""
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Step 3: Creating a Custom Connection Factory
This step involves creating your custom connection factory class that extends the base class ConnectionFactory. This gives you control over how your app establishes HTTP connections to send data to Renta
public class MyConnectionFactory extends ConnectionFactory {
// Overriding projectSettings method to establish a custom connection using the URL specified in BuildConfig
public HttpURLConnection projectSettings(String writeKey) throws IOException {
return openConnection(BuildConfig.URL);
}
// Overriding upload method to create a custom connection to Segment's API host
public HttpURLConnection upload(String apiHost) throws IOException {
HttpURLConnection connection = openConnection(String.format("%s", apiHost));
connection.setRequestProperty("Content-Encoding", "");
connection.setDoOutput(true);
connection.setChunkedStreamingMode(0);
return connection;
}
}
Step 4: Initializing and configuring the client
We recommend initializing the client in your application's subclass.
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Building and configuring the instance
Analytics analytics = new Analytics.Builder(this, "YOUR_RENTA_WRITE_KEY")
.trackApplicationLifecycleEvents() // Enables automatic tracking of certain application events
.recordScreenViews() // Enables automatic tracking of screen views
.trackDeepLinks() // Enables tracking of incoming deep links
.logLevel(Analytics.LogLevel.VERBOSE) // Sets the logging level
.connectionFactory(new MyConnectionFactory()) // Sets our custom connection factory
.build();
// Setting the initialized instance as a globally accessible instance
Analytics.setSingletonInstance(analytics);
}
}
Replace "YOUR_RENTA_WRITE_KEY" with your segment record key, which can be obtained from the Renta interface.
The data is applied in the client configuration (we recommend leaving it in, but it is not mandatory):
Step 5: Configuring Event Tracking
Once the client has been successfully installed and initialized, you can start implementing event tracking.