add this dependency in your build.gradle(app level)
implementation 'com.github.humatv:HumaAnalytics:1.2.1'
implementation 'com.google.android.gms:play-services-auth:20.4.1'
and add repository in your project level
repositories {
google()
...
maven { url 'https://jitpack.io' }
}
sync and build your project then follow below steps:
- step 1:
extend your application class from AnalyticsApplication and pass your BuildConfig.DEBUG, and BuildConfig.FLAVOR
class MyExampleApplication : AnalyticsApplication(
isBuildConfigDebug = BuildConfig.DEBUG,
buildConfigFlavor = BuildConfig.FLAVOR) {
}
- FLAVOR must be "prod" and "dev"
If you can not use inheritance for your Application class so you can add this line at the end of onCreat in your Application class instead
WebEngageConfig().initializeWebEngage(this, webEngageLicensesKey, isDebugMode)
- Step 2 :
Disable automatic backup inside the application tag in your AndroidManifest.xml file.
<application
...
android:allowBackup="false"
....
>
If your application needs allowBackup to be set as true, then call me :)
- Step 3 :
call AnalyticsUtil.loginUser() in first level of entrance to your application (for Example in Application Class) you can pass 3 argument for login user :
/**
* You acn login with "user_unique_Id_from_user_manager" which you got from
* UserManager Server
* it's recommend to pass userManagerUserId */
AnalyticsUtil.loginUser(userManagerUserId = "user_unique_Id_from_user_manager",isDevFlavor)
/**
* Or You acn login with user's "phoneNumber"
* example : "09151646562"
*/
AnalyticsUtil.loginUser(userManagerUserId = null,phoneNumber = "09151646562", isDevFlavor = isDevFlavor, )
/**
* Or You acn login with "device mac Address" which you got from
* UserManager Server
* it's not Recommended*/
AnalyticsUtil.loginUser(userManagerUserId = null, macAddress = "4f:54:23:fs:50", isDevFlavor = isDevFlavor, )
>
- Send Events: example of events without parameters:
AnalyticsUtil.sendEvent("test_event_name")
example of events with parameters:
val addedToCartAttributes: MutableMap<String, Any> = HashMap()
addedToCartAttributes["Product ID"] = 1337
addedToCartAttributes["Price"] = 39.80
addedToCartAttributes["Quantity"] = 1
addedToCartAttributes["Product"] = "Givenchy Pour Homme Cologne"
addedToCartAttributes["Category"] = "Fragrance"
addedToCartAttributes["Currency"] = "USD"
addedToCartAttributes["Discounted"] = true
AnalyticsUtil.sendEvent("test_event_name",addedToCartAttributes)
- SetUser Attributes: (just for HumaStore Project when user update profile)
AnalyticsUtil.setUserAttribute(
UserAttributes(firstName = "first_name",
lastName = "last_name",
phoneNumber = "phoneNumber",
city = "city",
email = "email",
avatarUrl = "avatarUrl"
))
-
Login User: be careful to login user when user log in
-
Logout User:
AnalyticsUtil.logoutUser()
config: if Your Application class extended from AnalyticsApplication all thing is set up on the other way add below code after setting up webengage
WebengagePersonalizationConfig.initPersonalization()
whe have some type which can find in ''' ir.huma.notificationlibrary.utils.personalizition.webengage.models.PersonalizationType '''
- miniPromotion
- footer
- vote
- json
- rowData
can send your campain based on it and receive your data like below
AnalyticsUtil.screenNavigated("ScreenName")
PersonalizationUtil.getVoteData("parentId"){
//yourData
}
[//]: # can also call :(
getVoteData
getPromotionData
getRawData
getJsonData
getJsonStringData)
please be attention that you must call screenNavigated first
Contributions are always welcome!
BaseTeam Huma