Usage
Theming Options Explained:
Decide which values will be used as triggers (e.g., "spending_amount," "time_played," "level," etc.). You can use any variable you choose. In the web app, when creating a survey, select the trigger parameters and their values, such as level = 3 and time_played = 15 (minutes).
Implement a call whenever you want to update the value of a trigger and possibly display a survey.
using PlaytestingGames.InAppSurvey;
// Call CheckForSurvey
var triggerFields = new List<Trigger> {
new TriggerField("level", "4"); // field
new TriggerField("playedTime", "15"); // field
new TriggerEvent("NEW_ROUND"); // event
// ...
};
InAppSurvey.CheckForSurvey(triggers, inAppSurveyCallbackHandler)
// Implement InAppSurvey.Callback - Optional in case you want custom logic
private InAppSurveyCallbackHandler inAppSurveyCallbackHandler = new InAppSurveyCallbackHandler();
public class InAppSurveyCallbackHandler : InAppSurvey.Callback
{
public void OnNotAvailable()
{
// do something if needed
Debug.Log("InAppSurvey.Callback --> OnNotAvailable");
}
public void OnReadyToShow()
{
// consider to pause the game if needed
Debug.Log("InAppSurvey.Callback --> OnReadyToShow");
}
public void OnDismissed()
{
// user dismissed the survey
Debug.Log("InAppSurvey.Callback --> OnDismissed");
}
public void OnCompleted()
{
// user completed the survey
Debug.Log("InAppSurvey.Callback --> OnCompleted ");
}
}
// To test the implementation you can call: on your Start function
InitInAppSurvey(() => {
var triggerFields = new List<Trigger> {
new TriggerField("level", "4"); // field
new TriggerField("playedTime", "15"); // field
new TriggerEvent("NEW_ROUND"); // event
// ...
};
CheckForSurvey(triggers, inAppSurveyCallbackHandler)
});
Complete Example:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using PlaytestingGames.InAppSurvey;
public class ExampleUsage : MonoBehaviour
{
public static Button getSurveyButton;
private InAppSurveyCallbackHandler inAppSurveyCallbackHandler = new InAppSurveyCallbackHandler();
void Start()
{
Debug.Log("...STARTING GAME...");
InitInAppSurvey(() => {
CheckForSurvey();
});
}
void Update()
{
}
private void InitInAppSurvey(Action onSuccess)
{
var access = new Access(
"sdasdasdnsda2",
"5xz4ixz4jdxg2omzd4o1dtbtyynavpbh",
"demo_player_id_unity_1234",
"2.0",
true
);
// Helper Function
public static Color HexToColor(string hex)
{
// Remove the '#' character if present
if (hex.StartsWith("#"))
{
hex = hex.Substring(1);
}
// Ensure the hex string is the correct length
if (hex.Length != 6 && hex.Length != 8)
{
Debug.LogError("Invalid hex string length.");
return Color.white;
}
// Parse the hex string
byte r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
byte g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
byte b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
byte a = 255; // Default to fully opaque
if (hex.Length == 8)
{
a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
}
// Convert the bytes to a Color object
return new Color32(r, g, b, a);
}
var theme = new Theme(
new Theme.Dialog(
Color.white, // [DIALOG] Background Color
Color.black, // [QUESTION] question text color
Color.black, // [SUBTITLE] subtitle text color
Color.black, // [CLOSE_MODAL_ICON] Color of the Close button
"Choose one to continue", // [SINGLE_CHOOSE_SUBTITLE] Choose one subtitle text
"Choose one or more choices to continue", // [MULTI_CHOOSE_SUBTITLE] Multiple subtitle text
"Fonts/Roboto-Light SDF", // [FONT_PATH] Font path for TextMeshPro saved on Scripts/PlaytestingGames/InAppSurvey/Resource/Fonts folder
Theme.Dialog.Position.BOTTOM // or .CENTER
),
new Theme.NextButton(
HexToColor("#a8dab5"), // [NEXT_BUTTON] button background
HexToColor("#FFFFFF"), // [NEXT_BUTTON] onClick button background
HexToColor("#d9dadc"), // [NEXT_BUTTON] disabled button background
Color.black, // [NEXT_BUTTON] disabled button.text
Color.black, // [NEXT_BUTTON] text color
Color.black // [NEXT_BUTTON] onCLick text color
),
new Theme.Choice(
HexToColor("#f2f3f3"), // [CHOICE] background
HexToColor("#c8e4e4"), // [CHOICE] onClick background
Color.black, // [CHOICE] text color
Color.black // [CHOICE] onClick text color
),
new Theme.Slider(
Color.green, // [SLIDER] Fill Color
HexToColor("#f2f3f3"), // [SLIDER] UnFilled Color
Color.black, // SLIDER] Handle Background Color
Color.white // [SLIDER] Handle text Color
)
);
InAppSurvey.Initialize(access, theme, (bool success) => {
if (success) onSuccess();
});
}
private void CheckForSurvey()
{
var triggerFields = new List<Trigger> {
new TriggerField("LEVEL", "900"),
// new TriggerField("EARNED_COINS", "2400"),
// new TriggerEvent("NEW_ROUND")
};
InAppSurvey.CheckForSurvey(triggerFields, inAppSurveyCallbackHandler);
}
}
public class InAppSurveyCallbackHandler : InAppSurvey.Callback
{
public void OnNotAvailable()
{
// do something if needed
Debug.Log("InAppSurvey.Callback --> OnNotAvailable");
}
public void OnReadyToShow()
{
// consider to pause the game if needed
Debug.Log("InAppSurvey.Callback --> OnReadyToShow");
}
public void OnDismissed()
{
// user dismissed the survey
Debug.Log("InAppSurvey.Callback --> OnDismissed");
}
public void OnCompleted()
{
// user completed the survey
Debug.Log("InAppSurvey.Callback --> OnCompleted");
}
}