Sdk Implementation
- Add dengage sdk dependency to your project level gradle file.
Java
dependencies {
implementation 'com.github.dengage-tech:dengage-android-sdk:6.0.85'
}
For latest Android SDK click
Sdk Necessary Rules
Application Manifest Parameters
You should add some parameters with meta-data to your application manifest.
Please see API Endpoints By Datacenter to set your event end point.
Application Manifest Services
You should add firebase and huawei messaging services to your application manifest. If you are using
your own messaging service classes, you don't need to add Dengage service classes to your manifest.
XML
<service
android:name="com.dengage.sdk.push.FcmMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.dengage.hms.HmsMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
Application Manifest Push Receiver
You should add your PushNotificationReceiver class which extends NotificationReceiver class of
Dengage sdk.
Java
<!-- For handling push notifications comes to messaging service classes -->
<receiver
android:name="{your_package}.PushNotificationReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.dengage.push.intent.RECEIVE" />
<action android:name="com.dengage.push.intent.OPEN" />
<action android:name="com.dengage.push.intent.DELETE" />
<action android:name="com.dengage.push.intent.ACTION_CLICK" />
<action android:name="com.dengage.push.intent.ITEM_CLICK" />
<action android:name="com.dengage.push.intent.CAROUSEL_ITEM_CLICK" />
</intent-filter>
</receiver>
Registering LifeCycle Callbacks
You should register activity lifecycle callbacks to DengageLifecycleTracker. This is required for
fetching some contents from api like in app message list. You can do this operation on your application class.
Java
registerActivityLifecycleCallbacks(DengageLifecycleTracker())
Sdk Methods
init
Should be called once in application lifecycle for initiation of Dengage sdk. You can place it into
Application class onCreate method.
Java
init(
context: Context,
firebaseIntegrationKey: String? = null,
huaweiIntegrationKey: String? = null,
firebaseApp: FirebaseApp? = null,
dengageHmsManager: IDengageHmsManager? = null,
deviceId: String? = null,
deviceConfigurationPreference: DeviceConfigurationPreference? = DeviceConfigurationPreference.Google,
contactKey: String? = null,
partnerDeviceId: String? = null,
disableOpenWebUrl:Boolean? =false,
notificationDisplayPriorityConfiguration: NotificationDisplayPriorityConfiguration =NotificationDisplayPriorityConfiguration.SHOW_WITH_DEFAULT_PRIORITY
)
e.g :
val dengageHmsManager = DengageHmsManager()
Dengage.init(
context = context,
firebaseIntegrationKey = Constants.FIREBASE_APP_INTEGRATION_KEY,
dengageHmsManager = dengageHmsManager,
deviceConfigurationPreference = DeviceConfigurationPreference.Huawei,
disableOpenWebUrl = false,
notificationDisplayPriorityConfiguration = NotificationDisplayPriorityConfiguration.SHOW_WITH_HIGH_PRIORITY
)
to start geofence
DengageGeofence.startGeofence()
Disable Open web
if you do not want the browser to be opened on the push click then you can use the parameter in the init block of the sdk as follows:
disableOpenWebUrl = false
setLogStatus
You can enable or disable logs comes from Dengage sdk to your Logcat.
Java
Dengage.setLogStatus(
enable: Boolean
)
setFirebaseIntegrationKey
You can also set your Dengage firebase app integration key after sdk initiation.
Java
Dengage.setFirebaseIntegrationKey(
integrationKey: String
)
setHuaweiIntegrationKey
You can also set your Dengage huawei app integration key after sdk initiation.
Java
Dengage.setHuaweiIntegrationKey(
integrationKey: String
)
getSubscription
You can get Dengage sdk subscription model from sdk cache if exists (If you init correctly, it will
exist).
Java
Dengage.getSubscription(): Subscription?
setCountry
You can set country of current user subscription.
Java
Dengage.setCountry(
country: String
)
You can set contact key of current user subscription.
Java
Dengage.setContactKey(
contactKey: String?
)
setUserPermission
You can set user permission of current user subscription.
Java
Dengage.setUserPermission(
permission: Boolean
)
getUserPermission
You can get user permission of current user subscription.
Java
Dengage.getUserPermission(): Boolean?
setToken
You can set firebase or huawei messaging token of current user subscription.
Java
Dengage.setToken(
token: String?
)
getToken
You can get token of current user subscription.
Java
Dengage.getToken(): String?
onNewToken
You can set firebase or huawei messaging token of current user subscription.
Java
Dengage.onNewToken(
token: String?
)
setNotificationChannelName
You can set notification channel name for setting to notifications above android 26.
Java
Dengage.setNotificationChannelName(
name: String
)
startAppTracking
You can start app tracking with package name of the apps that you want to track.
Java
Dengage.startAppTracking(
appTrackings: List<AppTracking>?
)
getInboxMessages
You can get inbox messages with pagination. If you set push message addToInbox parameter as true,
push messages sent from Dengage are also saved to your inbox.
Java
Dengage.getInboxMessages(
limit: Int,
offset: Int,
dengageCallback: DengageCallback<MutableList<InboxMessage>>
)
deleteInboxMessage
You can delete any inbox message from the user's inbox.
Java
Dengage.deleteInboxMessage(
messageId: String
)
setInboxMessageAsClicked
You can set any inbox message as clicked with the user's interaction.
Java
Dengage.setInboxMessageAsClicked(
messageId: String
)
setNavigation
You can call this method for showing in app message popup if exists.
Java
Dengage.setNavigation(
activity: Activity
)
setNavigation
You can call this method for showing in app message popup if exists with the given screen name.
Java
Dengage.setNavigation(
activity: Activity,
screenName: String?
)
Retrieve on the same link parameter from the dashboard
Starting from 6.0.11.x , we have added a new parameter if you want to handle deeplink by yourself and do not want the app to restart then you need to pass request code in the setNavigation function and the result intent would be provided in the onActivityForResult
Java
Dengage.setNavigation(
activity: Activity,
screenName: String?
resultCode:Int ,
Dengage.setNavigation(
activity: Activity,
resultCode:Int
To set deeplink in the sdk you can use the link
Dengage.inAppLinkConfiguration(inappDeeplink:String)
You can send tag items to Dengage api.
Java
Dengage.setTags(
tags: List<TagItem>
)
onMessageReceived
You should send push message data, if you are using your own firebase or huawei messaging service
receivers.
Java
Dengage.onMessageReceived(
data: Map<String, String?>?
)
showTestPage
You can use our embedded test pages if you want to show or manipulate any data on Dengage sdk. It is
useful for your development or qa team. Test pages contain;
- Push Message ui and events
- In App Message ui and events
- Getting your device's info on Dengage sdk (Contains copy paste)
- Getting your device's cache on Dengage sdk (Contains copy paste)
- Manipulating fetch times of device parameters
- Showing last 200 logs of Dengage sdk operations (Contains copy paste)
Java
Dengage.showTestPage(
activity: Activity
)
saveRFMScores
You can save rfm scores to local storage if you will use rfm item sorting.
Java
Dengage.saveRFMScores(
scores: RFMScore(
categoryId: String,
score: Double
)
)
categoryView
You can update rfm score of viewed category.
Java
Dengage.categoryView(
categoryId: String
)
sortRFMItems
You can sort rfm items with respect to rfm scores saved to local storage.
Returns list of the sorted rfm items
Java
Dengage.sortRFMItems(
rfmGender: RFMGender,
rfmItems: MutableList<RFMItem>
)
RFMItem(
id: String,
categoryId: String,
personalized: Boolean,
gender: RFMGender{
MALE,
FEMALE,
NEUTRAL
},
sequence: Int
)
You can use RFMItem directly. Also you can create your own rfm item object that extends RFMItem.
Then sort your own items like below:
Java
class YourOwnRFMItem(
id: String,
categoryId: String,
personalized: Boolean,
gender: RFMGender,
sequence: Int,
var parameter1: String,
var parameter2: String,
) : RFMItem(
id = id,
categoryId = categoryId,
personalized = personalized,
gender = gender,
sequence = sequence,
)
val sortedYourOwnRFMItems: MutableList<YourOwnRFMItem> = Dengage.sortRFMItems(
rfmItems = listOfYourOwnRFMItems
)
Event Methods
You can send events to Dengage sdk. Available event methods listed below. But you can send your own
custom events also.
Java
Dengage.pageView(data: HashMap<String, Any>)
Dengage.sendCartEvents(data: HashMap<String, Any>, eventType: String)
Dengage.addToCart(data: HashMap<String, Any>)
Dengage.removeFromCart(data: HashMap<String, Any>)
Dengage.viewCart(data: HashMap<String, Any>)
Dengage.beginCheckout(data: HashMap<String, Any>)
Dengage.cancelOrder(data: HashMap<String, Any>)
Dengage.order(data: HashMap<String, Any>)
Dengage.search(data: HashMap<String, Any>)
Dengage.sendWishListEvents(data: HashMap<String, Any>, beventType: String)
Dengage.addToWishList(data: HashMap<String, Any>)
Dengage.removeFromWishList(data: HashMap<String, Any>)
Dengage.sendCustomEvent(
tableName: String,
key: String,
data: HashMap<String, Any>
)
Dengage.sendDeviceEvent(
tableName: String,
data: HashMap<String, Any>
)
Dengage.sendOpenEvent(
buttonId: String,
itemId: String,
message: Message?
)
Adjust Adid sync with dengage
You can sync adjust adid with dengage through the following method
Java
Dengage.setPartnerDeviceId(adid:String)
Real time inapp functions
You can use the real time in-app functionality by using the function.
Java
showRealTimeInApp(
activity: Activity,
screenName: String? ,
params: HashMap<String, String>? , resultCode: Int
)
here the params are the custom parameters used for comparison.
Some functions used to set properties are as follows
fun setCategoryPath(path: String?)
fun setCartItemCount(count: String?)
fun setCartAmount(amount: String?)
fun setState(name: String?)
fun setCity(name: String?)
Google Tag Manager Implementation
You should use the interface CustomTagProvider.CustomTagProvider is automatically called by tag manager internal sdk.
The execute function provides the hashmap which then can be feeded to our sdk for event collection.
Java
@Keep
class TagManager : CustomTagProvider {
override fun execute(map: Map<String, Any>) {
Log.d("tagRecieved", " $map")
Dengage.sendCustomEvent("Table Name", "key ", map as HashMap<String, Any>)
Dengage.sendDeviceEvent("Table Name", map)
}
For GTM integration please refer
https://developers.google.com/tag-platform/tag-manager/android/v5
https://developers.google.com/android/reference/com/google/android/gms/tagmanager/CustomTagProvider
Restarting Application
If anyone wishes not to restart application when application is in foreground then you can use the function
Dengage.setCurrentActivity(this)
Dengage.restartApplicationAfterPushClick(false)
Here the setCurrentActivity accepts the current activity. For example ,you want to open activity N then in the onCreate function of Activity N you can use Dengage.setCurrentActivity(this).
Set Development Status
If you wish to bypass all the delay and fetch times for inapp , you can use this function.
Dengage.setDevelopmentStatus(isDebug: Boolean? = false)
This however should be used when debugging not in production.
In App Inline
Dengage.showInlineInApp(propertyId:String, inAppInlineElement: InAppInlineElement, activity: Activity, customParams: HashMap<String, String>? = null, screenName: String?, hideIfNotFound:Boolean? = false)
Here propertyID is the android selector that you will be placing while creating campaign.
InApp inline element is the view that you will be placing where inapp inline is to be shown.
custom params is the hashmap for custom params filter that you will be placing on the panel while creating campaign.
screen name parameter is when the inapp inline is to be shown on the specific screen.
hide if not found is a parameter where user can tell the sdk whether hide the view if inappinline is not found.
App Stories
showStoriesList(
storyPropertyId: String,
storiesListView: StoriesListView,
activity: Activity,
customParams: HashMap<String, String>? = null,
screenName: String?
)
here StoriesListView view can be found in
com.dengage.sdk.ui.story.StoriesListView
Here propertyID is the story property id that you will be placing while creating campaign.
custom params is the hashmap for custom params filter that you will be placing on the panel while creating campaign.
screen name parameter is when the inapp inline is to be shown on the specific screen.
Pro guard rules
-keep class com.dengage.** { *;}
You can use the above pro guard rules if you face any error.
If you cannot log any data or witness sdk not calling any api then you need to add retrofit rules also as shown below.
https://github.com/square/retrofit/blob/trunk/retrofit/src/main/resources/META-INF/proguard/retrofit2.pro
Sample App Content
1- Adding Manifest Rules of Sdk (See AndroidManifest)
2- Initiating Dengage Sdk (See class App)
3- Push Notification Receiver (See class PushNotificationReceiver)
4- Sending Page View Events (See class BaseDataBindingFragment)
5- Showing Device Subscription Parameters (See class DeviceInfoFragment)
6- Changing Contact Key (See class ContactKeyFragment)
7- Listing Inbox Messages & Actions of Inbox Messages (See class InboxMessagesFragment)
8- Sending Custom Events (See class CustomEventFragment)
9- In App Message (See class InAppMessageFragment)
10- Send Tags (See class TagsFragment)
11- Show Dengage Test Page (See class HomeFragment)
Migration From Old Sdk
You can follow the instructions on this documentation for migration from old sdk of Dengage.
Visit here.