使用GTM for Android的GA中没有数据..?

时间:2016-05-25 12:12:04

标签: android google-analytics google-tag-manager google-analytics-v4

有人可以帮帮我..?

GA中没有捕获数据。我使用GTM for Android(最新版本),我已经做了以下事情:

  • 设置Google Play服务SDK并添加对Android清单文件的权限。
  • 为项目添加了默认的GTM容器(二进制)。
  • Google最新支持页面初始化GTM。
  • 将事件和价值推送到dataLayer。
  • 我已经使用正确的标签,触发器和变量名称以及配置设置了GTM。

这是目前使用的大部分代码:

启动活动

public class SplashActivity extends AppCompatActivity {
    private static final long TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS = 2000;
    private static final String CONTAINER_ID = "GTM-XXXXXX";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TagManager tagManager = TagManager.getInstance(this);

        if (Environment.get() != BaseEnvironment.PRODUCTION) {
            tagManager.setVerboseLoggingEnabled(true);
        }

        PendingResult<ContainerHolder> pending = tagManager.loadContainerPreferNonDefault(CONTAINER_ID, R.raw.gtm_xxxxxx);

        pending.setResultCallback(new ResultCallback<ContainerHolder>() {
            @Override
            public void onResult(ContainerHolder containerHolder) {
                ContainerHolderSingleton.setContainerHolder(containerHolder);

                if (! containerHolder.getStatus().isSuccess()) {
                    return;
                }

                Intent intent = new Intent(SplashActivity.this, NavigationActivity.class);
                startActivity(intent);

            }
        }, TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS, TimeUnit.MILLISECONDS);
    }
}

信息活动

@Override
public void onStart() {
    super.onStart();

    TagUtils.pushOpenScreenEvent(this, "Informatie");
}

@Override
protected void onStop() {
    super.onStop();

    TagUtils.pushCloseScreenEvent(this, "Informatie");
}

TagUtils

/**
 * Push an "openScreen" event with the given screen name. Tags that match that event will fire.
 */
public static void pushOpenScreenEvent(Context context, String screenName) {
    DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
    dataLayer.pushEvent("openScreen", DataLayer.mapOf(
            "screenName", screenName,
            "appVersion", appVersionName(context),
            "operatingSystem", systemVersion()
    ));
}

/**
 * Push a "closeScreen" event with the given screen name. Tags that match that event will fire.
 */
public static void pushCloseScreenEvent(Context context, String screenName) {
    DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
    dataLayer.pushEvent("closeScreen", DataLayer.mapOf(
            "screenName", screenName,
            "appVersion", appVersionName(context),
            "operatingSystem", systemVersion()
    ));
}

/**
 * Push a "scanProduct" event with the given screen name. Tags that match that event will fire.
 */
public static final String ACTION_PRODUCT_FOUND = "Product gevonden";
public static final String ACTION_PRODUCT_NOT_FOUND = "Product niet gevonden";
public static final String ACTION_PRODUCT_NOT_FOUND_CONNECTION_ISSUES = "Product niet opgehaald door verbindingsproblemen";

public static void pushScanProductEvent(Context context, String action, String code) {
    DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
    dataLayer.pushEvent("scanProduct", DataLayer.mapOf(
            "Category", "Scan",
            "Action", action,
            "Label", code
    ));
}

清单

    <activity
        android:name="com.google.android.gms.tagmanager.PreviewActivity"
        android:label="@string/app_name"
        android:noHistory="true">

        <intent-filter>
            <data android:scheme="tagmanager.c.nl.everybodylikespenguins" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE"/>
        </intent-filter>

    </activity>

请注意我隐藏了容器文件ID和数据android:scheme =&#34; tagmanager.c.nl.everybodylikespenguins&#34; 确实是接受构建的正确名称应用程序(Google也在其示例中使用此功能)。

1 个答案:

答案 0 :(得分:0)

看起来你没有在onResult回调中调用containerHolder.getContainer()。激活容器需要调用getContainer。