Google Tag Manager (GTM) is a free platform by Google used to deploy and update code (tags) on your website instead of updating the website’s code. Use Median’s GTM template to connect your website to the JavaScript Bridge and trigger Bridge commands using GTM tags. The template injects the Median JavaScript Bridge (median.min.js) into the website using a sandboxed environment. It provides error handling, debugging logs, and dataLayer pushes to track the status of the bridge injection.
The template pushes this object to the data layer:
Required permissions
For security reasons, this template is sandboxed and utilizes the following permissions:
- Injects Scripts: Allows the injection of scripts specifically from https://unpkg.com/ where the JavaScript Bridge is hosted
- Accesses Global Variables: Allows pushing data into the
dataLayer array.
- Logs to Console: Allows the template to print debugging and status messages to the browser console.
Configuration fields (optional)
-
Bridge Version (bridgeVersion)
- Enter the version number of the JavaScript Bridge that will be injected.
- If left blank, defaults to the latest version.
-
User Agent Variable (userAgentValue)
- Enter the name of your user-defined variable that stores the device user agent string
- This value is included in console logs and passed into the
dataLayer payload to provide the following device information: browser, operating system, and device type
How it works
- Debugging initialization: The template reads the
userAgentValue field and logs the user agent to the GTM preview console to confirm the Median app was detected.
- Dynamic URL construction: The template pulls the version number from the
bridgeVersion field and constructs the CDN URL: https://unpkg.com/median-js-bridge@[version]/dist/median.min.js
- Script injection: Using GTM’s sandboxed
injectScript API, it attempts to load the constructed URL into the document.
- State handling: Depending on the outcome of the script injection, a specific event is pushed to the
dataLayer and the tag successfully resolves or fails.
Data layer events
The template automatically pushes an event named median_injected to the dataLayer upon completion. You can use this event to trigger subsequent tags.
On success
If the script successfully loads from the CDN, the following payload is pushed:
On failure
If the script fails to load, the tag signals a failure to GTM and pushes the following payload:
Last modified on November 7, 2026