An embedded script is an app extension that injects an HTML code fragment into the DOM of a site. Unlike other extensions, embedded scripts aren't fully configured by default during app installation and an extra step is required to embed the code fragment. For detailed instructions, see:
Embedded scripts have a variety of uses, including:
Script types determine whether site visitors consent to having your script run during their visit. Script types categorize embedded scripts for privacy and consent management purposes according to GDPR and similar data protection guidelines. For more information about meeting consent requirements and selecting a script type, see Implement Cookie Consent Requirements.
Each embedded script must specify 1 of the following types:
| Type | Description | Use Cases |
|---|---|---|
ESSENTIAL | Core functionality crucial to site operation. | Authentication, security features |
FUNCTIONAL | Remembers site visitors' choices to improve experience. | Language preferences, UI customization |
ANALYTICS | Provides statistics on how visitors use the site. | Google Analytics, Hotjar, Mixpanel |
ADVERTISING | Provides visitor data for marketing purposes. | Facebook Pixel, Google Ads, retargeting |
If a script falls into multiple types, choose the option closest to the bottom of the list (most restrictive). For example, a script with both Analytics and Advertising aspects should use ADVERTISING.
If you have custom keys or data per user, you can use dynamic parameters in your embedded script.
Dynamic parameters must:
{{).") to prevent code evaluation.For example:
Important: If you add, remove, or change a dynamic parameter, users must update your app to receive the latest version of the embedded 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.