Skip to main content
Version: Javascript tag

Start message programmatically

How to start a message programmatically?โ€‹

In most cases, you should let the Screeb targeting engine start the message. But sometimes, you may need more control on message trigger time.

tip

You can find the MESSAGE_ID in the Manual section of the message editor. You can also find it in the message editor URL, after the /messages/ part.

$screeb("message.start", "<MESSAGE_ID>");

Prevent multiple displays?โ€‹

If current user already replied to your message and you would rather not display it many times, please add the allow_multiple_responses argument:

$screeb("message.start", "<MESSAGE_ID>", { allow_multiple_responses: false });

Respect message status?โ€‹

By default, using manual message start will ignore the message status. If you want to respect the message status, you can add the ignore_message_status argument and set it to false:

$screeb("message.start", "<MESSAGE_ID>", { ignore_message_status: false });

Contextualize responseโ€‹

The message.start command accepts an object of hidden fields. Values passed as parameters will be listed alongside the responses, on the Screeb platform.

$screeb("message.start", "<MESSAGE_ID>", {
hidden_fields: { color: "green", article_id: 42 },
});

Force languageโ€‹

If you want to force the message language, you can pass the language parameter: Here is the order of priority for the language: message.start param > init param > user property > browser language.

$screeb("message.start", "<MESSAGE_ID>", { language: "en" });

How to close a message?โ€‹

You can close the currently running message with the message.close command. Optionally, you can pass a message id to close a specific message.

// Close all running messages
$screeb("message.close");

// Close a specific message
$screeb("message.close", "<MESSAGE_ID>");

Force restart a messageโ€‹

If a message is already active for the current user and you want to close it and restart it from the beginning, use the force_restart option:

$screeb("message.start", "<MESSAGE_ID>", { force_restart: true });

Without this option, calling message.start while a response is already in progress will result in an error.