Custom on-click behavior
Each
Braze.InAppMessage
object contains a correspondingClickAction
, which defines the behavior upon clicking.
Click action types
The clickAction
property on your Braze.InAppMessage
defaults to .none
but can be set to one of the following values:
ClickAction |
On-Click Behavior |
---|---|
.url(URL, useWebView: Bool) |
Opens the given URL in an external browser. If useWebView is set to true , it will open in a web view. |
.newsFeed |
News Feed will be displayed when the message is clicked, and the message will be dismissed. Note: The News Feed is being deprecated. Check out the migration guide for more details. |
.none |
The message will be dismissed when clicked. |
For in-app messages containing buttons, the message clickAction
will also be included in the final payload if the click action is added prior to adding the button text.
Customizing on-click behavior
To customize this behavior, you may modify the clickAction
property by referring to the following sample:
1
2
3
4
5
6
7
8
func inAppMessage(
_ ui: BrazeInAppMessageUI,
prepareWith context: inout BrazeInAppMessageUI.PresentationContext
) {
if let newUrl = URL(string: "{your-url}") {
context.message.clickAction = .url(newUrl, useWebView: true)
}
}
The inAppMessage(_:prepareWith:)
method is not available in Objective-C.
Customizing in-app message and button clicks
The following BrazeInAppMessageUIDelegate
delegate method is called when an in-app message is clicked. For clicks on in-app message buttons and HTML in-app message buttons (links), a button ID is provided as an optional parameter.
1
2
3
4
5
6
7
func inAppMessage(
_ ui: BrazeInAppMessageUI,
shouldProcess clickAction: Braze.InAppMessage.ClickAction,
buttonId: String?,
message: Braze.InAppMessage,
view: InAppMessageView
) -> Bool
1
2
3
4
5
6
- (BOOL)inAppMessage:(BrazeInAppMessageUI *)ui
shouldProcess:(enum BRZInAppMessageRawClickAction)clickAction
url:(NSURL *)uri
buttonId:(NSString *)buttonId
message:(BRZInAppMessageRaw *)message
view:(UIView *)view;
This method returns a boolean value to indicate if Braze should continue to execute the click action.