Sample mCommerce (Batch Store) for sales. This sample is a full fledged example meant to show both basic and advanced integrations of the Batch SDK with a real-world use case.
- Clone this repository
- Follow this instructions about prerequisites https://batch.com/doc/android/prerequisites. You will need to associate the project to a Firebase Project to continue.
- Batch SDK is already installed, you have to setup Batch with your API KEY in build.gradle :
buildConfigField "String", "API_KEY", '"<YOUR API KEY HERE>"'
Make sure you keep'"
before your API Key and"'
after, they are needed to make a working string constant. - Build gradle
- Run your app, open the Logcat tab of Android Studio. You should see the following logs :
Batch (<version>) is running in dev mode (your API key is a dev one)
Installation ID: <your installation ID>
More information : https://batch.com/doc/android/sdk-integration
Well, installation's over you can setup your first In App campaign.
In-App campaigns will appear on your users’ screen according to a specific trigger. For example, you can choose to display an In-App promoting a discount when a user add one article to cart.
Sample app contains 3 triggers
// Track when the user select an article
fun trackArticleVisit(article: Article){
Batch.Profile.trackEvent("ARTICLE_VIEW", BatchEventAttributes().apply {
put(BatchEventAttributes.LABEL_KEY, article.name)
put("name", article.name)
})
}
// Track when the user add article to cart
fun trackAddArticleToCart(article: Article){
Batch.Profile.trackEvent("ADD_TO_CART", BatchEventAttributes().apply {
put(BatchEventAttributes.LABEL_KEY, article.name)
put("name", article.name)
})
}
// Track when the user proceed to checkout
fun trackCheckout(amount: Double){
Batch.Profile.trackEvent("CHECKOUT", BatchEventAttributes().apply {
put("amount", amount)
})
}
This triggers can be use in the Batch dashboard with labels. More details here : https://batch.com/doc/dashboard/in-app-messaging/campaign-edition.html#_trigger-condition
Example :
- Create campaign
- Set trigger display event :
add_to_cart
- Set label :
Patek Philippe
(If you don’t select any labels, Batch will trigger the message on every trigger of the selected event) - Setup message edition on the interface
In app, if you select Patek Philippe in your cart, you will see In App messaging.