实现谷歌标签管理到安卓 [英] Implementing Google Tag Manager into Android

查看:516
本文介绍了实现谷歌标签管理到安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按照这个教程来实现谷歌标签管理: https://开头developers.google.com/tag-manager/android/v4/

I am trying to implement Google Tag Manager by following this tutorial: https://developers.google.com/tag-manager/android/v4/

当我运行应用程序,我在控制台得到这些错误:

When I run the application, I get in the console these errors :

    05-22 12:27:44.490    V/GoogleTagManager﹕ Attempting to load a container from the resource ID 2131099650 (testconverteo.ismail.converteotag:raw/gtm_default_container)
    05-22 12:27:44.520    E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
    05-22 12:27:44.520    V/GoogleTagManager﹕ loadAfterDelay: containerId=GTM-XXXXX delay=29397190
    05-22 12:27:44.530    E/GoogleTagManager﹕ Invalid macro: _gtm.loadEventEnabled
    05-22 12:27:44.490    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

和我在谷歌Analytics(分析)没有实时数据,更没有这证明我的应用程序跟踪。

And I have no data in Google Analytics in real time, even more nothing which proves that my application is tracked.

如果有人有过同样的问题,或者他遵循相同的步骤,并知道如何解决这个问题,请留下评论中的解释。

If anybody has had the same problem , or he had followed the same steps and knows how to resolve this issue, please leave an explanation in comment.

我做的步骤:

  • 在我设置的是谷歌播放服务SDK由builde.gradle(模块:应用程序)增加这部分的code: 编译com.google.android.gms:玩-服务:7.3.0
  • 我添加权限AndroidManifest.xml文件
  • 我下载并添加默认容器二进制应用程序
  • 在我按照教程的方式创建一个启动画面的活动,我初始化GTM
  • 我已经把事件变成dataLayer
  • I set up the Google Play Services SDK by adding in the builde.gradle (module: app) this part of code: compile 'com.google.android.gms:play-services:7.3.0'
  • I add the permissions to the AndroidManifest.xml file
  • I download and add a default container binary to the application
  • I Create a splash screen activity where I initialize GTM by following the tutorial’s pattern
  • I’ve pushed an event into a dataLayer

我目前在我的闪屏的活动如下:

What I currently have in my splash screen activity is the following:

public class SplashScreenActivity extends Activity {

    private static final String CONTAINER_ID = "GTM-XXXX";

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);

        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) {
                ContainerHolderSingleton.setContainerHolder(containerHolder);
                Container container = containerHolder.getContainer();
                if (!containerHolder.getStatus().isSuccess()) {
                    Log.e("IL", "failure loading container");
                    return;
                }
                ContainerHolderSingleton.setContainerHolder(containerHolder);
            ContainerLoadedCallback.registerCallbacksForContainer(container);
            containerHolder.setContainerAvailableListener(new ContainerLoadedCallback());
                startMainActivity();
            }
        }, 2, TimeUnit.SECONDS);
    }

    private void startMainActivity() {
        Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
        startActivity(intent);
    }

    private static class ContainerLoadedCallback implements ContainerHolder.ContainerAvailableListener {
        @Override
        public void onContainerAvailable(ContainerHolder containerHolder, String containerVersion) {
            // We load each container when it becomes available.
            Container container = containerHolder.getContainer();
            registerCallbacksForContainer(container);
        }

        public static void registerCallbacksForContainer(Container container) {
            // Register two custom function call macros to the container.
            container.registerFunctionCallMacroCallback("increment", new CustomMacroCallback());
            container.registerFunctionCallMacroCallback("mod", new CustomMacroCallback());
            // Register a custom function call tag to the container.
            container.registerFunctionCallTagCallback("custom_tag", new CustomTagCallback());
        }

    }

}

和在主要活动:

public void onStart() {
    super.onStart();
    DataLayer dataLayer = TagManager.getInstance(this).getDataLayer();
    dataLayer.pushEvent("Application ouverte", DataLayer.mapOf("login page","un de plus"));
}

和我还创建了这个类:

public class ContainerHolderSingleton {

    private static ContainerHolder containerHolder;

    /**
     * Utility class; don't instantiate.
     */
    private ContainerHolderSingleton() {
    }

    public static ContainerHolder getContainerHolder() {
        return containerHolder;
    }

    public static void setContainerHolder(ContainerHolder c) {
        containerHolder = c;
    }
}

请注意,我已经隐藏了谷歌标签管理器的容器ID

Please note I've hidden the Google Tag Manager container ID

让我知道,如果有人想了解更多信息

Let me know if anybody wants more information

感谢您

推荐答案

替换线 编译com.google.android.gms:玩-服务:7.3.0编译com.google.android.gms:玩-服务:7.0.0 要么 编译com.google.android.gms:玩 - 服务 - 分析:7.0.0(那更好,因为它仅仅包括GA和GTM相关的东西)

Replace line compile 'com.google.android.gms:play-services:7.3.0' with compile 'com.google.android.gms:play-services:7.0.0' or compile 'com.google.android.gms:play-services-analytics:7.0.0' (that's even better as it just includes ga and gtm related stuff)

我很幸运地开始7.0.0,看到GTM的工作。然后升级到7.3.0,它只是停止工作。这可能是固定的新克库。

I was lucky enough to start with 7.0.0 and saw gtm working. Then upgraded to 7.3.0 and it just stopped working. It might be fixed with new gms lib.

所有这些假设你已经配置你的容器。如果不详细了解这里的https://support.google.com/tagmanager/answer/6103657?hl=en&ref_topic=3441530

All that assuming you've configured your container. If not read more about that here https://support.google.com/tagmanager/answer/6103657?hl=en&ref_topic=3441530

这篇关于实现谷歌标签管理到安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆