Android应用程序未向分析服务器

时间:2015-08-27 17:32:59

标签: android google-analytics

我正在尝试为我的某个应用程序实施Google Analytics,并且在尝试时文件中没有错误,但没有数据发送到服务器。

我在log cat中找到了以下行

W/GAv4﹕ AnalyticsReceiver is not registered or is disabled. Register the receiver for reliable dispatching on non-Google Play devices. See http://goo.gl/8Rd3yj for instructions.
W/GAv4﹕ CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.
I/MainActivity﹕ Setting screen name:
W/GAv4﹕ AnalyticsService not registered in the app manifest. Hits might not be delivered reliably. See http://goo.gl/8Rd3yj for instructions.

我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dell.testanalytics" >

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:name=".AnalyticsApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>



</manifest>

需要跟踪的主要活动

package com.example.dell.testanalytics;


import java.util.Locale;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;


public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    private ViewPager mViewPager;

    private Tracker mTracker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // [START shared_tracker]
        // Obtain the shared Tracker instance.
        AnalyticsApplication application = (AnalyticsApplication) getApplication();
        mTracker = application.getDefaultTracker();
        // [END shared_tracker]

        // Create the adapter that will return a fragment for each image.

        // Set up the ViewPager with the pattern adapter.

        // When the visible image changes, send a screen view hit.


        // Send initial screen screen view hit.
        sendScreenImageName();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }


    private void sendScreenImageName() {


        // [START screen_view_hit]
        Log.i(TAG, "Setting screen name: ");
        mTracker.setScreenName("Image~");
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
        // [END screen_view_hit]
    }

    }

我的分析应用程序文件

  package com.example.dell.testanalytics;
    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;


    public class AnalyticsApplication extends Application {
        private Tracker mTracker;

        synchronized public Tracker getDefaultTracker() {
            if (mTracker == null) {
                GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);

                mTracker = analytics.newTracker(R.xml.global_tracker);
            }
            return mTracker;
        }
    }

此外,我注意到全局tracker.xml文件是自动生成的,它不允许我创建我选择的全局tracor。

希望得到你的帮助。

1 个答案:

答案 0 :(得分:1)

您可能需要在androidmanifest中添加这些设置

 <!-- Used for Google Play Store Campaign Measurement-->
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
          android:exported="true">
  <intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

 <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
     android:enabled="true">
     <intent-filter>
         <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
     </intent-filter>
 </receiver>
 <service android:name="com.google.android.gms.analytics.AnalyticsService"
     android:enabled="true"
     android:exported="false"/>