Use custom templates for improved security & performance
1. Navigate to Templates in the Google Tag Manager user interface and click New by the template type you want to create to build a new template.
In Web containers, you can create tag and variable templates In Server containers, you can also create Client templates If you want a head start, you can use ready-made template.tpl files, such as Simo Ahava’s Google Tag Manager Templates, and import them into the Template Editor by clicking Import from the action menu in the top-right corner of the UI.
2. Add template metadata, such as Name, Icon, and Description in the Info tab of the template editor.
3. Fill in the template fields in the Fields tab of the template editor
Give each field a name that you can then reference in the Code Editor. Don’t forget to explore the Field Configurations for each field by clicking the cogwheel icon in the field. Through field configurations, you can add things like validation rules or nested fields. Available Field Configurations for the Simple Table field type
4. Add the template code in the Code tab of the template editor
5. Add all permissions in the Permissions tab of the editor, fill in required fields, and click Run to test the template in the editor and make sure there are no missing permissions.
Running the template will throw an error if there are problems with permissions. You can also use the logToConsole() template API to add logging to your template. This helps with the build setup. Alternatively, you can add unit tests to the template using the Tests tab in the editor. The template has permissions to set the _ga cookie and only the _ga cookie. Any other cookie name would raise a permission error.
6. Click Save to save the template in the respective Custom category - client, tag, or variable - once the test has run successfully.
7. If you want to publish the template to the Community Template Gallery, tick the Agree to Community Template Gallery Terms of Service checkbox in the Info tab and export the template following the submission guidelines.
Check this box if you want to prepare the template for gallery submission