自定义指标不工作|谷歌分析 [英] Custom Metrics not working | Google Analytics
问题描述
这是我的Java文件,它定义了我的跟踪器:
Here is my Java file that defines my tracker :
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;
}
}
MainActivity文件是:
The MainActivity file is :
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("");
}
}
现在我知道点击量正在传递给Google分析,因为我可以在GA上的实时分析仪表板中看到活跃用户(1)。这是我一进入应用程序。
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. And this is as soon as I enter the app.
但是,我的自定义指标(索引为1)仍然显示为0.
However, my custom metric ( with index 1) still displays 0.
真的很感谢帮助!
推荐答案
有些事情可能会发生:
- 您未将自定义指标传递给Google Analytics(分析)
- 您正在通过它,但您的配置问题是
将其过滤出来
- 您正在通过它,但您的配置问题是
- You're not passing the custom metric to Google Analytics
- You're passing it but you have a configuration issue that's filtering it out
尝试使用Google Analytics代码记录工具在您的网站上记录会话并查看自定义指标正在传递给Google Analytics,以帮助确定您的问题所在。
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.
这篇关于自定义指标不工作|谷歌分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!