问题
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;
}
}
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("");
}
}
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.
However, my custom metric ( with index 1) still displays 0.
Would really appreciate help with this !
回答1:
A few things might be happening:
- 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
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.
Quick training video
Get Chrome Extension
来源:https://stackoverflow.com/questions/39839758/custom-metrics-not-working-google-analytics