This repository has been archived by the owner on Jan 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d2478d
commit 0b9dc99
Showing
1 changed file
with
1 addition
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,3 @@ | ||
# Gist for Android | ||
|
||
Gist enables you to create embeddable experiences that range from simple welcome messages to complex multi-step flows. | ||
|
||
## Installation | ||
```gradle | ||
implementation 'build:gist:2.+' | ||
repositories { | ||
maven { | ||
url 'https://maven.gist.build' | ||
} | ||
} | ||
``` | ||
|
||
## Setup | ||
Initialize Gist inside the application’s `onCreate` method. A shared Gist instance can be fetched using `GistSdk.getInstance()`. | ||
When using Kotlin, the shared instanced can also be accessed directly by calling the `GistSdk` object. | ||
The Site Id property can be retrieved from your Customer.io workspace settings. | ||
|
||
```kotlin | ||
import android.app.Application | ||
import build.gist.presentation.GistSdk | ||
|
||
class Application : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
// Initialize Gist with Customer IO site id | ||
GistSdk.getInstance().init(this, "your-site-id") | ||
} | ||
} | ||
``` | ||
|
||
### User Token | ||
If your app is relying on Gist’s web hook service to trigger in-app messages, a user token must be set. This user token should be generated by your services and set at any point during runtime, ex: login or registration. | ||
|
||
```kotlin | ||
GistSdk.getInstance().setUserToken("unique-user-token") | ||
``` | ||
To clear the user token: | ||
```kotlin | ||
GistSdk.getInstance().clearUserToken() | ||
``` | ||
|
||
### Setting Your Current Route | ||
Gist is able to show messages when a user reaches a particular route within your product. This is completely optional but messages containing route rules will not be displayed. | ||
In your route handler add: | ||
|
||
```kotlin | ||
GistSdk.getInstance().setCurrentRoute("user/profile") | ||
``` | ||
|
||
## Manually Triggering In-App Messages | ||
Gist gives you the option to programmatically trigger in-app messaging flows within your app. | ||
|
||
### Show Message | ||
```kotlin | ||
val message = Message("artists") | ||
GistSdk.getInstance().showMessage(message, MessagePosition.CENTER) | ||
``` | ||
|
||
### Adding Message Properties | ||
```kotlin | ||
val mainRouteProperties = mutableMapOf<String, Any?>() | ||
mainRouteProperties["property-key"] = "Hello" | ||
val message = Message(messageId = "artists", properties = mainRouteProperties) | ||
``` | ||
Note: Properties also support `data` classes | ||
|
||
### Dismiss Message | ||
```kotlin | ||
GistSdk.getInstance().dismissMessage() | ||
``` | ||
|
||
## Embedding | ||
Gist gives you the option to embed a message within your native product. Actions performed within the view are reported back to `GistListener`, View size changes are reported to `GistViewListener`. | ||
|
||
```xml | ||
<build.gist.presentation.GistView | ||
android:id="@+id/gistView" | ||
android:layout_below="@id/button" | ||
android:layout_width="match_parent" | ||
android:layout_height="200dp" /> | ||
``` | ||
|
||
```kotlin | ||
binding.gistView.setup(message = Message("message-id")) | ||
binding.gistView.listener = this | ||
``` | ||
|
||
### Adjust View Height Based On Content | ||
|
||
```kotlin | ||
override fun onGistViewSizeChanged(width: Int, height: Int) { | ||
val params = binding.gistView.layoutParams | ||
params.height = height | ||
runOnUiThread { | ||
binding.mainLayout.updateViewLayout(binding.gistView, params) | ||
} | ||
} | ||
``` | ||
|
||
## Event Handling | ||
The library exposes a listener which you can hook into, this gives you the option to know when a message is shown, dismissed or when an action occurs within the message. | ||
|
||
```kotlin | ||
interface GistListener { | ||
fun embedMessage(message: Message, elementId: String) | ||
fun onMessageShown(message: Message) | ||
fun onMessageDismissed(message: Message) | ||
fun onError(message: Message) | ||
fun onAction(message: Message, currentRoute: String, action: String) | ||
} | ||
``` | ||
|
||
Whenever a message is queued for embedding, the event embedMessage is triggered. This leaves it up to the developer to decide where to place the view. | ||
This repository has been archived. If you're looking to implement in-app messaging in your Android app, please refer to our [docs](https://customer.io/docs/journeys/in-app-getting-started/). |