การกำหนดค่า Android Tag Manager ขั้นสูง
หากต้องการขยายฟังก์ชันการทำงานของ Google Tag Manager ให้เพิ่มตัวแปรการเรียกใช้ฟังก์ชันและแท็กการเรียกใช้ฟังก์ชัน ตัวแปรการเรียกใช้ฟังก์ชันช่วยให้คุณบันทึกค่าที่แสดงผลจากการเรียกฟังก์ชันที่บันทึกไว้ล่วงหน้าได้ แท็กการเรียกฟังก์ชันช่วยให้คุณเรียกใช้ฟังก์ชันที่ลงทะเบียนล่วงหน้าได้ (เช่น เพื่อเรียกใช้ Hit สําหรับเครื่องมือการวัดและรีมาร์เก็ตติ้งเพิ่มเติมซึ่งปัจจุบันยังไม่รองรับเทมเพลตแท็กใน Tag Manager)
วิธีเพิ่มแท็กที่กำหนดเองหรือตัวแปรที่กำหนดเองที่มีการเรียกใช้ฟังก์ชัน
ใช้คลาสที่ขยาย com.google.android.gms.tagmanager.CustomTagProvider
หรือ 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);
}
}
}
หากคุณใช้ ProGuard โปรดดูให้แน่ใจว่าชื่อและเมธอดคลาสไม่มีความสับสน ใช้คำอธิบายประกอบของ Keep เพื่อระบุข้อมูลนี้
ในอินเทอร์เฟซเว็บของ Google Tag Manager ให้ใช้ชื่อคลาสแบบเต็มที่สมบูรณ์เพื่อตั้งค่าแท็กและตัวแปร ดังนี้

เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-11-08 UTC
[null,null,["อัปเดตล่าสุด 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"]]