Event binding
To bind functions to events within the Hello Retail script, you can include the following JavaScript snippet anywhere on your site to. It can be used any time, before and after the script is loaded.
hrq = window.hrq || [];
hrq.push([
"{action}",
"{event-name}",
callback
]);
Waiting for the script to be ready is a very common usecase. The command queue therefore provides a shorthand for binding to the ready
event. Pushing a callback function on the command queue will automatically bind that function to the ready
event.
hrq = window.hrq || [];
hrq.push(function() {
console.log("Hello Retail is ready");
});
Is equivalent to
hrq = window.hrq || [];
hrq.push([
"bind",
"ready",
function() {
console.log("Hello Retail is ready");
}
]);
The following options are available for action
:
Options for "action"
Action | Description |
---|---|
bind |
The callback will be called each time the event name occurs. If 'name' has already occurred, the callback will be called once immediately (no matter how many times 'name' previously occurred). |
bind_once |
The callback will be called once, when 'name' first occurs. If 'name' has already occurred, the callback will be called immediately, and never again. |
unbind |
If you no longer want to receive callbacks for an event, you can unbind it by specifying the same name and callback as you used when binding. Note that it must be the same instance of the function that was bound. |
Options for "event-name"
For now there is only one event available
Event | Description |
---|---|
ready |
Triggered when the sdk is ready to be called |