Using the SDK functions
After setting up the storefront SDK, you can now access the awesome features of the SDK.
There are currently two parts of the SDK: utils
functions, and the events
listeners.
The below section focuses on the general details when using utils
functions. For events
, please visit here.
(For the list of available utils
functions & events
, please refer to this guide.)
Accessing Utils Functions
Below is the sample function for ref.
sdk = window.shopline.appExtension.init({ appId: 'your app id'});
// Utils
utils = sdk.utils;
// Example
const currentPage = await utils.getCurrentPageIdentifier();
console.log(currentPage);
// Expected output: String
// product_detail
Initialising the SDK first to get access utils functions
Utils functions are part of the initialised SDK object! Can only access the utils functions after initialising the SDK
All functions in utils are async functions
Below is the sample function for ref.
sdk = window.shopline.appExtension.init({ appId: 'your app id'});
// Utils
utils = sdk.utils;
await utils.getCurrentPageIdentifier();
await utils.getCurrentThemeKey();
await utils.getLoadedLanguage();
...
Due to the async nature, always use 'await' when calling utils
functions!
Updated 3 days ago