Segment

Segment makes it easy to send/receive your user data/events to/from CustomFit.ai. Analytics for Android only supports any Android device running API 14 (Android 4.0) and higher.

Getting Started

To integrate Segment with CustomFit.ai follow the below steps:

Step 1: Install the Library

The recommended way to install the library for Android is with a build system like Gradle. This makes it dead simple to upgrade versions and add destinations. The library is distributed via Maven Central. Simply add the analytics module to your build.gradle:

dependencies {
compile 'com.segment.analytics.android:analytics:4.+'
implementation 'ai.customfit:customfit-android-client:1.0.0'
}

And also you need to make the following entries in the build.gradle of the project :

allprojects {
repositories {
....
maven {
url "https://maven.customfit.ai/artifactory/gradle-release-local"
}
}
}

Step 2: Initialize the Client

We recommend initializing the client in your Application subclass.

// Create an analytics client with the given context and Segment write key.
Analytics analytics = new Analytics.Builder(getApplication(), YOUR_WRITE_KEY)
.trackApplicationLifecycleEvents() // Enable this to record certain application events automatically!
.recordScreenViews() // Enable this to record screen views automatically!
.build();
// Set the initialized instance as a globally accessible instance.
Analytics.setSingletonInstance(analytics);

Once you have initialized an Analytics client, you also need to inform CustomFit.ai about the user, just by sending the user customer id

CFUser user = new CFUser.Builder("user_customer_id")
.build();
CustomFit.init(getApplication(), "CLIENT_KEY", user, WAIT_TIME);

Step 3: Add Permissions

Ensure that the necessary permissions are declared in your application’s AndroidManifest.xml.

Identify

identify lets you tie a user to their actions(events) and record traits(properties) about them. It includes a unique User ID and any optional traits you know about them.

We recommend calling identify a single time when the user’s account is first created, and only identifying again later when their traits(properties) change.

Example identify call:

Traits traits = new Traits();
traits.putName("ASHWIN");
traits.putGender("MALE");
traits.putEmail("ashwin");
traits.put("age",30);
traits.put("weight",30);
analytics.identify("Ashwin",traits,null);

Track

track lets you record the actions your users perform. Every action triggers what we call an “event”, which can also have associated properties.

Example track call:

analytics.track("Product Added", new Properties()
.putValue("cart_id", "skdjsidjsdkdj29j")
.putValue("product_id", "507f1f77bcf86cd799439011")
.putValue("sku", "G-32")
.putValue("category", "Games")
.putValue("name", "Monopoly: 3rd Edition")
.putValue("brand", "Hasbro")
.putValue("variant", "200 pieces")
.putValue("price", 18.99)
.putValue("quantity", 1)
.putValue("coupon", "MAYDEALS")
.putValue("position", 3)
.putValue("url", "https://www.example.com/product/path")
.putValue("image_url", "https://www.example.com/product/path.jpg"));

In order to configure your app to get the config values please visit here. And also to get the near real-time updates you need to register the configs. To know how to register the configs please visit here.