AppstleMembership:CustomerPortal:ReadyToEmbed and AppstleMembership:CustomerPortal:Embedded. Use them to start the portal from your own code once it can run, and to run your code once the portal is on the page.
The events exist only on a Shopify theme where the Appstle℠ Memberships app embed is on (in the theme editor, under App embeds). If you build a headless storefront or your own front end on the Storefront API, nothing fires them: update your own UI when your own calls return.
The events
Both events are plainEvent objects with no detail, and they don’t bubble. The app embed dispatches each one on document and then on window, so a listener on both runs twice. Listen on one of them.
AppstleMembershipCustomerPortal element recorded the events in this order:
AppstleMembership:CustomerPortal:ReadyToEmbed, withwindow.appstleMembershipCustomerPortalInitalready a function.AppstleMembership:CustomerPortal:Embedded, once the portal’s HTML was in the element.
ReadyToEmbed fires while the page loads. Embedded fires each time the portal is loaded into an element, including the load that starts by itself when the page has an element with the id AppstleMembershipCustomerPortal. A listener that you add after an event has fired never sees it, so add your listeners early, for example in a script with defer or in the theme’s <head>. For ReadyToEmbed, also check the function as shown in Start the portal from your own code.
Embed the customer portal on a page
Use the embed to show Appstle’s customer portal inside a page of your store, such as/pages/members, instead of rebuilding the portal with the Storefront API.
This embeds the customer portal that Appstle serves through the app proxy, by default at
/apps/memberships. The membership page inside Shopify’s own customer account pages is a separate Shopify customer account extension, and you can’t embed it elsewhere.Add the portal to a page
Add an element with the idAppstleMembershipCustomerPortal to the page. On a Shopify page, switch the editor to HTML view (the <> button) and paste:
iframe, so don’t depend on the markup inside the element.
A signed-in customer sees their memberships. A visitor who isn’t signed in sees a form that asks for their email address to send them a new sign-in link. On the demo store, it showed the message “Your magic link has expired. Enter your email to get a new link.” with an Email address field and an Email Magic Link button.
Start the portal from your own code
Callwindow.appstleMembershipCustomerPortalInit(selector) when the element has a different id, or when your code adds it after the page loads. Call it after the element is in the page. The function loads the portal into every element that matches the CSS selector, so use a selector that matches one element, such as an id. Without a selector, it uses #AppstleMembershipCustomerPortal.
The function may not exist yet when your code runs. Check for it first, and when it isn’t there yet, wait for the ReadyToEmbed event:
- When the portal’s HTML is in the element,
Embeddedfires and the returned promise resolves, with no value. - When the request for the portal fails, the error is logged to the browser console,
Embeddeddoesn’t fire and the promise still resolves. It never rejects. - When no element matches the selector, the call does nothing and no event fires.
- Each call loads the portal again and replaces what is inside the element, so call it once per page view.
undefined, and the promise isn’t always a native Promise. To wait for the portal, wrap the call in Promise.resolve():
apps/memberships, so the path must open the portal on the store. When the setting isn’t an app proxy path such as apps/memberships, the call does nothing and logs nothing.
Further reading
Sell from a custom page
Add a membership to the cart from your own page or theme code.
Storefront API authentication
How Storefront API calls are authorized and limited.