我在项目中实施Google跟踪代码管理器时遇到问题。我添加了库并在Google跟踪代码管理器控制台中创建了应用ID和容器文件,但该应用未注册事件。这是我的代码:
public class App extends Application {
private static final String TAG = App.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
loadTagmanager();
}
private void loadTagmanager() {
final TagManager tagManager = TagManager.getInstance(this);
tagManager.setVerboseLoggingEnabled(true);
PendingResult<ContainerHolder> pending = tagManager
.loadContainerPreferNonDefault(CONTAINER_ID, R.raw.gtm_default_container);
pending.setResultCallback(new ResultCallback<ContainerHolder>() {
@Override
public void onResult(ContainerHolder containerHolder) {
if (!containerHolder.getStatus().isSuccess()) {
Log.e(TAG, "GTM - Failure loading container");
} else {
Log.d(TAG, "GTM - Connected");
}
}
}, 2, TimeUnit.SECONDS);
}
}
注册事件的方法:
public static void pushOpenScreenEvent(Context context, String screenName) {
DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
dataLayer.pushEvent("openScreen", DataLayer.mapOf("screenName", screenName));
}