Android SDK
Detailed technical documentation on the Lemnisk Android SDK to send data from your website to your destinations via Lemnisk.
This document acts as a reference for the Android SDK documentation. Please ensure that you have an agreed-upon Event Tracking Plan from your Lemnisk Customer Success Point of Contact in conjunction with this document for the correct and complete implementation.
What is the Android SDK?
The Lemnisk Android SDK allows you to track user event data from your Android app. The SDK can be easily imported into any Android app. Based on the data it receives from the user activity, it sends real-time personalized push notifications to the users about the services and products that our clients provide.
Version Details
Lemnisk's latest Android SDK version is 1.1.52, and supports Android 5 and above.
Installing and using the Lemnisk Android SDK
Prerequisites
Lemnisk WriteKey
Lemnisk Server URL
Step 1: Getting the SDK
In your build.gradle
file, add the following dependency:
Step 2: Add Google Play Services to your app
Apps in the Google Play Store use the Google Advertising ID to uniquely identify devices. Therefore, to allow the Lemnisk SDK to use the Google Advertising ID, you need to integrate the Google Play Services.
Open your app/build.gradle
and add the below dependency under dependencies
:
Step 3: Some Additional dependencies
Open your app/build.gradle
and add the below dependency under dependencies
:
Manifest File Changes
In the Package Explorer, open the AndroidManifest.xml
file and make the following changes:
Replace WRITE_KEY
and SERVER_URL
with original values that you receive from our Lemnisk Account Manager.
DEBUG_MODE
is used to show Lemnisk debug/error/info logs. Set this to false
when going to production.
Step 3: Initialize the Android App SDK
Import the library for the classes you desire to use LemniskHelper
library:
Add the below code to the onCreate
method in your Application
class:
Step 4: Add Proguard Rules
If your application uses Proguard, add following rule in proguard-rules.pro
of your application.
Android SDK Methods
1.identify()
method
The identify()
records user-specific information. In the Android SDK, we capture deviceID
and use that as anonymousID
to identify the user.
Usage:
lemniskClient.identify(userId, traits, otherIds);
Example:
2.
screen()
method
The screen()
method is used to record the screen details whenever a user sees any screen on the application.
Usage:
lemniskClient.screen(screenName, properties, otherIds);
Example:
3.
Track()
method
Every action of the user can be tracked through the track
method. Each of these activity is called an event.
Usage:
lemniskClient.track(name, properties, otherIds);
Example:
App Events
Application Installed
This event is automatically fired when the user installs an application.
NO
Application Opened
This event is automatically fired when the user opens an application.
NO
Application Updated
This event is automatically fired when the application gets updated.
NO
Application Backgrounded
This event is automatically fired when a user backgrounds the application.
NO
Application Uninstalled
This event should be sent when a user uninstalls the application.
NO
Application Session Started
This event is automatically fired when a user spends over 10 seconds on the app.
NO
Application Session Concluded
This event is automatically fired when a user is inactive for 20 minutes on the app.
NO
Application Crashed
This event should be sent when your application crashes.
YES
SDK Methods
trackAppEventCrashed()
method
The trackAppEventCrashed()
method is used to send crash report data whenever the application crashes.
Usage
Example
Push Notifications
Lemnisk clients that are running Android app push notifications are requested to provide the required FCM project credentials, to assist in migration to FCM HTTP v1 API by end of May 2024.
This is explained here.
Lemnisk sends push notifications to Android devices using Firebase Cloud Messaging.
Add Firebase SDK
Lemnisk account manager will provide google-services.json. This google-services.json needs to be placed at root level in the app module.
Gradle changes
Manifest Changes
In the Package Explorer open the AndroidManifest.xml of your Android project and make the following changes:
Add the following meta-tags
NOTIFICATION_ICON
is displayed at the left of a notificationNOTIFICATION_ICON_SMALL
is displayed in the notification bar. This should be white icon on a transparent background
Refer to Android Notifications and Style Icons for more details.
Add the following services for receiving the FCM token and messages.
Mandatory intent service for doing the heavy lifting
To support app-based deep link from Android 11 and onwards, following permission needs to be added to AndroidManifest.xml
of the app.
OPT-IN for Push Notifications
If you are targeting Api level >= 33 then you must ask user permission for push notifications at runtime. For that you can call the below function at appropriate place in your app.
We recommend calling this method on every app launch
FCM Auth 2.0 Credentials
FCM deprecated legacy APIs for HTTP and requires OAuth 2.0 authorization for sending push notifications. In order to generate Auth2.0 access token we need following credentials from the clients FCM project.
1. FCM Project Id
This can be retrieved from Project settings -> General -> Project ID
2. Generate Private Key
To authenticate a service account and authorise it to access Firebase services, you must generate a private key file in JSON format.
To generate a private key file for your service account:
In the Firebase console, open Settings > Service Accounts.
Click Generate New Private Key, then confirm by clicking Generate Key.
Securely store the JSON file containing the key.
Please share the above two credentials with lemnisk.
Running Marketing Channels on WebView
If you are using WebView in your Android app and want to run marketing channels such as On-site Notification, Banner Personalization and Notification Bot, you need to call the below method in your app:
webView
WebView instance
Webview instance you want to use
domain
String
Domain of the website where you want to run the marketing channels
Example:
FAQs
Q1. What is the Android version required to set up the Lemnisk Android App SDK?
Minimum Android 5.0 (minAppSDKVersion = API level 21)
Q2. Can Lemnisk Android App SDK be used with Kotlin?
Yes, our Android App SDK can be used with Kotlin as well.
Q3. Can I use the library with Maven?
Yes.
Q4. I need to check the logs. Where should I look?
We can filter with the string "Lemnisk" among the application logs.
Q5. How does the SDK handle different client/server errors?
It prints error messages for both client/server in the logs, but nothing will be visible to the end-user.
Q6. Which all Android permissions are required for the SDK to run smoothly?
Q7. Does the SDK also support tracking events from wearables and TV that run on Android?
SDK is not yet tested for wearables. We have it in our Product Roadmap.
Contact Us
If you have an unanswered question or to know more about the Lemnisk Android SDK you can contact us.
Last updated