Stape
Search
Try for free

HTTP Lookup Variable for server Google Tag Manager

Updated
Sep 10, 2024
Published
Aug 15, 2024

We, at Stape, have developed HTTP Lookup Variable for the server Google Tag Manager (sGTM). The variable is created to make HTTP requests. Thanks to HTTP requests, you can fetch data from external APIs and/or other web services that help enrich the data.

In this article, we will review a variable's use cases, learn how it works, and how to set it up in server GTM.

Use cases

The HTTP Lookup Variable by Stape is beneficial in cases when you need to integrate real-time data from external sources into your GTM workflows. For example:

  • Customization. Fetch user-specific data from external API to customize the tags.
  • Data Enrichment. Provide tags with additional information from external sources (e.g., from CRM).

How it works

After configuring the HTTP Lookup Variable (check the section “How to set up HTTP Lookup Variable”) and adding it to the needed tag or another variable, GTM will send the HTTP request to the specified URL.

Since the HTTP Lookup Variable works with Promises (a JavaScript feature used for asynchronous operations), GTM will wait for the HTTP request to resolve (e.g., get a response) before proceeding.

If the request is successful, the variable will resolve with the data returned by the API.

How to set up HTTP Lookup Variable

Download Variable from GitHub

3. Open the “Templates” section in your server GTM container → find “Variable Templates” → click “New”.

Templates in GTM server-side

4. Click three dots in the top right corner → click “Import” → select the template you downloaded from GitHub → click “Save”.

Import template in GTM server

5. Go to the “Variables” → find the “User-Defined Variables” section → click “New” → choose “HTTP Lookup” variable type.

Choose variable type

6. Configure variable

6.1 Add request method, you can choose from three options:

  • GET - use it to retrieve data on a server.
  • POST - use it to create new resources.
  • PUT - use it to replace an existing resource with an updated one.
Choose request method

6.2 Add "Destination URL". It should be in the format "https://example.com," or you can choose the destination URL from the list of variables.

6.3 (Optional) Check the box:

  • Parse response as JSON - if you want to get the response in JSON format.
  • Store response in the cache - to store the response in Template Storage. If all request parameters are the same, a response will be taken from the cache (if such exists).
Variable settings

7. (Optional) Add advanced variable settings.

7.1 Request Data - add properties and values you want to request.

7.2 Request Headers - here, you can add keys and values to the request.

7.3 Additional Options - add request timeout.

7.4 Logs Settings - choose whether the variable constantly logs to the console, logs during debug mode, or doesn’t log at all.

7.5 Format Value - select options to format the value that will be output by this variable.

Additional settings in Variable

Conclusion

HTTP Variable will be helpful for those who want to customize and enrich the data they retrieve since the HTTP requests retrieve data from external APIs or other web services. The setup process is simple, and the variable is easy to customize to your needs. If you’d like help, don’t hesitate to contact our support team

Tagged with:gtm server

Try Stape for all things server-sideright now!