This repository features a server-side Google Tag Manager (sGTM) template that streamlines the creation of HTTP requests. Unlike traditional sGTM HTTP request template where you manually write the JSON for the request body—leading to potential syntax errors and formatting issues—this template simplifies the process, eliminating the need to write JSON manually and reducing the risk of mistakes.
You can easily define key-value pairs for request headers and body, and the template compiles all the necessary code in the backend.
- Simplifies the creation of HTTP requests in GTM
- Allows easy definition of key-value pairs for headers and body
- Automatically compiles the necessary code in the backend
To use this GTM template in your project, follow these steps:
- Download the template from this repository.
- In your GTM workspace, go to the Templates section.
- Click on the "New" button to create a new template.
- Import the downloaded template file.
- Save and publish the template.
Once the template is installed, you can use it to create HTTP requests as follows:
- Go to the Tags section in your GTM workspace.
- Click on the "New" button to create a new tag.
- Select the
httpRequesttemplate. - Define the key-value pairs for the request headers and body.
- Save and publish the tag.
Here is an example of how to use the httpRequest template:
-
Create a new tag using the
httpRequesttemplate. -
Define the following key-value pairs in the request headers:
Authorization: Bearer <your-token>Content-Type: application/json
-
Define the following key-value pairs in the request body:
name: John Doeemail: [email protected]
-
Save and publish the tag.
To create a nested array, use array builder variable: https://tagmanager.google.com/gallery/#/owners/stape-io/templates/array-builder-variable
To create a nested object, use object builder variable: https://tagmanager.google.com/gallery/#/owners/stape-io/templates/object-builder-variable
This will create an HTTP request with the defined headers and body, and the template will compile the necessary code in the backend to send the request.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.
