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:
1dependencies {
2 // Importing Segment's Analytics library for Kotlin Android
3 implementation 'com.segment.analytics.kotlin:android:1.13.0'
4}
5
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.
1buildTypes {
2 debug {
3 buildConfigField "String", "URL", "\"https://collect.renta.im/sdk/metadata\""
4 }
5 release {
6 buildConfigField "String", "URL", "\"https://collect.renta.im/sdk/metadata\""
7 minifyEnabled false
8 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
9 }
10 }
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
1public class MyConnectionFactory extends ConnectionFactory {
2 // Overriding projectSettings method to establish a custom connection using the URL specified in BuildConfig
3 public HttpURLConnection projectSettings(String writeKey) throws IOException {
4 return openConnection(BuildConfig.URL);
5 }
6
7 // Overriding upload method to create a custom connection to Segment's API host
8 public HttpURLConnection upload(String apiHost) throws IOException {
9 HttpURLConnection connection = openConnection(String.format("%s", apiHost));
10 connection.setRequestProperty("Content-Encoding", "");
11 connection.setDoOutput(true);
12 connection.setChunkedStreamingMode(0);
13 return connection;
14 }
15}
Step 4: Initializing and configuring the client
We recommend initializing the client in your application's subclass.
1public class MainApplication extends Application {
2
3 @Override
4 public void onCreate() {
5 super.onCreate();
6
7 // Building and configuring the instance
8 Analytics analytics = new Analytics.Builder(this, "YOUR_RENTA_WRITE_KEY")
9 .trackApplicationLifecycleEvents() // Enables automatic tracking of certain application events
10 .recordScreenViews() // Enables automatic tracking of screen views
11 .trackDeepLinks() // Enables tracking of incoming deep links
12 .logLevel(Analytics.LogLevel.VERBOSE) // Sets the logging level
13 .connectionFactory(new MyConnectionFactory()) // Sets our custom connection factory
14 .build();
15
16 // Setting the initialized instance as a globally accessible instance
17 Analytics.setSingletonInstance(analytics);
18 }
19}
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.