Advanced Android Tag Manager configuration

To extend the functionality of Google Tag Manager, you can add Function Call variables and Function Call tags. Function Call variables let you capture the values returned by calls to pre-registered functions. Function Call tags let you execute pre-registered functions (e.g., to trigger hits for additional measurement and remarketing tools that are not currently supported with tag templates in Tag Manager).

Add custom tags and variables

To add a custom tag or custom variable with a Function Call:

  1. Implement a class that extends com.google.android.gms.tagmanager.CustomTagProvider or com.google.android.gms.tagmanager.CustomVariableProvider:

    import android.support.annotation.Keep;
    import java.util.Map;
    
    @Keep
    public class HighScoreProvider implements com.google.android.gms.tagmanager.CustomVariableProvider {
      @Override
      public String getValue(Map<String, Object> map) {
        synchronized (HighScoreProvider.class) {
          return ((Long)sHighScore).toString();
        }
      }
    
      private static long sHighScore = 0;
      public static void recordScore(long score) {
        synchronized (HighScoreProvider.class) {
          sHighScore = Math.max(score, sHighScore);
        }
      }
    }
    
  2. If you use ProGuard, make sure that the class names and methods are not obfuscated. Use the Keep annotation to specify this.

  3. In Google Tag Manager's web interface, use the fully qualified class name to set up tags and variables: custom-variable