Notification

G Suite is now Google Workspace: everything your business needs to get work done.

User-defined variable types for mobile

Create custom user-defined mobile variables in Google Tag Manager to suit specific requirements that might not already be covered by built-in variables.

To create a new user-defined variable:

  1. In the left navigation, click Variables.
  2. In the User-Defined Variables section, click New.
  3. Click Variable Configuration and select the desired variable type.
  4. Complete the options for the selected variable type.
  5. Name the variable. Use a naming scheme that is descriptive of the variable's function, e.g. "Data Layer Variable - Product Name."
  6. Click Save.

Tag Manager supports these user-defined variable types for mobile:

Firebase

Event Name

The value is set to "eventNameXYZ" when the following code in your app is executed:

Android:
FirebaseAnalytics.getInstance(mContext).logEvent("eventNameXYZ", null);

iOS:
[FIRAnalytics logEventWithName:@"eventNameXYZ" parameters:parameters];

In most cases, you should use the equivalent built-in variable.

Event Parameter:

The value is set to the value of a Google Analytics (Firebase) event parameter for the given key.

Firebase User Property

The value is set to the Google Analytics (Firebase) user property value for the given key.

Utilities

Advertiser Tracking Enabled

For Android, the variable returns true if ad tracking is enabled, or false if the user has opted out of interest-based ads. Learn more in the Android Developer Center. SDK versions prior to v4 will always return false. For iOS versions 6 and greater, the value is set to the advertisingTrackingEnabled property. Otherwise, the value is set to true. In most cases, you should use the equivalent built-in variable.

Constant

The value is set to the string you specify.

Google Analytics Settings

The Google Analytics Settings variable is used in Universal Analytics tags in web and mobile (Firebase) containers to centrally configure and share common Google Analytics settings that are used across multiple tags. When you create a Google Analytics tag using Universal Analytics, Tag Manager will prompt you to select or create a Google Analytics Settings variable. Learn more.

Lookup Table

The value is set according to the instructions in the lookup table. The lookup table contains two columns (Table empty to illustrate how data is used later):

When [select variable] equals Set [this variable] to
   

The Lookup Table allows you to create a variable for which the value varies according to the value of another variable. This is useful if your app is set up in such a way that the appropriate value (for example, a conversion tracking ID) can be mapped to the App Version Code or another aspect of the app. In this example, a variable named Conversion ID is created. If the App Version Code is 1.0, the value is set to “12345”; if the App Version Code is 1.1, the value is set to “34567”. There is no limit to the number of rows in the lookup table. Fields are case sensitive.

When {{App Version Code}} equals Set {{Conversion ID}} to
1.0 12345
1.1 34567
1.2 56789

Random Number

The value is set to a random number between 0 and 2147483647. In most cases, you should use the equivalent built-in variable.

Container Data

Container ID

The value is the container's public ID (e.g. GTM-ABC42). In most cases, you should use the equivalent built-in variable.

Container Version Number

When the container is in preview mode, this variable's value is the container's preview version number. Otherwise, this variable's value is the container's live version number. In most cases, you should use the equivalent built-in variable.

Application

App ID

The value is set to the package name (Android) or app ID (iOS). In most cases, you should use the equivalent built-in variable.

App Name

The value is set to the name of the app. In most cases, you should use the equivalent built-in variable.

App Version Code

The value is set to the version of the currently running application. In most cases, you should use the equivalent built-in variable.

ID for Advertising

For Android, the value is set to the Advertising ID. SDK versions prior to v4 will always return an empty string. For iOS versions 6 and greater, the value is set to the identifier for advertising (IDFA). Otherwise, the value is set to an empty string.

SDK Version

The value is set to the SDK version of the operating system in which the application is installed. In most cases, you should use the equivalent built-in variable.

Device

Device Name

The value is set to the device name of the currently running application (e.g., "Samsung Android", "Pixel 2"). In most cases, you should use the equivalent built-in variable.

Language

The value is set to the two letter language code representing the device language preference that was set by the user. In most cases, you should use the equivalent built-in variable.

Operating System Version

The value is set to the version of the operating system in which the application is installed. In most cases, you should use the equivalent built-in variable.

Platform

The value is set to the platform of the currently running application (e.g., "Android", "iOS"). In most cases, you should use the equivalent built-in variable.

Screen Resolution

The value is set to the screen resolution of the device of the currently running application. The format is "width x height", e.g., "1920 x 1080". In most cases, you should use the equivalent built-in variable.

Other

Function call

The value is set to the returned value of a call to a pre-registered function. To learn more, refer to the Android or iOS SDK documentation.

Value Collection (legacy containers only)

This variable contains a set of key-value pairs expressed in JSON format. You use a Value Collection to set the configuration values for your application. For a race driving game app, for example, you might define an "App settings" variable of type Value Collection with the following:

{
  "max-fuel": 200,
  "starting-fuel": 100,
  "fuel-burn-rate": 20
}
Your mobile app can retrieve a value in the variable by providing the key. For example:

public class MainActivity {

  // Add your public container ID.
  private static final String CONTAINER_ID = "XXX-YYY";
  
  // Container configuration value keys, used later
  // for retrieving values.
  private static final String MAX_FUEL_KEY = "max-fuel";
  private static final String INIT_FUEL_KEY = "init-fuel";
  private static final String FUEL_BURN_KEY = "fuel-burn-rate";

  // Rest of your onCreate code.
  }
}

/*
* Method to update game configuration values using a
* Google Tag Manager container.
*/
public void updateConfigurationFromContainer(Container container) {

  // Get reference to the container.
  Container container = mFutureContainer.get();

  // Update game settings using Container 
  // configuration value keys.
  maxFuel = mContainer.getDoubleValue(MAX_FUEL_KEY);
  startingFuel = mContainer.getDoubleValue(INIT_FUEL_KEY);
  burnRate = mContainer.getDoubleValue(FUEL_BURN_KEY);
}

A Value Collection variable has triggers associated with it. For configuration values that apply to all instances and versions of your app, set the enabling trigger to the predefined Always. Refer to the developer documentation (Android or iOS) for details on how to use the Value Collection variable.

Was this helpful?

How can we improve it?
Search
Clear search
Close search
Main menu
1288166950662874404
true
Search Help Center
true
true
true
true
true
102259
false
false