askvity

What is Function Call in Google Tag Manager?

Published in Google Tag Manager Variable 3 mins read

A function call in Google Tag Manager, specifically known as a function call variable within the context of GTM for mobile apps, is a mechanism to fetch dynamic data directly from your application's native code.

According to Google's documentation, in Google Tag Manager (v5) for apps, a "function call variable is a variable that calls out to code in the app and requests that the app provide a value." This means you can configure a variable in your GTM container that, when evaluated, executes a specific piece of code within your mobile application and retrieves whatever value that code returns. "The value is then returned to GTM in a variable that works just like any other GTM variable."

How Function Call Variables Work

Function call variables bridge the gap between your GTM configuration and your app's underlying code. Here's a simplified flow:

  1. GTM Variable Configuration: You create a variable of the "Function Call Variable" type in your GTM container. You specify the name of the function or method within your app's code that GTM should call.
  2. App Implementation: Within your mobile application's code (iOS or Android), you implement a corresponding function or method that performs the necessary action (e.g., fetching a user ID, checking a setting, calculating a value) and returns the desired data. This function needs to be exposed to GTM in a specific way defined by the GTM SDK.
  3. Variable Evaluation: When a tag, trigger, or another variable in GTM requires the value of this function call variable, GTM requests the value.
  4. GTM SDK Interaction: The GTM mobile SDK in your app receives the request for the specific function call variable.
  5. App Code Execution: The SDK invokes the corresponding function or method within your app's code.
  6. Value Return: Your app's function executes and returns a value (e.g., a string, number, boolean) to the GTM SDK.
  7. Value in GTM: The GTM SDK passes this value back to the GTM container instance running within the app, where it becomes available as the value of the function call variable.

Why Use a Function Call Variable?

Function call variables are particularly useful in app tracking for scenarios where data you need for tagging is dynamic and resides within your app's logic, not easily available through standard GTM variables like event parameters or built-in variables.

  • Accessing Dynamic App Data: Retrieve data that changes during a user session or depends on complex app logic (e.g., subscription status, internal user ID, specific app settings).
  • Reusing App Logic: Leverage existing functions in your app's codebase without duplicating logic in GTM or relying solely on data layer pushes for every piece of information.
  • Simplifying Data Layer: Avoid pushing every conceivable data point into the data layer by calling specific functions only when their data is needed by GTM.

Essentially, a function call variable allows GTM to programmatically "ask" the app for information when required, providing a flexible way to integrate app-specific data into your tagging strategy.

Related Articles