You can use the Embedded Script API to inject custom script tags to the head tag of a site.
If you have custom keys or data, you can use dynamic parameters in your embedded script.
You can also listen to predefined Wix events, and report and listen to custom events.
The embedded script can include dynamic parameters. For example:
<script type=“text/javascript” id=“xyz-script-loader” async defer src=“//js.hs-scripts.com/{{abcid}}.js”></script>
{{
).The MISMATCHED ANONYMOUS DEFINE() MODULES...
error is a common issue when working with AMD/UMD bundled scripts. The error occurs when an embedded script defines an anonymous module, either because it's bundled with AMD or it adds a script tag to the head containing an anonymous module.
To resolve the issue, try the following:
requirejs
exists on the window. If it does, load the script via requirejs
instead of adding the script to the <head>
. This approach is suboptimal and might still lead to race conditions and errors.For more information on this issue, see RequireJS: Common Errors.
Script parameters.
Whether script is disabled or not. Default: false
(not disabled).
Retrieves information about your app's existing embedded script.
If your app doesn't have an embedded script on the relevant site, a 404
error is returned.
You can only call this method when authenticated as a Wix app or Wix user identity.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.
Inserts custom script tags into a site, with the specified values for any dynamic parameters. Call this method when your app is installed on a site.
Your app must have an existing embedded script component, with exactly matching parameter names.
You can only call this method when authenticated as a Wix app or Wix user identity.
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.