Server Side Solutions
16 JUNE 2024
httpRequest - Simple
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.
Features
- 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
Usage
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
httpRequest
template. - Define the key-value pairs for the request headers and body.
- Save and publish the tag.
Example
Here is an example of how to use the httpRequest
template:
Create a new tag using the
httpRequest
template.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 Doe
email: john.doe@example.com
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.