Zaawansowana konfiguracja Menedżera tagów Android
Aby rozszerzyć funkcjonalność Menedżera tagów Google, możesz dodać zmienne wywołania funkcji i tagi wywołania funkcji. Zmienne wywołania funkcji umożliwiają przechwytywanie wartości zwracanych przez wywołania zarejestrowanych wcześniej funkcji. Tagi wywołania funkcji umożliwiają wykonywanie wcześniej zarejestrowanych funkcji (np. w celu aktywowania działań na potrzeby dodatkowych narzędzi pomiarowych i remarketingowych, które nie są obecnie obsługiwane przez szablony tagów w Menedżerze tagów).
Aby dodać tag niestandardowy lub zmienną niestandardową za pomocą wywołania funkcji:
Zaimplementuj klasę rozszerzającą klasę com.google.android.gms.tagmanager.CustomTagProvider
lub 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);
}
}
}
Jeśli używasz ProGuard, upewnij się, że nazwy klas i metod nie są zaciemnione. Aby to określić, użyj adnotacji w Keep.
W interfejsie internetowym Menedżera tagów Google używaj pełnej nazwy kwalifikowanej klasy, aby konfigurować tagi i zmiennych:
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2024-11-08 UTC.
[null,null,["Ostatnia aktualizacja: 2024-11-08 UTC."],[[["Function Call variables enable capturing values from pre-registered function calls, extending Google Tag Manager's capabilities."],["Function Call tags allow execution of pre-registered functions, such as triggering hits for unsupported measurement tools."],["Custom tags and variables can be added by implementing a class extending `CustomTagProvider` or `CustomVariableProvider`."],["ProGuard users should prevent obfuscation of custom class names and methods using the Keep annotation."],["Within the Google Tag Manager interface, use the fully qualified class name to configure the custom tags and variables."]]],["Function Call variables and tags extend Google Tag Manager's functionality. Function Call variables capture values from pre-registered function calls, while Function Call tags execute pre-registered functions. To add custom tags/variables, implement a class extending `CustomTagProvider` or `CustomVariableProvider`. Use the `@Keep` annotation to prevent obfuscation with ProGuard. Finally, configure tags and variables in Google Tag Manager's web interface using the fully qualified class name.\n"]]