Create tag templates in Google Tag Manager

1. Create a new tag template.

In the left menu of GTM go to Templates and then click on New at the tag template section.

2. Add template information.

Choose a name for the template and a description. You can also include an image to display as an icon for the template, in the list of tags.

3. Add fields to use in the tag.

Depending on the tag you are creating, you have different types of fields to add. If you want a field where the user can write a value, choose Text input, or if you want the user to select within a list of values, you can use a Drop-down menu. Each type of field has a specific configuration, once added you’ll be able to set the field up.

4. Create the tag’s code.

The code editor allows you to create the custom HTML you need for the tag to work. If the code needs to access a global state of the page or run native JavaScript functions defined on the global level, it requires an API call, and you have to use require() it in the template code. For example, creating a variable: setInWindow = require('setInWindow');

5. Define permissions for APIs used in the code.

Permissions are automatically detected while using APIs on the code. Once you’ve created the code of the tag and call all the APIs, you have to set the type of permissions needed for them to work, If you skip this step the code won’t work.

6. Save the tag and test it.

Go to the list of tags, and you’ll find the new tag you’ve created. When setting up the tag, it will need you to type or choose the parameters you decided necessary to work. For example, if you created a tag template for the Facebook Pixel, you may have the following structure: