Embedding a component
How to include an embeddable component in your app
All the following examples are for a Store Page
but are applicable to any embeddable component.
Embedding using a prebuilt React component
Basic usage
We also provide the @sidedish/react
package that you can use to easily embed your store. To use it, simply run:
The npm package is super lightweight. To use it, simply provide store url and optional sessionId.
With an authenticated user
If you are creating a safe session to the store then use this code:
Internal users
To avoid tracking events and analytics made by your internal employees, you can pass true in the internal
property of the Store component.
Another way to do this is to use the internal
property of passed user
object in the unsafeParams or the safe session.
Embedding as an iframe
Basic usage
If you embed a store without the need for callbacks, then the easiest way to embed that store in your website would be by using an iframe:
Yes, it’s really that simple.
Specific page
You can embed a specific page in the iframe method by just including /p/{X}
in the url, where X can be either page id or page slug.
With a safe session
Internal users
To avoid tracking events and analytics made by your internal employees, you can pass a $internal=true
parameter in the search params of the url.
Another way to do this is to use the internal
property of passed user
object in the unsafeParams or the safe session.
Passing parameters unsafely
We support passing any of the acceptable parameters in an unsafe way if you use them just for display purposes and don’t use them for actual effects anyway.
Passing parameters is relatively straight forward, and depends on your implementation:
-
In the React component you could include the unsafe params as JSX prop-
unsafeParams
. -
In the iframe method you would simply include the params in the url in a querystring manner but preceding with
$
to guarantee uniqueness-URL?$accountId=SOME_ID&$userId=ANOTHER_ID
. This is only required in the iframe method and not in the react method. Please use JSON.stringify() the values.
Callbacks
We support plenty of actions inside a store, including custom callbacks.
Set origin validation in admin
Go to app.sidedish.com/ and navigate to the desired store settings page. Set up a origin validation hostname and set that up to your domain.
Set a callback for a button somewhere in your store
In the layout of the store, define a “Javascript Callback” and set its identifier to a unique string of your liking, that would be the ACTION_IDENTIFIER
, so you could recognize specific events of that kind. Since a store can have multiple callbacks, the id is used to recognize a specific action. You could however use the same id on multiple places in the store to call for the same callback.
Create your function
If you used the React method that is even simpler as you could just pass a function callback as the property onCallback
:
The props of the event are:
The action id that you’ve set in the admin dashboard
Test
Make sure everything works as intended.
Path changes
Preserving path changes provides the user with a bookmarkable page in the store, and is highly recommended.
Pass current page to store
Store url
should reflect the page from the browser. The implementation depends on your code.
Register changes in store and reflect in browser history
Listen to onPathChange
callback on the Store.