Assorted Operations (Other Actions)
Sending explicit signals from host UI or tuning to generic Assistant interactions (such as Favorite additions or Link opening).
Setup Reference
In addition to cart additions, user behavior tracking, catching a product favoriting trigger, or redirecting to pages presented by the widget happens under the similar standard mechanism.
1- Toggle Favorites
Let's see the same generic Javascript event listener applied to the favorite icon action inside your host site:
window.addEventListener("message", (event) => {
const data = event.data;
// Let's filter to Favorite toggle specifically
if (data && data.action === "toggleFavorite") {
// Retrieve the sent variables:
const skuCode = data.productCode; // The clicked target SKU
const booleanFavorited = data.isFavorite; // (true / false) Did they add or remove the like?
// Use this state to persist changes against user profile DB or turn your site's header heart green!
}
});2- Listening to URL Hyperlinks
Instead of just opening automatically, we broadcast a message allowing you custom link redirection. Let's see how:
window.addEventListener("message", (event) => {
const data = event.data;
if (data && data.action === "openUrl") {
// Supplied response payload contains:
const hyperLinkURL = data.url; // e.g. "https:// loops.ai / sales"
const windowTarget = data.target || "_blank"; // _blank, _self
// Note: Most of the time we inherently fire `window.open` out-of-the-box inside the logic, but if your setup relies strictly on intercepting this signal, you handle the `window.open()` explicitly here natively.
}
});3- Forcing the Chat Window to Close (Manually)
In situations involving custom web components acting as "Cancel", "Go Back" native page interactions you might wish to programmatically close the assistant completely and revert it down to badge form.
To dispatch the hide behavior without physically touching the widget, simply construct an iframe event push:
const iframe = window.document.getElementById("loopsmartai-iframe");
// Directly post an outbound "closeChat" into the chat iframe container. You might only have to run this line on Native UI triggers!
iframe.contentWindow.postMessage({
action: "closeChat"
}, "*");All interactions are seamless!