I know how to start and end Sessions in flurry
I am also able to successfully see them in my Analytics section.
What I want to implement now is events for user clicks/views.
I have a media player which plays a file. I want to see how many users have played the file till end. How add such events inside a session for a user?
Initialize a FlurryAgent after onCreate() using:
FlurryAgent.init(YourClass.this, "YOUR_API_KEY");
Start / End your sessions using: (This will come in your activity class)
#Override
protected void onStart() {
super.onStart();
FlurryAgent.onStartSession(YourClass.this, "YOUR_API_KEY");
}
#Override
protected void onStop() {
super.onStop();
FlurryAgent.onEndSession(YourClass.this);
}
Now add this line where ever you want to log the event:
FlurryAgent.logEvent("Your_event_name");
To log events with some parameters, use:
HashMap<String, String> myMap = new HashMap<String, String>();
myMap.put("key", "value");
FlurryAgent.logEvent("even_name", myMap);
Hope this will help somebody.
NOTE: If you come across the two terms FlurryAgent.logEvent and FlurryAgent.onEvent, use .logEvent
.onEvent is deprecated. Reference here
Related
I'm following a three day coarse of firebase chat app on udemy here https://classroom.udacity.com/courses/ud0352
According to them, I've attached the authStateListener for authentication on the onCreate().
mAuthStateListener = FirebaseAuth.AuthStateListener {
val user: FirebaseUser? = it.currentUser
if (user != null) {
// User is signed in
onSignedInInitialized(user.displayName)
} else {
// User is signed out
onSignedOutCleanup()
}
}
Later the suggested removing the state listener on the onPause function and attaching it back on the onStart function without proper explanation.
override fun onPause() {
super.onPause()
if (mAuthStateListener !=null) {
mFirebaseAuth!!.removeAuthStateListener(mAuthStateListener!!)
}
detachDatabaseReadListener()
mMessageAdapter!!.clear()
}
override fun onResume() {
super.onResume()
mFirebaseAuth!!.addAuthStateListener(mAuthStateListener!!)
}
I'm new to Android dev and Firebase and still cannot figure out the purpose of removing the adapter and listener on these functions.
Since your activity isn't at all visible to the user at onStop, it makes sense to stop things that might cause something to happen in your app that the user can't see. Likewise, your activity is visible again during onStart, so you'd want to re-establish any behaviors that should be visible.
I suggest reading through the documentation for Android lifecycle callbacks to better understand what they're used for.
I am creating a digitsauthconfig like this:
private DigitsAuthConfig createDigitsAuthConfig() {
return new DigitsAuthConfig.Builder()
.withAuthCallBack(createAuthCallback())
.withPhoneNumber("+91")
.withThemeResId(R.style.CustomDigitsTheme)
.build();
}
Where authcallback is returned by:
private AuthCallback createAuthCallback() {
return new AuthCallback() {
#Override
public void success(DigitsSession session, String phoneNumber) {
doIfSuccessfulOtpVerification();
}
#Override
public void failure(DigitsException exception) {
doIfNotSuccessfulOtpVerification();
}
};
}
I initiate the process using a button with event listener:
digitsButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Digits.authenticate(createDigitsAuthConfig());
}
});
The problem is, once my phone number is verified, it goes back to the activity where the button is displayed and does nothing. Technically, the authcallback is never called, doesn't matter successful or not. But if I click the button again, the authcallback is called without repeating the verification step. So right now I am required to click the button twice.
What is the way around it?
Finally i got solution for that issue, May it will help you too also.
You need to remove the ActiveSession, before calling the setCallback(authCallback) like mentioned as below.It will remove the existing session(if you already entered your phone number and got an OTP) from digits. This session will will not allows you to make another session to generate an OTP. So, we have to remove it. And it will work if there is no any previous sessions.
DigitsAuthButton digitsButton = (DigitsAuthButton) findViewById(R.id.auth_button);
Digits.getSessionManager().clearActiveSession();
digitsButton.setCallback(((WyzConnectApp) getApplication()).getAuthCallback());
Digits changed the way it reference the AuthCallback passed in the Digits#authenticate call.
Now Digits holds a weak reference (to avoid a memory leak), unless you hold a strong reference, that AuthCallback will be garbage collected and the result of the flow will be never propagated.
You need to define the AuthCallback in the Application context and then use this callback in your activity and it should work.
Please check the documentation on how to do this
I know its late but may be helpful for a beginner.To verify that the session is already active, please put this code in your onCreate of that activity in which Digits phone number verification button is initialised:
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new TwitterCore(authConfig), new Digits.Builder().build());
if (Digits.getActiveSession() != null) {
Intent ss = new Intent(CurrentActivity.this, SecondActivity.class);
startActivity(ss);
finish();
}
I try to collect a custom metric from an Android application using Google Analytics SDK v3.
The doc says to do it like this :
// May return null if EasyTracker has not yet been initialized with a
// property ID.
EasyTracker easyTracker = EasyTracker.getInstance();
// Set the custom metric to be incremented by 5 using its index.
easyTracker.set(Fields.customMetric(1), 5);
// Custom metric value sent is with this screen view.
easyTracker.send(MapBuilder
.createAppView("Home screen")
.build()
);
https://developers.google.com/analytics/devguides/collection/android/v3/customdimsmets
However set(Fields.customMetric(1), 5); is undefined because only EasyTracker.set(String,String) exists. The documentation seems not up to date with the v3 SDK.
So here is what I tried instead :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onStart() {
super.onStart();
EasyTracker.getInstance(this).activityStart(this);
}
#Override
public void onStop() {
super.onStop();
EasyTracker.getInstance(this).activityStop(this);
}
public void onDetected()
{
EasyTracker easyTracker = EasyTracker.getInstance(this);
easyTracker.set(Fields.customMetric(1), "1"); //not working
easyTracker.send(MapBuilder
.createEvent("cat", "detected", "beacon", (long) 1) // also tried with createAppView
.set(Fields.customMetric(1), "1") // not working
.set("&cm1", "1") // not working
.build());
}
But none of this actually works. How can I collect custom metrics using Google Analytics Android SDK ?
Have you looked at using the method:
Tracker.setCustomMetric(int, long)
I have done something similar with a custom dimension and it worked for me (tracker.setCustomDimension(String, string)). Another gotcha that I ran into is that I had to make sure that the dimension was defined in the admin panel before GA would accept it.
I wish to get a bit more detailed statistic about my app instead of standart google statistic. I was advised to use flury. However I dont see tutorial how to integrate it to my app or use it. Can any one explain or give a link to tutorials?
Flurry works with an ID to open a session an retrieve infos. I'm using it and it's quite simple to use.
1 - Head to flurry.com and register your app, which will generate a unique tracking code.
2 - Download and add the FlurryAgent jar to your project libraries. If you're using Eclipse, right-click your project folder, select properties, select Java Build Path, and choose Add External JARs...
3 - Add android.permission.INTERNET to your AndroidManifest.xml.
4 - Add a call to the Flurry agent from the onStart() and onStop() methods of your activities.
Note: replace the ID below with your unique tracking code.
public void onStart()
{
super.onStart();
FlurryAgent.onStartSession(this, "9GKQD4EBX123FEP6874H");
// your code
}
public void onStop()
{
super.onStop();
FlurryAgent.onEndSession(this);
// your code
}
See the answer here
1st you need to download Flurry agent.jar
and add this to your lib folder after that
do the following in following methods
private void getFlurryEvents()
{
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("Title of page", "Your page Title" );
FlurryAgent.logEvent("View Page",parameters);
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
FlurryAgent.onStartSession(this, Constants.FLURRY_API_KEY);
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
//FlurryAgent.onEndSession(this);
}
in onstart method strt the Session and in on stop stop the session and in oncreate add the method getFlurry agent
and get your API key from flurry
I want to add statistic in my android application.
Read article http://code.google.com/intl/ru/apis/analytics/docs/mobile/android.html#startingTheTracker and done below
1 added library libGoogleAnalytics.jar in my application
2 added in manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
3 changed source code
private GoogleAnalyticsTracker tracker;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tracker = GoogleAnalyticsTracker.getInstance();
// Start the tracker in manual dispatch mode...
tracker.startNewSession(GOOGLE_ANALYTICS, this);
tracker.trackPageView("/MainListView");
...
protected void onDestroy() {
super.onDestroy();
tracker.stopSession();
}
4 I created "fake" site for application (https://sites.google.com/site/balancetransportcardkazan/ :) )
5 registered site in https://www.google.com/analytics/,
constant GOOGLE_ANALYTICS is for this site.
statistic is empty, What I forgot to do?
You have to dispatch the changes to the server. Here is an excerpt from my wrapper class around GoogleTracker to make it easier for me.
public void trackPageView(String page) {
tracker.trackPageView( packageName + "/" + getVersionCode() + "/" + page );
tracker.dispatch();
}
public void trackEvent(String action, String label, int count) {
tracker.trackEvent( packageName, action, label, count );
tracker.dispatch();
}
public void trackEvent(String action) {
tracker.trackEvent(packageName, action, null, 0 );
tracker.dispatch();
}
As mentioned by chubbard You need to dispatch the events to get it tracked. check your logs whether requests are sent to GA server. As i have seen it usually takes around 4-5 hours for statistics to get updated. While viewing the report ensure the report date is current date. By default the report will be shown for yesterday.
I think for getting statics of your android app, you should implement google analytics code into all your classes/functions of the your app.
I think below link can help you for How to implement Google Analytics for android app -
http://www.tatvic.com/blog/android-application-tracking-through-google-analytics/