Unity SDK 5.0.0

Release notes, improvements, documentation, and examples.

Mobile Native SDKs

Android SDK 7.0.1
iOS SDK 6.0.2

Features

🚧

IMPORTANT

The in-app messages/actions triggering system now uses a queue. In order for it to work as expected and enqueue messages, your custom templates must let it know when the message has been dismissed.
Once you dismiss your message (or destroy/inactivate the game object that holds it) you need to call the Dismissed method on the ActionContext: actionContext.Dismissed(). This way the messaging queue can continue presenting messages.
For more information read the following articles:
IAM Handlers
Custom In-App Templates Migration - Android 6.0.0
Custom In-App Templates Migration - iOS 5.0.0

🚧

Android Application

It is mandatory to invoke LeanplumActivityHelper.enableLifecycleCallbacks(context) in the earliest possible moment, i.e. in the Application.onCreate method. This would allow the IAM Handlers mechanism to work properly. We made it easier by providing LeanplumUnityApplication class, which is registered in the manifest, but if you have a custom Application class you need to call LeanplumActivityHelper.enableLifecycleCallbacks(this) in Application.onCreate method.

  • Should Display Message:
public delegate MessageDisplayChoice ShouldDisplayMessageHandler(ActionContext context);

/// <summary>
///     Called per in-app message to decide whether to show, discard or delay it.
/// </summary>
/// <param name="handler">
///     Handler to be called before displaying a message.
///     Provides an ActionContext and returns MessageDisplayChoice
/// </param>
public static void ShouldDisplayMessage(ShouldDisplayMessageHandler handler)

Message choices:

public class MessageDisplayChoice
    {
        public int DelaySeconds { get; set; }
        public DisplayChoice Choice { get; set; }

        public enum DisplayChoice
        {
            SHOW = 0,
            DISCARD,
            DELAY
        }

        private MessageDisplayChoice(DisplayChoice type, int delaySeconds = 0)
        {
            Choice = type;
            DelaySeconds = delaySeconds;
        }

        public static MessageDisplayChoice Show()
        {
            return new MessageDisplayChoice(DisplayChoice.SHOW);
        }

        public static MessageDisplayChoice Discard()
        {
            return new MessageDisplayChoice(DisplayChoice.DISCARD);
        }

        public static MessageDisplayChoice Delay(int delaySeconds)
        {
            return new MessageDisplayChoice(DisplayChoice.DELAY, delaySeconds);
        }
    }

To delay indefinitely, pass -1 for the delay seconds.

Example:

            Leanplum.ShouldDisplayMessage((context) =>
            {
                return MessageDisplayChoice.Show();
            });
  • Trigger indefinitely delayed messages:
/// <summary>
///     Triggers all postponed messages when indefinite time was used with `MessageDisplayChoice`
/// </summary>
public static void TriggerDelayedMessages()
  • Prioritize Messages:
public delegate ActionContext[] PrioritizeMessagesHandler(ActionContext[] contexts, Dictionary<string, object> actionTrigger);

/// <summary>
///     Called when there are multiple messages to be displayed. Messages are ordered by Priority.
///     Messages can be reordered or removed if desired. Removed messages will not be presented.
///     Messages will be presented one after another in the order returned.
/// </summary>
/// <remarks>
///     If this function is not implemented, the first message is presented only.
/// </remarks>
/// <param name="handler">
///     Handler to be called if there are multiple messages triggered by the same trigger.
///     Provides ActionContexts ordered by priority.
///     Returns the messages to be displayed in that order.
/// </param>
public static void PrioritizeMessages(PrioritizeMessagesHandler handler)

The action trigger dictionary contains the following keys:

  • eventName, condition, contextualValues.
    The contextual values contain information about:
  • parameters, arguments, previousAttributeValue, attributeValue.

Example:

Leanplum.PrioritizeMessages((contexts, trigger) =>
{
      // Reverse the messages order
      return contexts.Reverse().ToArray();
});

  • On Message Handlers:
public delegate void MessageHandler(ActionContext context);
public delegate void MessageActionHandler(string action, ActionContext context);

/// <summary>
///     Called when the message is displayed.
/// </summary>
/// <param name="handler">Handler with the message ActionContext.</param>
public static void OnMessageDisplayed(MessageHandler handler)

/// <summary>
///     Called when the message is dismissed.
/// </summary>
/// <param name="handler">Handler with the message ActionContext.</param>
public static void OnMessageDismissed(MessageHandler handler)

/// <summary>
///     Called when a message action is executed.
/// </summary>
/// <param name="handler">Handler with the actionName and message ActionContext.</param>
public static void OnMessageAction(MessageActionHandler handler)
  • Pause/Enable queue execution:
/// <summary>
///     Use method to pause or unpause in-app messages execution.
///     When paused, it stops executing actions but new actions will continue to be added to the queue.
///     Default value is false (unpaused).
/// </summary>
/// <param name="enabled">True to pause queue, false otherwise.</param>
public static void SetActionManagerPaused(bool paused)
  • Disable/Enable queue execution:
/// <summary>
///     Use method to disable queue. That would stop queue from receiving new actions.
///     Default value is true (enabled).
/// </summary>
/// <param name="enabled">False to disable adding actions to queue and true otherwise.</param>
public static void SetActionManagerEnabled(bool enabled)

Other Changes

  • OnAction and runActionNamedResponder are removed

  • DefineAction overload with Dismiss handler, for more information see the migration guides linked above

  • ActionContext Name on mobile now uses the actionName of the action and not the format actionName:id

  • Added AddOnceVariablesChangedAndNoDownloadsPendingHandler

Unity Native

  • Built-in in-app messages no longer use the EditorDialog. They use a prefab with panels and UI elements instead.
    In order to work properly, ensure you have updated the LeanplumWrapper and the Leanplum game object on your scene has InAppPrefabPlaceholder script component.
  • LeanplumActionManager is rewritten to use queue and to support the IAM handlers
  • Improvements and bug fixes are applied to the LeanplumWrapper are also done, so ensure you update your own.
  • Updates to the mainTemplate.gradle

Bug Fixes

  • Use parent id for chained messages
  • Fix group variable values
  • Fix isEditor when using simulator
  • Fix WebGL build