การกำหนดค่า 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"],[[["\u003cp\u003eFunction Call variables enable capturing values from pre-registered function calls, extending Google Tag Manager's capabilities.\u003c/p\u003e\n"],["\u003cp\u003eFunction Call tags allow execution of pre-registered functions, such as triggering hits for unsupported measurement tools.\u003c/p\u003e\n"],["\u003cp\u003eCustom tags and variables can be added by implementing a class extending \u003ccode\u003eCustomTagProvider\u003c/code\u003e or \u003ccode\u003eCustomVariableProvider\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eProGuard users should prevent obfuscation of custom class names and methods using the Keep annotation.\u003c/p\u003e\n"],["\u003cp\u003eWithin the Google Tag Manager interface, use the fully qualified class name to configure the custom tags and variables.\u003c/p\u003e\n"]]],["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"],null,["# Advanced Android Tag Manager configuration\n\nTo extend the functionality of Google Tag Manager, you can add Function Call\nvariables and Function Call tags. Function Call variables let you capture the\nvalues returned by calls to pre-registered functions. Function Call tags let you\nexecute pre-registered functions (e.g., to trigger hits for additional\nmeasurement and remarketing tools that are not currently supported with tag\ntemplates in Tag Manager).\n\nAdd custom tags and variables\n-----------------------------\n\nTo add a custom tag or custom variable with a Function Call:\n\n1. Implement a class that extends\n `com.google.android.gms.tagmanager.CustomTagProvider` or\n `com.google.android.gms.tagmanager.CustomVariableProvider`:\n\n import android.support.annotation.Keep;\n import java.util.Map;\n\n @Keep\n public class HighScoreProvider implements com.google.android.gms.tagmanager.CustomVariableProvider {\n @Override\n public String getValue(Map\u003cString, Object\u003e map) {\n synchronized (HighScoreProvider.class) {\n return ((Long)sHighScore).toString();\n }\n }\n\n private static long sHighScore = 0;\n public static void recordScore(long score) {\n synchronized (HighScoreProvider.class) {\n sHighScore = Math.max(score, sHighScore);\n }\n }\n }\n\n2. If you use [ProGuard](https://developer.android.com/tools/help/proguard.html), make sure that the class names and methods are not\n obfuscated. Use the Keep annotation to specify this.\n\n3. In Google Tag Manager's web interface, use the fully qualified class name\n to set up tags and variables:"]]