谷歌分析不报告在Android应用程序

2016-01-08 android google-analytics

我正在尝试使用以下教程将Google Analytics(分析)实施到我的android应用中: https : //developers.google.com/analytics/devguides/collection/android/v4/

在活动中,我尝试发送事件,但我的GA个人资料中没有任何反应:

Dictum application = (Dictum) getApplication();
mTracker = application.getDefaultTracker();
                mTracker.setScreenName("Main");
                mTracker.send(new HitBuilders.EventBuilder()
                        .setCategory("Tutorial")
                        .setAction("0")
                        .build());

manifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="su.worldbest.dictum" >

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.android.vending.BILLING" />




    <application
        android:name=".Dictum"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
...

Build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.google.gms:google-services:1.4.0-beta3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Build.gradle(模块:应用程序)

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "su.worldbest.dictum"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 2
        versionName "1.1"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.jjoe64:graphview:4.0.1'
    compile 'com.daimajia.swipelayout:library:[email protected]'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.android.gms:play-services-analytics:8.1.0'
    compile 'com.github.asne:asne-facebook:0.3.3'
    compile 'com.github.asne:asne-instagram:0.3.3'
    compile 'com.github.asne:asne-vk:0.3.3'
}

应用类别:

public class Dictum 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.analytics);
        }
        return mTracker;
    }
}

analytics.xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">

    <!--Replace placeholder ID with your tracking ID-->
    <string name="ga_trackingId">UA-XXXXXXXX-3</string>
//here i placed real track


    <!--Enable automatic activity tracking-->
    <bool name="ga_autoActivityTracking">true</bool>

    <!--Disable automatic exception tracking-->
    <bool name="ga_reportUncaughtExceptions">false</bool>

</resources>

另外,我生成了google-services.json文件并将其放在/ app文件夹中。

我做错了什么?

Answers

更改:

mTracker = analytics.newTracker(R.xml.analytics);

至:

mTracker = analytics.newTracker(R.xml.global_tracker);
mTracker.enableAutoActivityTracking(true);
mTracker.enableExceptionReporting(false);

Related