Skip to content

Commit

Permalink
add final code sample
Browse files Browse the repository at this point in the history
  • Loading branch information
maureenorea-clores committed Jun 25, 2024
1 parent fd9e4d0 commit 4ecfe78
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions inappmessaging/USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ In-App Messaging (IAM) module allows app developers to easily configure and disp
* [SDK Integration](#integration)
* [SDK Logic](#logic)
* [Advanced Features](#advanced)
* [Final Code (Sample)](#final-code)
* [Troubleshooting](#troubleshooting)
* [FAQ](#faq)
* [Documentation and Useful Links](#see-also)
Expand Down Expand Up @@ -422,6 +423,79 @@ InAppMessaging.instance().configure(context = this,
enableTooltipFeature = true)
```

## <a name="final-code"></a>Final Code (Sample)

The final code should basically look something like this:

<details>
<summary style="cursor: pointer;";>(click to expand)</summary>

MainApplication.kt
```kotlin
class MainApplication: Application() {
override fun onCreate() {
InAppMessaging.configure(this)
InAppMessaging.instance().registerPreference(YourUserInfoProvider())
}
}
```

YourUserInfoProvider.kt
```kotlin
class YourUserInfoProvider: UserInfoProvider() {

// Update during login or logout
var userId = ""
var accessToken = ""
var idTracking = ""

override fun provideUserId() = userId

override fun provideAccessToken() = accessToken

override fun provideIdTrackingIdentifier() = idTracking
}
```

MainActivity.kt
```kotlin
class MainActivity: AppCompatActivity(), View.OnClickListener {

override fun onStart() {
super.onStart()
InAppMessaging.instance().logEvent(AppStartEvent())
}

override fun onResume() {
super.onResume()
InAppMessaging.instance().registerMessageDisplayActivity(this)
}

override fun onPause() {
super.onPause()
InAppMessaging.instance().unregisterMessageDisplayActivity()
}

fun onUserLogin() {
// When user logins successfully
InAppMessaging.instance().logEvent(LoginSuccessfulEvent())
}

override fun onClick(v: View) {
// Log the events based on your use-cases

when (v.id) {
R.id.purchase_button_tapped -> InAppMessaging.instance().logEvent(PurchaseSuccessfulEvent())

R.id.home_tab_tapped -> InAppMessaging.instance().logEvent(CustomEvent("tab_visit").addAttribute("tab_name", "home"))

R.id.cart_tab_tapped -> InAppMessaging.instance().logEvent(CustomEvent("tab_visit").addAttribute("tab_name", "cart"))
}
}
}
```
</details>

## <a name="troubleshooting"></a> Troubleshooting
### Proguard ParseException
```kotlin
Expand Down

0 comments on commit 4ecfe78

Please sign in to comment.