Google Analytics(分析) - 跟踪未知

时间:2010-11-08 14:06:18

标签: android google-analytics analytics google-analytics-api

我按照Google Analytics SDK for Android documentation中的指示创建了一个测试Google Analytics示例应用,并且我已使用以下代码在我的代码中启动了跟踪:

tracker = GoogleAnalyticsTracker.getInstance();
tracker.trackEvent(
            "Clicks",  // Category
            "Button",  // Action
            "clicked", // Label
            77);  

tracker.trackPageView("/HomeScreen");
tracker.dispatch();

我已创建Google Analytics帐户,在我的帐户中,如果转到Google Analytics设置标签。我的状态为“跟踪未知”

我尝试点击修改并点击检查状态,然后我也是“未安装跟踪”

参考我的代码是:

public class GAnalytics extends Activity {

  GoogleAnalyticsTracker tracker;

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

    tracker = GoogleAnalyticsTracker.getInstance();
    tracker.start("UA-19487404-1",20, this);

    setContentView(R.layout.main);
    Button createEventButton = (Button)findViewById(R.id.NewEventButton);
    createEventButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        tracker.trackEvent(
            "Clicks",  // Category
            "Button",  // Action
            "clicked", // Label
            77);       // Value
      }
    });

    Button createPageButton = (Button)findViewById(R.id.NewPageButton);
    createPageButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        tracker.trackPageView("/HomeScreen");
      }
    });

    Button quitButton = (Button)findViewById(R.id.QuitButton);
    quitButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        finish();
      }
    });

    Button dispatchButton = (Button)findViewById(R.id.DispatchButton);
    dispatchButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        tracker.dispatch();
      }
    });
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    super.onDestroy();
    tracker.dispatch();
    tracker.stop();
  }
}

请指出我在哪里做错了。

3 个答案:

答案 0 :(得分:6)

您致电.getInstance()后是否启动了跟踪器? 像这样:

tracker.start("UA-YOUR-ACCOUNT-HERE", this);

您还需要调用以下内容将数据发送到Google Analytics:

tracker.dispatch();

答案 1 :(得分:2)

默认情况下,分析数据落后一天,您是否要修改报告日期以显示当天?如果是这样,请记住,30分钟的延迟并不罕见。

答案 2 :(得分:1)

参考下面的代码

public class TestActivity extends Activity {

   GoogleAnalyticsTracker tracker;


      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tracker = GoogleAnalyticsTracker.getInstance();

        // Start the tracker in manual dispatch mode...
        tracker.startNewSession("UA-33332745-1", this);

        setContentView(R.layout.main);
        Button createEventButton = (Button)findViewById(R.id.NewEventButton);
        createEventButton.setOnClickListener(new OnClickListener() {

          public void onClick(View v) {
            tracker.trackEvent(
                "Clicks",  // Category
                "Button",  // Action
                "clicked", // Label
                77);       // Value
          }
        });

        Button createPageButton = (Button)findViewById(R.id.NewPageButton);
        createPageButton.setOnClickListener(new OnClickListener() {

          public void onClick(View v) {       
            // Add a Custom Variable to this pageview, with name of "Medium" and value "MobileApp"
            tracker.setCustomVar(1, "Medium", "Mobile App");        
            tracker.trackPageView("/testApplicationHomeScreen");
          }
        });

        Button quitButton = (Button)findViewById(R.id.QuitButton);
        quitButton.setOnClickListener(new OnClickListener() {

          public void onClick(View v) {
            finish();
          }
        });

        Button dispatchButton = (Button)findViewById(R.id.DispatchButton);
        dispatchButton.setOnClickListener(new OnClickListener() {

          public void onClick(View v) {
            tracker.dispatch();
          }
        });
      }


      protected void onDestroy() {
        super.onDestroy();
        // Stop the tracker when it is no longer needed.
        tracker.stopSession();
      }
    }