Skip to content

CleverTap/clevertap-android-sdk

Repository files navigation

CleverTap Android SDKs

Build Status build - pr raised against develop build - master Download

πŸ‘‹ Introduction

(Back to top)

The CleverTap Android SDK for Mobile Customer Engagement and Analytics solutions

CleverTap brings together real-time user insights, an advanced segmentation engine, and easy-to-use marketing tools in one mobile marketing platform β€” giving your team the power to create amazing experiences that deepen customer relationships. Our intelligent mobile marketing platform provides the insights you need to keep users engaged and drive long-term retention and growth.

For more information check out our website and documentation.

To get started, sign up here

πŸŽ‰ Installation

(Back to top)

We publish the SDK to mavenCentral as an AAR file. Just declare it as dependency in your build.gradle file.

    dependencies {      
         implementation "com.clevertap.android:clevertap-android-sdk:7.0.2"
    }

Alternatively, you can download and add the AAR file included in this repo in your Module libs directory and tell gradle to install it like this:

   dependencies {      
       implementation (name: "clevertap-android-sdk-7.0.2", ext: 'aar')
   }

πŸ“– Dependencies

(Back to top)

Add the Firebase Messaging library and Android Support Library v4 as dependencies to your Module build.gradle file.

     dependencies {      
         implementation "com.clevertap.android:clevertap-android-sdk:7.0.2"
         implementation "androidx.core:core:1.9.0"
         implementation "com.google.firebase:firebase-messaging:23.0.6"
         implementation "com.google.android.gms:play-services-ads:22.3.0" // Required only if you enable Google ADID collection in the SDK (turned off by default).
     }

Also be sure to include the google-services.json classpath in your Project level build.gradle file:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.         
        
    buildscript {       
         repositories {      
             google()
             mavenCentral()       

             // if you are including the aar file manually in your Module libs directory add this:
             flatDir {
                dirs 'libs'
            }
        
         }       
         dependencies {      
             classpath "com.android.tools.build:gradle:8.2.2"
             classpath "com.google.gms:google-services:4.4.0"
        
             // NOTE: Do not place your application dependencies here; they belong       
             // in the individual module build.gradle files      
         }       
    }

Add your FCM generated google-services.json file to your project and add the following to the end of your build.gradle:

apply plugin: 'com.google.gms.google-services'

Interstitial InApp Notification templates support Audio and Video with the help of ExoPlayer. To enable Audio/Video in your Interstitial InApp Notifications, add the following dependencies in your build.gradle file : Note: Clevertap supports AndroidX Media3 from v7.0.0+ to replace the deprecated ExoPlayer libraries. While Clevertap continues to support ExoPlayer, migration is recommended. For migration, refer to this

    implementation "com.google.android.exoplayer:exoplayer:2.19.1"
    implementation "com.google.android.exoplayer:exoplayer-hls:2.19.1"
    implementation "com.google.android.exoplayer:exoplayer-ui:2.19.1"

Once you've updated your module build.gradle file, make sure you have specified mavenCentral() and google() as a repositories in your project build.gradle and then sync your project in File -> Sync Project with Gradle Files.

πŸŽ‰ Integration

(Back to top)

Add Your CleverTap Account Credentials

Add the following inside the <application></application> tags of your AndroidManifest.xml:

<meta-data  
     android:name="CLEVERTAP_ACCOUNT_ID"  
     android:value="Your CleverTap Account ID"/>  
<meta-data  
     android:name="CLEVERTAP_TOKEN"  
     android:value="Your CleverTap Account Token"/>

Replace "Your CleverTap Account ID" and "Your CleverTap Account Token" with actual values from your CleverTap Dashboard -> Settings -> Integration -> Account ID, SDK's.

Setup the Lifecycle Callback - IMPORTANT

Add the android:name property to the <application> tag in your AndroidManifest.xml:

    <application
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:name="com.clevertap.android.sdk.Application">

Note: If you've already got a custom Application class, call ActivityLifecycleCallback.register(this); before super.onCreate() in your custom Application class.

Note: The above step is extremely important and enables CleverTap to track notification opens, display in-app notifications, track deep links, and other important user behavior.

πŸš€ Initialization

(Back to top)

By default the library creates a shared default instance based on the Account ID and Account Token included in your AndroidManifest.xml. To access this default shared singleton instance in your code call -

CleverTapAPI.getDefaultInstance(context)
CleverTapAPI clevertap = CleverTapAPI.getDefaultInstance(getApplicationContext());

Creating multiple instances of the SDK

Starting with version 3.2.0 of the SDK, you can create additional CleverTap instances to send data to multiple CleverTap accounts from your app. To create an additional instance:

  • Create a CleverTapInstanceConfig object. This object can be created and configured as follows:
    CleverTapInstanceConfig clevertapAdditionalInstanceConfig =  CleverTapInstanceConfig.createInstance(context, "ADDITIONAL_CLEVERTAP_ACCOUNT_ID", "ADDITIONAL_CLEVERTAP_ACCOUNT_TOKEN");
    clevertapAdditionalInstanceConfig.setDebugLevel(CleverTapAPI.LogLevel.DEBUG); // default is CleverTapAPI.LogLevel.INFO
    clevertapAdditionalInstanceConfig.setAnalyticsOnly(true); // disables the user engagement features of the instance, default is false
    clevertapAdditionalInstanceConfig.useGoogleAdId(true); // enables the collection of the Google ADID by the instance, default is false
  • Then to create and subsequently access the additional CleverTap instance, call CleverTapAPI.instanceWithConfig with the CleverTapInstanceConfig object you created.
CleverTapAPI clevertapAdditionalInstance = CleverTapAPI.instanceWithConfig(clevertapAdditionalInstanceConfig);

Note: All configuration to the CleverTapInstanceConfig object must be done prior to calling CleverTapAPI.instanceWithConfig. Subsequent changes to the CleverTapInstanceConfig object will have no effect on the additional CleverTap instance created.

𝌑 Example Usage

(Back to top)

See the usage examples here. Also, see the example project, included with this repo.

See our full documentation here for more information on Events and Profile Tracking, Push Notifications, In-App messages, Install Referrer tracking and app personalization.

πŸ“ CleverTap Geofence SDK

(Back to top)

CleverTap Android Geofence SDK provides Geofencing capabilities to CleverTap Android SDK by using the Play Services Location library. To find the integration steps for CleverTap Geofence SDK, click here

πŸ“² CleverTap Xiaomi Push SDK

(Back to top)

CleverTap Xiaomi Push SDK provides an out of the box service to use the Xiaomi Push SDK. Find the integration steps for the CleverTap Xiaomi Push SDK here

πŸ“² CleverTap Huawei Push SDK

(Back to top)

CleverTap Huawei Push SDK provides an out of the box service to use the Huawei Messaging Service. Find the integration steps for the CleverTap Huawei Push SDK here

πŸ“² CleverTap Push Templates SDK

(Back to top)

CleverTap Push Templates SDK helps you engage with your users using fancy push notification templates built specifically to work with CleverTap. Find the integration steps for the CleverTap Push Templates SDK here

πŸ“² CleverTap RenderMax SDK

(Back to top)

RenderMax SDK delivers and renders notifications on the user's device even if the FCM delivery fails or the device is optimized for battery consumption. Find the integration steps for the CleverTap RenderMax SDK here

πŸ“„ License

(Back to top) CleverTap Android SDK is MIT licensed, as found in the LICENSE file.