Android 谷歌分析 xml 文件 [英] Android Google Analytics xml file

查看:22
本文介绍了Android 谷歌分析 xml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读新的 谷歌 Android 分析教程这很奇怪,首先当我在我的 gradle 中添加这个字符串时:

I am reading a new google tutorial for Android analytics and it's strange, first of all when I add this strings in my gradle:

classpath 'com.google.gms:google-services:1.3.0-beta1'
apply plugin: 'com.google.gms.google-services'

我无法同步我的项目(未找到插件错误).不知道重要不重要.我只能添加compile 'com.google.android.gms:play-services-analytics:7.3.0'.其次,在教程中有一个步骤,我应该将应用程序子类化:

I can't sync my project (plugin not found error). I don't know is it important or not. I only can add compile 'com.google.android.gms:play-services-analytics:7.3.0'. And second, in tutorial there is a step where I should subclass Application:

package com.google.samples.quickstart.analytics;

import android.app.Application;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;

/**
 * This is a subclass of {@link Application} used to provide shared objects for this app, such as
 * the {@link Tracker}.
 */
public class AnalyticsApplication extends Application {
  private Tracker mTracker;

  /**
   * Gets the default {@link Tracker} for this {@link Application}.
   * @return tracker
   */
  synchronized public Tracker getDefaultTracker() {
    if (mTracker == null) {
      GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
      // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
      mTracker = analytics.newTracker(R.xml.global_tracker);
    }
    return mTracker;
  }
}

而且我不明白从哪里获得 R.xml.global_tracker 文件??我想我会使用我之前生成的 json 文件.有人遇到过这个问题吗?这很有趣,但对于 iOs 教程更好.

And I can't understand where to get R.xml.global_tracker file?? I thought that I will use json file, that I generated before. Have some1 faced this problem? It is funny, but for iOs tutorial was better.

更新

这种方法有更好的文档,如果some1 很有趣.

This approach has better documentation by the way, if some1 is interesting.

推荐答案

我同意你的看法.新文档不是很有帮助.

I agree with you. New documentation is not so helpful.

这是我的 Application 类,您所需要的只是,基本集成不需要任何其他东西.甚至不需要一个xml.在您需要的地方使用此跟踪器对象.

Here is my Application class and all you need is that, you don't need any other thing for basic integration. Even not need a xml. Use this tracker object where you want.

import android.app.Activity;
import android.content.Context;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import java.io.IOException;

public class Application extends android.app.Application {

    public static GoogleAnalytics analytics;
    public static Tracker tracker;

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

        analytics = GoogleAnalytics.getInstance(this);
        analytics.setLocalDispatchPeriod(1800);
        tracker = analytics.newTracker("UA-XXXXXX-X");
        tracker.enableExceptionReporting(true);
        tracker.enableAdvertisingIdCollection(true);
        tracker.enableAutoActivityTracking(true);
    }

}

还要在build.gradle"中保留com.google.android.gms:play-services-analytics:7.3.0"依赖项.

Also keep 'com.google.android.gms:play-services-analytics:7.3.0' dependency in your "build.gradle".

我认为我的回答不再有效.不要强迫,只使用 json 文件 :)

i think my answer is not valid anymore. Don't force and just use json file :)

这篇关于Android 谷歌分析 xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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