SwymCallBacks

Entry point to the Swym Javascript SDK.

window.SwymCallbacks

The window.SwymCallbacks is an JavaScript Array and the entry point to the Swym Javascript SDK.

Definition

window.SwymCallbacks = [].

Push all your custom functions to window.SwymCallbacks to run after the Swym app loads.

Example

Here we are pushing a onSwymLoadCallback function to the SwymCallbacks array.

//Executed after SWYM has loaded all necessary resources.
function onSwymLoadCallback(swat) {
  // Please make all SWYM-related API calls inside this function.
  // You can use the swat argument within this scope.
}
if (!window.SwymCallbacks) {
  window.SwymCallbacks = [];
}
window.SwymCallbacks.push(onSwymLoadCallback);

API Parameters

ArgumentsTypeComments
swatobjectSwym Javascript SDK is passed as the first argument to the callback function.
onSwymLoadCallbackfunctionAs a custom function, this function name can be an arbitrary name of your choice.

Best Practices

✍️

Quick tip

Ideally, one should use the window.onload event to ensure the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images. However, this is not necessary for Swym apps, as we will queue and execute your code after everything has loaded.


swat

swat is the javascript wrapper that contains APIs, settings, and functionality for Swym Apps.

It's installed on your store via a script tag specific to your e-commerce platform (e.g., Shopify or BigCommerce) during app installation process automatically.

Definition

swat | Argument

Example

swat is the first argument inside onSwymLoadCallback .

//Executed after SWYM has loaded all necessary resources.
function onSwymLoadCallback(swat) {
  // Please make all SWYM-related API calls inside this function.
  // You can use the swat argument within this scope.
  if (swat) {
  console.log("Swym scripts tags are installed on your store");
  }
}
if (!window.SwymCallbacks) {
  window.SwymCallbacks = [];
}
window.SwymCallbacks.push(onSwymLoadCallback);