简体   繁体   English

自定义指标不起作用| 谷歌分析

[英]Custom Metrics not working | Google Analytics

Here is my Java file that defines my tracker : 这是定义跟踪器的Java文件:

    package com.example.anantchowdhary.simpletodo;

import android.app.Application;
import android.content.pm.ApplicationInfo;

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

/**
 * Created by anantchowdhary on 18/09/16.
 */
public class MyApplication extends Application {
    public Tracker mTracker;
    public void startTracking()
    {

            if(mTracker==null)
            {
                GoogleAnalytics ga = GoogleAnalytics.getInstance(this);

                mTracker = ga.newTracker(R.xml.track_app);

                ga.enableAutoActivityReports(this);

                //ga.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);


// Send the custom dimension value with a screen view.
// Note that the value only needs to be sent once.
                mTracker.send(new HitBuilders.ScreenViewBuilder()
                        .setCustomMetric(1, 5)
                        .build()
                );
            }

    }

    public Tracker getTracker()
    {


           startTracking();

            return mTracker;

    }

}

The MainActivity file is : MainActivity文件是:

package com.example.anantchowdhary.simpletodo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;




import com.example.anantchowdhary.simpletodo.R;

import java.util.ArrayList;

public class MainActivity extends Activity

{


    private ArrayList<String> items;
    private ArrayAdapter<String> itemsAdapter;
    private ListView lvItems;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // ADD HERE
        lvItems = (ListView) findViewById(R.id.lvItems);
        items = new ArrayList<String>();
        itemsAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, items);
        lvItems.setAdapter(itemsAdapter);
        items.add("First Item");
        items.add("Second Item");

        ((MyApplication)getApplication()).getTracker();

    }

    public void onAddItem(View v) {
        EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
        String itemText = etNewItem.getText().toString();

        items.add(etNewItem.getText().toString());
        etNewItem.setText("");
    }
}

Now I do know that hits are passing on to Google Analytics, since I can see active users(1) in my Real Time Analytics Dashboard on GA. 现在,我确实知道点击量正在传递给Google Analytics(分析),因为我可以在GA的“实时分析”信息中心中看到活跃的用户(1)。 And this is as soon as I enter the app. 这是我一进入应用程序。

However, my custom metric ( with index 1) still displays 0. 但是,我的自定义指标(索引为1)仍然显示0。

Would really appreciate help with this ! 非常感谢您的帮助!

A few things might be happening: 可能正在发生一些事情:

  1. You're not passing the custom metric to Google Analytics 您没有将自定义指标传递给Google Analytics(分析)
  2. You're passing it but you have a configuration issue that's filtering it out 您正在传递它,但是有一个配置问题正在将其过滤掉

Try using the Google Analytics Tag Recording tool to record a session on your site and see if the custom metric is being passed to Google Analytics, to help figure out where your problem is. 尝试使用Google Analytics(分析)标记记录工具来记录您网站上的会话,并查看自定义指标是否已传递给Google Analytics(分析),以帮助确定问题出在哪里。

Quick training video 快速培训视频

Get Chrome Extension 获取Chrome扩展程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM