Push notifications
Start a Screeb survey when the user receives or taps a push notification, by sending the survey id in the notification payload.
Screeb does not send push notifications. Your push service (Firebase Cloud Messaging, for example) sends them, with a survey id in the payload, and your app starts that survey when the notification arrives or when the user taps it.
You need a survey in the Screeb admin and a push service already working in your app.
Add the survey id to the payload
Section titled “Add the survey id to the payload”In your push service, create the notification (title, body, audience, schedule) and add a custom data entry with the key screeb and the survey id as value. In the Firebase console, custom data is in the “Additional options” step.
{ "screeb": "<SURVEY-ID>"}The key screeb is a convention used in the examples below: any key works, as long as your app reads the same one.
App in the foreground
Section titled “App in the foreground”When the app is in the foreground, Firebase delivers the payload to your FirebaseMessagingService. Start the survey in onMessageReceived.
import app.screeb.sdk.Screebimport com.google.firebase.messaging.FirebaseMessagingServiceimport com.google.firebase.messaging.RemoteMessage
class PushService : FirebaseMessagingService() { override fun onMessageReceived(remoteMessage: RemoteMessage) { remoteMessage.data["screeb"]?.let { surveyId -> Screeb.startSurvey(surveyId = surveyId) } }}Declare the service in your AndroidManifest.xml with the com.google.firebase.MESSAGING_EVENT intent filter, as the Firebase documentation describes.
App in the background
Section titled “App in the background”When the app is in the background, the system shows the notification. Tapping it opens the app with the payload.
// Call it from onCreate() of the activity the notification opens.private fun startScreebSurveyFromIntent() { intent.extras?.getString("screeb")?.let { surveyId -> Screeb.startSurvey(surveyId = surveyId) }}startSurveyFromNotification is deprecated: call startSurvey with the survey id read from the payload, as above.
To add hidden fields, force the language or start a message the same way, see Start a survey programmatically and Start a message programmatically.