Google Analytics屏幕视图和会话为零

时间:2015-11-19 11:21:14

标签: google-analytics

我在Android中实施了Google Analytics。它工作正常,但屏幕视图和会话为零。它已超过12小时,其他所有内容都被跟踪,我可以看到除屏幕视图和会话之外的数据

主要活动:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    progressDialog = new ProgressDialog(MainActivity.this);//prikaz progres dialoga
    tracker = ((BornToInvestApplication) getApplication())
            .getTracker(TrackerName.APP_TRACKER);

//call MD5Hash class from Utils package and call md5 method for has android_id

    //set user id on google analitycs
    android_id= Settings.Secure.getString(this.getContentResolver(),
            Settings.Secure.ANDROID_ID);
    // You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
    // sent with all subsequent hits.
  //  String dimensionValue = "SOME_DIMENSION_VALUE";
  // tracker.set(Fields.customDimension(1), dimensionValue);//we can't reconize Fields??????

//call method md5 form md object
    tracker.set("&uid", md.md5(android_id));
    tracker.set("&cd1", md.md5(android_id));

}

//tracking next story with GA in NewspageFragment

MainActivity.tracker.send(new HitBuilders.EventBuilder()
                    .setCategory(AnalyticsEventsConsts.NEXT_STORY_EVENT)
                    .setAction(allnewsObj.get(pos).getTitle())
                    .setLabel(AnalyticsEventsConsts.STORY_PARAMETER)
                    .build());

类别:

import android.app.Application;
import android.content.pm.ApplicationInfo;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import android.provider.Settings.Secure;

import org.json.JSONException;
import org.json.JSONObject;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;

public class MyClassApplication extends Application {

    // The following line should be changed to include the correct property id.
    private static final String PROPERTY_ID = "UA-XXX-3"; // client
    private static  String android_id="";
    private DataManager dataManager;

    public static int GENERAL_TRACKER = 0;

    public enum TrackerName {
        APP_TRACKER, // Tracker used only in this app.
        GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg:
        // roll-up tracking.
        ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a
        // company.
    }

    HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();


    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        dataManager = new DataManager(getApplicationContext());
        //call MD5Hash class for hash android_id
        MD5Hash md = new MD5Hash();
        android_id=Secure.getString(this.getContentResolver(),
                Secure.ANDROID_ID);
    }


    //set GA tracker when stays in documentation of GA
    public synchronized Tracker getTracker(TrackerName trackerId) {
        if (!mTrackers.containsKey(trackerId)) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics
                    .newTracker(PROPERTY_ID)
                    : (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics
                    .newTracker(R.xml.global_tracker) : analytics
                    .newTracker(R.xml.ecommerce_tracker);
            mTrackers.put(trackerId, t);

        }
        return mTrackers.get(trackerId);
    }

}

这是数据: enter image description here

1 个答案:

答案 0 :(得分:0)

您只发送事件,因此预计您没有屏幕视图数据。

要跟踪需要调用跟踪器的屏幕视图,请设置屏幕名称然后发送。

这是这样的:

// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);

// Set screen name.
t.setScreenName(screenName);

// Send a screen view.
t.send(new HitBuilders.ScreenViewBuilder().build());

有关详细信息,您可以访问Google Developers Docs here

希望我帮助过你。