Created
July 7, 2016 19:05
-
-
Save jirawatee/8e0998682831d6327e0e1cc42a8b3cd4 to your computer and use it in GitHub Desktop.
Firebase Analytics - MainActivity.java
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
package com.example.fanalytics; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import com.google.firebase.analytics.FirebaseAnalytics; | |
public class MainActivity extends AppCompatActivity { | |
private FirebaseAnalytics mFirebaseAnalytics; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Initialize | |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); | |
// Set user property | |
mFirebaseAnalytics.setUserProperty("favorite_food", "Noodle"); | |
} | |
// android:onClick="sendPredefineEvent" in Button | |
public void sendPredefineEvent(View view) { | |
Bundle bundle = new Bundle(); | |
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "12345"); | |
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "Nougat"); | |
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Image"); | |
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); | |
} | |
// android:onClick="sendCustomEvent" in Button | |
public void sendCustomEvent(View view) { | |
Bundle params = new Bundle(); | |
params.putString("image_name", "android.png"); | |
params.putString("full_text", "Android 7.0 Nougat"); | |
mFirebaseAnalytics.logEvent("share_image", params); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment