Add Appmaker Web SDK to an Existing Page
This guide will help you add the Appmaker Web SDK to an existing page in your website.
Steps
- Add the following script tag to the page you want to add the Appmaker Web SDK to:
<script src="https://unpkg.com/@appmaker-xyz/web-sdk@latest/dist/index.umd.js"></script>
- And then you can use the Appmaker Web SDK in your code:
<script src="https://unpkg.com/@appmaker-xyz/web-sdk@latest/dist/index.umd.js"></script>
<script>
if (AppmakerWebSdk.isAppmakerWebview()) {
alert("This code is running inside the Appmaker WebView");
}else{
alert("This code is running outside the Appmaker WebView");
}
</script>
- Save the file.
How to do custom actions by editing the theme.liquid file
Find your theme.liquid file in your theme folder.
Add the following code to your theme.liquid file.
<script src="https://unpkg.com/@appmaker-xyz/web-sdk@latest/dist/index.umd.js"></script>
<script>
setTimeout(function() {
if (AppmakerWebSdk.isAppmakerWebview()) {
alert("This code is running inside the Appmaker WebView"); // to test if the code is running inside the Appmaker WebView
// Do custom actions if it is inside appmaker webview
// For example, you can use the following code to open the cart page
AppmakerWebSdk.openCart();
// You can use the following code to open the product page
AppmakerWebSdk.openProductByHandle('test-product'); // test-product is the sample product handle
// You can use the following code to get the platform
AppmakerWebSdk.getPlatform();
if (AppmakerWebSdk.getPlatform() === 'android') {
// Do something if the platform is android
} else if (AppmakerWebSdk.getPlatform() === 'ios') {
// Do something if the platform is ios
}
}
}, 3000);
</script>
- Save the file.
You can refer to the Appmaker Web SDK Methods and Usage guide for more information on the Appmaker Web SDK methods.