This feature is in Developer Preview and is subject to change.
An embedded script is an app extension that injects an HTML code fragment into the DOM of your users' sites. Unlike other extensions, embedded scripts are not fully configured during app installation, and require an additional setup step to embed the code fragment.
Follow the instructions below to:
Once this task is complete, your app will have an embedded script extension that injects its HTML code fragment into the DOM of every page of your users' sites.
In the terminal:
Navigate to your project repo.
Run the following command and follow the prompts to create an embedded script extension:
During the creation process you will be prompted to select a script type and a placement. For this guide, you can make any selection. For more information, see the script type and placement options.
Upon completion, the extension files will be created in your app directory with the following structure:
Note: This step has covered the basics of setting up an embedded script extension. For more information about how you can customize your embedded script, read Embedded Script Extension Files and Code
To finish setting up your embedded script, either you or the site owner must call the embedScript() endpoint to embed your script and update the values of the dynamic parameters in each app instance.
If your app has a dashboard page, you have the option to shift responsibility for this last configuration step onto site owners.
Note: If an app has a dashboard page and an embedded script extension, site owners will automatically be directed to the app's dashboard page after installing the app.
Site owners can call embedScript() from the Wix React SDK.
This API call is also used to specify the value of any dynamic parameters. For more information about using dynamic parameters see Using dynamic parameters in your HTML code.
To use embedScript()
in your app's dashboard page:
Open the page.tsx
file in your app’s src/dashboard/pages
folder.
Add the following import statement at the top of your page:
Inside the Index
method, add the following code:
Add the embedScript()
call somewhere in your code.
For example, add a call to action with instructions to click a button to complete setup for your app. Then, when the site owner clicks the button, they will call the endpoint.
If your app contains only one embedded script, the endpoint should be called in the following format:
If your app contains more than one embedded script, you must also pass a componentId
using the id
value defined in your embedded.json
file. In this situation, your call should be in the following format:
Warning:
If your app only has 1 embedded script, don't pass the componentId
in the request body. This action could break your app in production. The componentId
is only relevant for apps with more than 1 embedded script.
Ensure that parameters
contains all the dynamic parameters in your embedded script. Otherwise, you will get an error and your code will not be embedded.
Although we are setting it up now, the Embed Script
call will not work until you have created an app version, as documented below.
For a practical example of this configuration, see our Mixpanel Analytics template.
You can also call the Embed Script endpoint from your server once the app is installed on a user's site. This requires an access token obtained through the OAuth process.
Now that your app is ready for production, you can build your app and create a version in the app dashboard.
Run the following command to build your app:
Run the following command and follow the prompts to create an app version:
An app version allows you to publish an app to the Wix App Market or install it on a site with a direct install URL. You can view your app versions in the app dashboard.
For more information about building and deploying your app, see Build and Deploy an App with the CLI.
By following these instructions, you have: