Last active
December 19, 2015 09:09
-
-
Save tomoyamkung/5930926 to your computer and use it in GitHub Desktop.
[Android]Google Analytics へのトラッキングを行うクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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