> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Install Median's GTM tag template

> Install Median's tag template in Google Tag Manager so your GTM tags can run JavaScript Bridge commands in your app.

Use Median's GTM Tag template to execute JavaScript Bridge commands directly from GTM tags instead of updating your website. Learn how to install your GTM container in your app and import Median's Tag template into your GTM workspace.

## Prerequisites

1. A Median app using the [JavaScript Bridge NPM package](https://docs.median.co/docs/npm-package#app-configuration)
   1. If you don't have one yet, [create an app in App Studio](https://median.co/app)

2. A GTM container ID. To create one:

   1. Create a [Google Tag Manager Account and Web Container](https://support.google.com/tagmanager/answer/14842164?hl=en\&ref_topic=15191151\&sjid=7201322012849225464-NC)
      1. Make sure you select **Web** for the container platform
   2. Copy your container ID

### Key concepts

* **GTM Container ID**: Identifies your Google Tag Manager instance (Web Container). You can find it in the top-right area of your GTM container workspace.

* **GTM Tag**: A snippet of code that is executed on your website by GTM to avoid hardcoding it on the site.

* **GTM Tag Template**: A tag that can be imported into your GTM workspace to create preconfigured tags. Median's tag template injects the Median JavaScript Bridge into your app so that other tags can execute bridge commands.

* **GTM Trigger**: Rules that determine when a GTM tag is executed, such as a page view or button click.

## Implementation guide

### Install your GTM container

1. On line 1 of the snippet below, replace `ENTER-GTM-ID-HERE` with your GTM container ID and copy the snippet to your clipboard

```javascript JavaScript theme={null}
var gtmId = 'ENTER-GTM-ID-HERE';
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });

var checkReady = setInterval(function () {
  if (document.body) {
    clearInterval(checkReady);
    var f = document.getElementsByTagName('script')[0];
    var j = document.createElement('script');
    j.async = true;
    j.src = 'https://www.googletagmanager.com/gtm.js?id=' + gtmId;
    f.parentNode.insertBefore(j, f);
  }
}, 50);
```

2. In App Studio:

   1. Head over to the Web Overrides page
   2. In the Custom JavaScript section (iOS and Android), paste the snippet from your clipboard. Make sure your GTM container ID is on line 1.
   3. Click Save
   4. Head over to the Build & Deploy page and rebuild your app

![Custom JavaScript section on the Web Overrides page in App Studio with the GTM snippet pasted](https://mintcdn.com/median-co/TpSItjrYpkPK-i0N/images/docs/a85816119d1d2f672c80f1fcc3c4c8f2d3aad3c066dde9e942506845df8ce304-image.png?fit=max\&auto=format\&n=TpSItjrYpkPK-i0N\&q=85\&s=52b86ca79f9d0d3d8f3925c6aa8631a8)

App Studio: paste the custom JavaScript snippet

### Import Median's tag template in GTM

1. Download the template's `.tpl` file from [this GitHub repository](https://github.com/gonativeio/gtm-median-template/blob/main/template.tpl)

2) In your Google Tag Manager Console: a. Head over to Templates b. Click **New** in the Tag Templates section

![Templates page in a GTM workspace with the New button in the Tag Templates section](https://mintcdn.com/median-co/dZQPJ_0wlG7WNBTy/images/docs/369d480bdd7511e147a1693d272b81fb580a9481c4ccb9cdfee3b187665e2585-image.png?fit=max\&auto=format\&n=dZQPJ_0wlG7WNBTy\&q=85\&s=76e4f007139df9aa3e33d4eb05ddc410)

GTM workspace: import template

c. Click the three-dot menu icon in the top right corner of the screen d. Click **Import** and upload the `.tpl` file e. (Optional) Add a bridge version and `userAgentValue` in the template's fields. See the [configuration fields](https://docs.median.co/docs/google-tag-manager#configuration-fields-optional) on the [Google Tag Manager](https://docs.median.co/docs/google-tag-manager) page for more information.

![GTM template editor with the three-dot menu open and the Import option](https://mintcdn.com/median-co/7LCOHMhgIef7ewYE/images/docs/8a80d591da7aaa5337ae2374606cc6d59010556bb2a1e39cf61e225b8e4da8f8-image.png?fit=max\&auto=format\&n=7LCOHMhgIef7ewYE\&q=85\&s=02ad368f73d0ced21501f50a2ae1356a)

GTM workspace: import template

3. Create a new tag from the template and set the trigger to fire on All Pages. This tag injects the Median JavaScript Bridge into your app so that other tags can use it.

4. Before publishing your container, you can use [GTM's Preview mode](https://support.google.com/tagmanager/answer/6107056?hl=en-US) to verify your configuration. Click **Preview** in your GTM workspace to launch the Tag Assistant, connect it to your web URL, and interact with your website to trigger the desired events. You can then check the Tag Assistant window to confirm that your tags are firing successfully.

5. Publish your GTM container

### Build your own tags

You can create additional tags and triggers to call JavaScript Bridge commands. For example, a tag can check `median.auth.status` to determine if a user's device supports Face ID or Touch ID. If it's supported, you can trigger biometric login prompts directly from GTM, without writing code into your website.

### Reference documentation from Google

* [About GTM](https://developers.google.com/tag-platform/tag-manager)
* [GTM Tags](https://support.google.com/tagmanager/answer/3281060?hl=en)
* [GTM Triggers](https://support.google.com/tagmanager/answer/7679316?hl=en-US)
* [GTM Variables](https://support.google.com/tagmanager/answer/7683056?hl=en-US)
* [Preview and Debug](https://support.google.com/tagmanager/answer/6107056?hl=en-US)

## Setup checklist

Use this checklist to ensure GTM is working correctly:

**Basic setup**

* [ ] The app is using the [JavaScript Bridge NPM package](https://docs.median.co/docs/npm-package#app-configuration)
* [ ] The custom JavaScript snippet is pasted in **App Studio → Web Overrides** with the correct GTM container ID
* [ ] A new app build has been generated in App Studio
* [ ] Median's `.tpl` Tag template is successfully imported into the GTM workspace
* [ ] A tag has been created from the template and set to fire on "All Pages"

**Triggers**

* [ ] GTM triggers are configured correctly to fire on specific app events (e.g., page views, button clicks)
* [ ] Tags fire exactly when expected according to the defined trigger conditions

**JavaScript Bridge commands**

* [ ] Custom tags correctly execute Median JavaScript Bridge commands
* [ ] Executed commands trigger the intended native device features

**Publishing and live testing**

* [ ] The tags are firing in GTM's preview tool
* [ ] The GTM container is successfully published to the live environment

## Troubleshooting

### GTM tags are not firing

Verify that you replaced `ENTER-GTM-ID-HERE` with your actual GTM Container ID in the Custom JavaScript snippet under **Web Overrides**. Use [GTM's Preview mode](https://support.google.com/tagmanager/answer/6107056?hl=en-US) to ensure your triggers are configured correctly and firing on the expected events.

### JavaScript Bridge commands are not executing

Ensure you have imported the Median Tag template (`.tpl`) into your GTM workspace and created the initialization tag set to fire on **All Pages**. Also, confirm you generated a new app build in App Studio after saving your Web Overrides.

### App is not reflecting GTM changes

Changes made within Google Tag Manager do not require a new app build, but they must be published to go live. Make sure you have clicked **Submit** and **Publish** in your GTM workspace after creating or modifying tags.


## Related topics

- [Control your Median app with Google Tag Manager](https://docs.median.co/docs/google-tag-manager.md)
- [Median App Studio](https://docs.median.co/docs/app-studio.md)
- [Install Android APK](https://docs.median.co/docs/install-android-apk.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.