我尝试在this guide之后的Android应用中实施跟踪代码管理器,但出于某种原因,我无法将事件推送到数据层。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TagManager tagManager = TagManager.getInstance(getApplicationContext());
TagManager.getInstance(getApplicationContext()).setVerboseLoggingEnabled(true);
PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferFresh(GOOGLE_TAG_MANAGER_CONTAINER_ID, R.raw.gtm_default_container_v2);
pending.setResultCallback(new ResultCallback<ContainerHolder>() {
@Override
public void onResult(ContainerHolder containerHolder) {
TagManager.getInstance(getApplicationContext()).getDataLayer().push("event", "screenName");
// Using the "pushEvent" method doesn't work either
// TagManager.getInstance(getApplicationContext()).getDataLayer().pushEvent("screenName", DataLayer.mapOf());
}
}, 2, TimeUnit.SECONDS);
}
当我尝试运行我的应用时,我的所有日志都在说这是
V/GoogleTagManager﹕ Attempting to load a container from the resource ID 2131099649 (com.example.cpe.gatestapp:raw/gtm_default_container_v2)
V/GoogleTagManager﹕ Deleted 0 expired items
W/GoogleTagManager﹕ Failed to extract the container from the resource file. Resource is a UTF-8 encoded string but doesn't contain a JSON container
V/GoogleTagManager﹕ The container was successfully loaded from the resource (using binary file)
E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
V/GoogleTagManager﹕ Attempting to load resource from disk
V/GoogleTagManager﹕ loadAfterDelay: containerId=GTM-XXXXXX delay=0
D/GoogleTagManager﹕ Setting previous container version: MQ$0
E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
V/GoogleTagManager﹕ The Disk resource was successfully read.
V/GoogleTagManager﹕ Start loading resource from network ...
V/GoogleTagManager﹕ Successfully loaded supplemented resource: zzi_p: "MQ$0"
V/GoogleTagManager﹕ No change for container: GTM-XXXXXX
V/GoogleTagManager﹕ loadAfterDelay: containerId=GTM-XXXXXX delay=43200000
D/GoogleTagManager﹕ Setting previous container version: MQ$0
E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
V/GoogleTagManager﹕ setting refresh time to current time: 1435818825632
V/GoogleTagManager﹕ Load resource from network finished.
我的GA和跟踪代码管理器帐户的屏幕截图:
答案 0 :(得分:1)
在我弄明白之后,我的问题的答案非常简单。
所以我创建了一个分析跟踪器,跟踪我的应用程序是否崩溃。我已经做了一个选择,如果我在调试模式下运行我的应用程序,也就是从AndroidStudio运行它,我的跟踪器将创建一个'dryRun'。
所以我认为TagManager正在使用Analytics跟踪器发送所有事件。这就是为什么它有助于在我的GoogleAnalytics追踪器上禁用dryRun。