The structure of an embedded script extension in a CLI app is as follows:
These files can be generated in your app by running the following command and selecting Embedded Script extension:
The file named embedded.html
contains the code you wish to inject. Your code will be added to the page's head or body depending on your configuration.
In your HTML code, you can:
Wix will host and deploy every file in your project unless you specify otherwise, including any that you add. Your HTML code can reference these files using a relative path.
When referencing local files in a <script>
tag, the tag needs to have type="module"
.
For example, to reference a file named local-script.js
in the same directory as embedded.html
, use the following code:
Note: TypeScript files are supported.
Dynamic parameters are placeholders in your code that allow for the injection of custom information specific to each site where the code is deployed.
Dynamic parameters must:
{{
)."
) to prevent code evaluation.For example, the following code contains the dynamic parameters googleTag
and userName
:
See below how to specify dynamic parameter values to use during development.
You can add CSS directly to your embedded.html
file, or you can reference a CSS stylesheet with a link. For example:
This CSS applies to your site globally. For example, the following code would make the background of every page of your site red:
This file contains information about your script, and must have the following structure:
Field | Type | Description |
---|---|---|
id | string | A unique identifier for your script. This is a randomly generated GUID. |
name | string | The name of your script as it will appear in your app's dashboard. It can only contain letters and the hyphen (-) character. A descriptive name will help you identify your embedded script in your Extensions page. |
scriptType | enum | An enum used by Wix's Cookie Consent Banner tool to determine whether site visitors consent to having your script run during their visit. Possible values are:
An embedded script must have a type. If your script falls into more than one type, choose the option closest to the bottom of the list above. For example, if your script has Advertising and Analytics aspects, choose Advertising as its type. It's unlikely that you'll need to mark it as Essential. |
placement | enum | An enum indicating where in the page's DOM the HTML code will be injected. Possible values are:
|
This file specifies dynamic parameter values to use during development.
In production, dynamic parameter values are set after installation by embedding the script as explained in Add an Embedded Script Extension Using the Wix CLI.
This file includes an object containing key-value pairs for each of your dynamic parameters.
For example, the code:
Requires a params.dev.json file in the following format:
Make sure the keys are the dynamic parameter names in quotes. The values will be assigned to the parameters when testing your script.