Getting started with Android SDK

Convertedin SDK for events and push notifications is a powerful tool for developers to create engaging and personalized experiences for your app users. With this SDK, developers can easily track user behavior and send targeted push notifications to drive engagement and increase retention. Push notifications allow developers to reach users even when they're not actively using the app, keeping them up to date with the latest news, updates, and promotions. By leveraging Convertedin SDK for events and push notifications, developers can create more meaningful and impactful experiences for their users, leading to higher engagement, increased user satisfaction, and ultimately, greater success for their app.


SDK Integration

The Android SDK is compatible with apps supporting Android API level 21 and above. Apps can be written using Kotlin or Java.

Using Github Library

  1. Downloading and importing the SDK

  2. ​Adding the dependency to your Gradle files.

Adding dependency to your Gradle files.

Once you acquire a username and password from Convertedin, you can access the repository that has the SDK. Add the following snippet to your root build.gradle file and you will be able to resolve the library.

allprojects {
    repositories {
           maven { url 'https://jitpack.io' }
    }
}

Then, in the build.gradle file for the project for which you would like to include the SDK, add:

dependencies {
    implementation 'com.github.convertedin:android-pixel-sdk:1.4.4'
}

Manual Download

Step 1: ​Downloading and importing the SDK.

Download the SDK from Github and follow the steps

  1. Open your Android Studio project.

  2. Click on the "File" menu and select "New" > "Import Module".

  3. In the "Import Module" dialog box, Browse and select the module file you want to import, then click "Finish".

  4. In the "Project" view, you should now see the imported module as a sub-project within your main project.

Step 2: ​Adding the dependency to your Gradle files.

dependencies {
  implementation project(path: ':PixelSDK')
  }

Getting Started

Step 1: Initialize the SDK with your Pixel Id and store url.

Initialize the SDK using this function

ConvertedInSdk().initialize(this,"Your pixel id", "Your store url")
//you can get pixel id and store id from the dashboard

Step 2: Authenticate user by Sending user data.

The "Identify User" API in the Convertedin SDK allows developers to track and identify users across different devices and sessions. When a user logs in or creates an account, the developer can use the Identify User API to associate a unique identifier with that user.

This identifier can then be used to track the user's actions and behavior throughout their usage of the application. For example, if a user makes a purchase or completes a form, the Identify User API can associate that action with the user's unique identifier.

By using the Identify User API, developers can gain valuable insights into their user's behavior, preferences, and interests. This information can then be used to improve the user experience, personalize content, and increase user engagement and retention.

Additionally, the Identify User API can also be used to implement security measures such as authentication and authorization, by verifying that a user is who they claim to be and granting them access to certain features or content.

Overall, the Identify User API is a powerful tool for developers to understand and optimize their user's experience, as well as provide a more secure and personalized platform for their users.

Identify user using this function

//This function will be removed soon, use 'register()', login() or 'setUserData()' instead.
ConvertedInSdk().identifyUser(“email”,”phone”,”countryCode”)
//You can enter either email or phone number and country code  

You can enter either email or phone number and country code.

This function is typically triggered when a user signs up for an account or registers their information. By tracking Register events, developers can gain insights into user acquisition and onboarding processes and optimize their registration flow accordingly.

 /**
  * This function is typically triggered when a user registers for the app.
  * @param email or phone is required
  */
ConvertedInSdk().register("email")

ConvertedInSdk().register("phone", "countryCode")
//where eventName is "Register"

This function is typically triggered when a user login into your app. By tracking login action, developers can gain insights into user acquisition and onboarding processes and optimize their login flow accordingly.

 /**
  * This function is typically triggered when a user login into the the app.
  * @param email or phone is required
  */
ConvertedInSdk().login("email")

ConvertedInSdk().login("phone", "countryCode")

This function is commonly used to set the current customer data, for example email or phone and should be used in the first screen of the app.

 /**
  * TThis function is typically triggered in the first screen of the app when user email or phone is available.
  * @param email or phone is required
  */
ConvertedInSdk().setCustomerData("email")

ConvertedInSdk().setCustomerData("phone", "countryCode")

Step 3: Track user events and actions through your app.

Tracking user events and actions through your app is an essential component of app development and user analysis. By monitoring user actions and events, developers can gain valuable insights into how users interact with their app, what features they use most often, and where they encounter problems or difficulties.

To track user events and actions through your app, you can Convertedin SDK. it will allow you to track user behavior in real-time and provide detailed reports and analytics on user engagement, retention, and conversion.

Typically, the process of tracking user events and actions involves the following steps:

  1. Define the events you want to track: Before you can start tracking user events, you need to identify the specific actions or behaviors that you want to monitor. For example, you might want to track when a user completes a registration form or makes a purchase.

  2. Instrument your app with tracking code: Once you have identified the events you want to track, you need to add tracking code to your app to collect data on user behavior. This code can be added to specific screens or features of your app to track when users perform certain actions.

  3. Send data to our SDK: Once the tracking code is implemented, the data on user events and actions is sent to us, where it is stored and analyzed. From there, you can generate reports and dashboards to visualize user behavior and identify areas for improvement.

By tracking user events and actions, developers can make data-driven decisions and improve the user experience of their app. Whether you're looking to optimize conversion rates, improve user engagement, or identify areas for improvement, event tracking can provide valuable insights into how users interact with your app.

To add event, you can use this function

ConvertedInSdk().addEvent("event name","Currency","Total","products")
//where products is an arrayList of EventContent("id","quantity","name")

There are several predefined events you can use

The ViewContent event is a type of event that is commonly tracked to monitor user behavior on your app. This event is typically triggered when a user views a specific piece of content, such as a product, article, or video. By tracking ViewContent events, developers can gain insights into what content users are engaging with most and optimize their content strategy accordingly. The ViewContent event is one of many events that can be tracked by event tracking platforms, and is an important component of user analysis and app optimization.

/**
  * @param currency is required
  * @param total is required
  * @param products(arraylist of EventContent) is required
  * For each product in the products(id & quantity) are required
  */
ConvertedInSdk().viewContentEvent("Currency","Total","products")
//where eventName is "ViewContent"

The PageView event is a type of event that is commonly tracked to monitor user behavior on your app. This event is triggered when a user views a page or screen within the app. By tracking PageView events, developers can gain insights into how users navigate through their app and optimize the user experience accordingly. The PageView event is one of the most basic and commonly tracked events in event tracking, and is an important component of user analysis and app optimization.

ConvertedInSdk().pageViewEvent()
//where eventName is "PageView"

The AddToCart event is a type of event that is commonly tracked to monitor user behavior on an e-commerce app. This event is triggered when a user adds a product to their shopping cart. By tracking AddToCart events, developers can gain insights into which products are most popular and optimize their product offering and pricing accordingly. The AddToCart event is often paired with other e-commerce events such as Purchase or Checkout events, and is an important component of user analysis and e-commerce optimization.

 /**
  * @param currency is required
  * @param total is required
  * @param products is required, for each product `id` and `quantity` are required
  */
ConvertedInSdk().addToCartEvent("Currency","Total","products")
//where eventName is "AddToCart"

The InitiateCheckout event is a type of event that is commonly tracked to monitor user behavior during the checkout process on an e-commerce app. This event is triggered when a user begins the process of checking out and entering their payment and shipping information. By tracking InitiateCheckout events, developers can gain insights into how users interact with the checkout process and identify areas for improvement to increase conversion rates. The InitiateCheckout event is often paired with other e-commerce events such as AddToCart or Purchase events, and is an important component of user analysis and e-commerce optimization.

 /**
  * @param currency is required
  * @param total is required
  * @param products is required, for each product `id` and `quantity` are required
  */
ConvertedInSdk().initiateCheckoutEvent("Currency","Total","products")
//where eventName is "InitiateCheckout"

The Purchase event is a type of event that is commonly tracked to monitor user behavior on an e-commerce app. This event is triggered when a user completes a purchase and successfully makes a payment for a product or service. By tracking Purchase events, developers can gain insights into which products are most popular and identify patterns in user behavior to optimize the checkout process and increase sales. The Purchase event is often paired with other e-commerce events such as AddToCart or InitiateCheckout events, and is an important component of user analysis and e-commerce optimization.

/**
 *  @param currency is required
 *  @param total is required
 *  @param products is required, is required, for each product `id` and `quantity` are required
 *  @param orderId is required
 */
ConvertedInSdk().purchaseEvent("Currency","Total","products, orderId")
//where eventName is "Purchase"

Step 4: ​Configre Push Notifications.

To use Convertedin SDK’s push notifications, you need to integrate with Firebase notifications

Integrating your Android app with Firebase Notifications allows you to send push notifications to your app users. Here are the steps to integrate your Android app to Firebase Notifications:

  1. Create a Firebase project: If you haven't already, create a Firebase project in the Firebase console and add your Android app to it.

  2. Add the Firebase SDK to your app: Add the Firebase SDK to your app by following the instructions provided by Firebase. This involves adding the necessary dependencies to your app's Gradle files and downloading a google-services.json file from the Firebase console and adding it to your app.

  3. Set up Firebase Cloud Messaging: Firebase Cloud Messaging (FCM) is the service that powers Firebase Notifications. Follow the instructions provided by Firebase to set up FCM for your Android app.

  4. Add Firebase messaging to your app: To receive Firebase Notifications in your app, you need to add Firebase Messaging to your app. This involves creating a FirebaseMessagingService and registering it in your app's AndroidManifest.xml file.

  5. Handle incoming messages: Once you have set up Firebase Messaging in your app, you can receive incoming messages in your FirebaseMessagingService. You can then handle the message data and display a notification to the user.

  6. Test your integration: Finally, test your Firebase Notifications integration by sending a test notification from the Firebase console or using a third-party tool like Postman.

By following these steps, you can integrate your Android app with Firebase Notifications and start sending push notifications to your app users.

Step 5: ​ Save Device Token

After Integrating with firebase successfully, call this function on the SDK to send the firebase token to start getting notifications from your dashboard.

ConvertedInSdk().saveDeviceToken("token")
//where token is firebase token

⚠️ Important Note: Each Time firebase token is updated you must call saveDeviceToken function to save the new firebase token

Step 6: ​ Pass Campaign ID

This event is typically triggered when a user clicks on a push notification, and should pass the received campaign id to the function onPushNotificationClicked(), and you can find the campaign id in the payload of the push notification ["campaign_id"] with a string value.

/**
 * @param campaignId is required
 */
ConvertedInSdk().onPushNotificationClicked(campaignId)
/**
 * Inside the `onMessageReceived(message: RemoteMessage)` method, when the app is in the foreground,
 * you can receive the `campaign_id` as follows:
 */
val campaignId = message.data["campaign_id"]

/**
 * If the app is in the background, you can receive the `campaign_id` in your launcher activity as follows:
 */
val campaignIdBackground = intent.extras?.getString("campaign_id")
campaignIdBackground?.let {
    ConvertedInSdk().onPushNotificationClicked(it)
}

Logging out

If user logged out or you want user to stop getting notifications from our side, you can call this function

ConvertedInSdk().deleteDeviceToken()

proguard-rules

# Keep all classes and members in the convertedin.pixel.pixelsdk package
-keep class convertedin.pixel.pixelsdk.** { *; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

-keepattributes Signature
-keepattributes *Annotation*

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * implements java.lang.reflect.Type
-keep class com.google.common.reflect.TypeToken { *; }


# Gson specific classes
-dontwarn sun.misc.**
-keep class com.google.gson.stream.** { *; }

-keep class java.util.HashMap { *; }

# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
 -keep,allowobfuscation,allowshrinking interface retrofit2.Call
 -keep,allowobfuscation,allowshrinking class retrofit2.Response

# Keep classes and members that are used by RxJava
-keep class io.reactivex.** { *; }
-keep class * extends io.reactivex.** { *; }
-keep class * implements io.reactivex.** { *; }

# Keep methods that are used by RxJava subscribers
-keepclassmembers class * {
    void onSubscribe(io.reactivex.disposables.Disposable);
    void onNext(*);
    void onError(java.lang.Throwable);
    void onComplete();
}

Last updated