Initialization
To initialize the Recharge JavaScript SDK you will need to do it within the root of your theme (wherever the <head />
element is located). Generally this is located in a file called theme.liquid
.
Example
Load the JavaScript SDK script and initialize it with your storefront token and store domain.
storefrontAccessToken
- this token can be created via the merchant-admin where you manage your API tokens
theme.liquid
<html>
<head>
<script src="https://static.rechargecdn.com/assets/storefront/recharge-client-1.26.0.min.js"></script>
<script>
recharge.init({
// optional when in a shopify environment
storeIdentifier: '{{shop.permanent_domain}}',
// required for API access
storefrontAccessToken: 'storefrontAccessToken',
// optional for traceability and debugging
appName: 'appName',
// optional for traceability and debugging
appVersion: '1.0.0',
// retry middleware function if/when Recharge session expires
loginRetryFn: () => {
return recharge.auth.loginShopifyAppProxy().then(session => {
// do anything you want with the session here
// return session
return session;
});
},
});
</script>
</head>
</html>