Google Analytics for Apps - 跟踪应用内的搜索字词。有任何想法吗?

时间:2013-07-04 13:26:34

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

我们差不多为我们的文件托管服务开发应用程序。该应用程序的主要用途是托管文件中的搜索引擎,但Google Analytics Mobile没有与网站搜索设置类似的功能。

有没有人知道如何跟踪搜索字词?

目前我只想将搜索查询作为屏幕名称推送,例如:mGaTracker.sendView("/search/SearchTerm") 并在一个配置文件上收集此数据并在另一个配置文件上过滤还有其他想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个: -

    private Tracker tracker;
// write code in on create of your activity

    tracker = GoogleAnalyticEntity.getInstance().getTracker();


//code for event
        tracker.sendEvent(ConstantLib.HmeScreen, ConstantLib.PreLoginScreen,


                "", 0l);
GoogleAnalyticEntity的代码: -

import android.app.Activity;
import android.content.Context;

import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.Tracker;

public class GoogleAnalyticEntity {

    public Tracker tracker;
    Context context;
    public static EasyTracker easytracker;
    private static GoogleAnalyticEntity instance;

    public static GoogleAnalyticEntity getInstance() {
        if (null == instance) {
            instance = new GoogleAnalyticEntity();

        }
        return instance;
    }

    public static void setInstance(GoogleAnalyticEntity instance) {
        GoogleAnalyticEntity.instance = instance;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        EasyTracker.getInstance().setContext(context);

        this.context = context;
    }

    public void startTracker(Activity activity) {
        EasyTracker.getInstance().activityStart(activity);

    }

    public void StopTracker(Activity activity) {
        EasyTracker.getInstance().activityStop(activity);

    }

    public static EasyTracker getEasytracker() {
        if (easytracker == null) {
            easytracker = EasyTracker.getInstance();
        }
        return easytracker;
    }

    public Tracker getTracker() {
        if (tracker == null) {
            tracker = EasyTracker.getTracker();
        }
        return tracker;
    }

    public static void setEasytracker(EasyTracker easytracker) {
        GoogleAnalyticEntity.easytracker = easytracker;
    }

    public void setTracker(Tracker tracker) {
        this.tracker = tracker;
    }

    public void sentevent(Context mContext, String category, String label,
            String action, long val) {
        tracker.sendEvent(category, action, label, val);
    }
}

在values文件夹中创建analytics.xml: -

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- Replace placeholder ID with your tracking ID -->
    <string name="ga_trackingId">UA-4XXXXXXX-1</string>

    <!-- Enable Activity tracking -->
    <bool name="ga_autoActivityTracking">true</bool>

    <!-- Enable debug -->
    <bool name="ga_debug">true</bool>

    <!-- The screen names that will appear in your reporting -->
    <string name="com.test.screen.PreLoginActivity">PreLogin Screen</string>

  <!--
   The inverval of time after all the collected data
   should be sent to the server, in seconds.
    -->
    <integer name="ga_dispatchPeriod">30</integer>

</resources>