Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
Last active December 19, 2015 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyamkung/5930926 to your computer and use it in GitHub Desktop.
Save tomoyamkung/5930926 to your computer and use it in GitHub Desktop.
[Android]Google Analytics へのトラッキングを行うクラス
/**
* Google Analytics へのトラッキングを行うクラス。
*
* @author tomoyamkung
*
*/
public class GoogleAnalyticsTrack {
private Tracker tracker;
/**
* コンストラクタ。
*
* @param activity Google Analytics へトラッキングを送信する画面のアクティビティ
*/
public GoogleAnalyticsTrack(Activity activity) {
GoogleAnalytics instance = GoogleAnalytics.getInstance(activity);
tracker = instance.getTracker(getGoogleAnalyticsPropertyID(activity));
}
/**
* Google Analytics へのトラッキングに必要な「プロパティID」を取得する。
*
* プロパティID 自体は strings.xml に定義してある。
*
* @param activity Google Analytics へトラッキングを送信する画面のアクティビティ
* @return プロパティID
*/
private String getGoogleAnalyticsPropertyID(BaseActivity activity) {
return activity.getString(R.string.ga_property_id);
}
/**
* トラッキング情報を送信する。
*
* @param message 送信メッセージ
*/
public void send(String message) {
tracker.sendView(message);
}
/**
* イベント情報を送信する。
*
* @param category
* @param action
* @param label
* @param value
*/
public void sendEvent(String category, String action, String label, long value) {
tracker.sendEvent(category, action, label, value);
GAServiceManager.getInstance().dispatch();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment