Screen tracking support - Firebase 9.8 - android

According Firebase Android SDK Release Notes with 9.8 update we have screen tracking support with android screens and activities... The documentation says that this event works like that:
mFirebaseAnalytics.setCurrentScreen(activity,class_name,class_override_name);
In my case, I don't need overrides class name and I send null value... But i'm waiting 48h and my firebase analytics console doesn't show info about this event, any ideas?
Thanks in advance!

Another very important thing that I've noticed only after two days of intensive struggling: the setCurrentScreen method MUST be called on the UI thread.
I was only able to see that after looking for a light in the Firebase decompiled code:
#MainThread
#Keep
public final void setCurrentScreen(#NonNull Activity var1, #Size(min = 1L,max = 36L) #Nullable String var2, #Size(min = 1L,max = 36L) #Nullable String var3) {
//...
}
Whenever this method is called a event of type screen_view is logged.
And keep in mind the Firebase size restrictions. The maximum size of a screen name is 36 characters long.

First I had the same question: where is my event with current screen name on the Firebase dashboard?
I've called method mFirebaseAnalytics.setCurrentScreen(this, "MainActivity", null); with no result.
Thanks to the comment by Benoit I realized that this method indicates the value of implicit parameter that is automatically attached to any event you send.
That means it's not independent event, it's a parameter that will stick to all your events since you set it.
This will be useful if you have changing screens within single Activity. For example when you have multiple fragments with one hosting Activity. And you call this method in each fragment in onResume().
If you want to have distinct metric with the name of your screen - fire explicitly a new event for that.
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "screen");
params.putString(FirebaseAnalytics.Param.ITEM_NAME, "MainActivity");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, params);

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, "YOUR SCREEN NAME")
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle)
Also Firebase Analytic's screen tracking is automatic. No need for explicit separate event tracking.

Sets the current screen name, which specifies the current visual context in your app. This helps identify the areas in your app where users spend their time and how they interact with your app.
Note that screen reporting is enabled automatically and records the class name of the current Activity for you without requiring you to call this function. The class name can optionally be overridden by calling this function in the onResume callback of your Activity and specifying the screenClassOverride parameter.
If your app does not use a distinct Activity for each screen, you should call this function and specify a distinct screenName each time a new screen is presented to the user.
The name and classOverride remain in effect until the current Activity changes or a new call to setCurrentScreen is made. I will try to add this method to onResume Method. I do not know the result but i will share my experience.

firebaseAnalytics.setCurrentScreen(activity,screeenName,activity.getClass().getSimpleName());
firebaseAnalytics.setMinimumSessionDuration(100L);
params = new Bundle();
params.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "screen");
params.putString(FirebaseAnalytics.Param.ITEM_NAME, screeenName);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, params);
Try using setCurrentScreen as well as manual event fire as firebase doesn't send data immediately to the console...but if event is fired up..all the remaining data is sent to firebase..

Just call that method in onResume(), and check the tracking through DebugView. it worked for me.
Check out the documentation.

Related

How to detect user interaction with graphstream?

I am investigating the use of GraphStream on Android using
api 'com.github.graphstream:gs-ui-android:2.0-alpha'
api 'com.github.graphstream:gs-core:2.0-alpha'
I have managed to construct and display my Graph fine,
However I cannot see how to listen for user interactions on the nodes within my graph.
I need to display a Dialog when any node is clicked on by the user and display the specific nodes information.
I've tried setting a Listener on the org.graphstream.ui.android_viewer.AndroidViewer, however I never received any callbacks
I can drag the displayed nodes around the screen so I know there are default listeners, how to I add my own listeners though?
You can implement ViewerListener with the ViewerPipe like this :
ViewerPipe pipe = fragment.getViewer().newViewerPipe();
pipe.addAttributeSink( graph );
pipe.addViewerListener( this ); // this or any class which implements ViewerListener
pipe.pump();
You can get an exemple here : https://github.com/graphstream/gs-ui-android-test/blob/master/app/src/main/java/ui/graphstream/org/gs_ui_androidtestFull/Activity_TestArrows.java
And here to understand how ViewerPipe works : http://graphstream-project.org/doc/Tutorials/Graph-Visualisation/

Mandatory Settings Update

I am making one android app where one setting is must every user need to update that which is pincode.
So after successful login, if the user has not updated pincode yet, it needs to be updated mandatory before navigating to any other screen.
What is the best way to implement this? Any Ideas?
Update:
After answer, I meant to say that setting I will be fetching from firebase database as boolean flag. So my actual query is how to show that as a mandatory to get the user update? (i.e) either navigating to different activity or showing popup and getting the setting etc. I need UI design ideas.
What is the best practice?
It is not clear what is the point of this, and if you have a server side that controls that stuff, but I'll try to give a help.
If you have a Server controlling authentication:
On login, call the API of your service to check if has happened or not. You could save the answer in a "shared preference" (Android Documentation), so you don't call your API every time.
If you only want to have the application on a client side:
Use 1 to store values that indicate if the desired action was performed or not, which is verified right after the login.
EDIT:
If the action is mandatory, you could send the user to an activity to update the pin, this will happen until the action is performed.
Client side approach:
You can use SharedPreferences to persist a value, like a simple boolean, that will inform you if that the user already updated the pincode or not.
I would recommend you to perform the check in the onResume() of your Launcher Activity.
Putting it simple and explicit:
public static final String PREF_FILE_NAME = "PrefFileName";
public static final String PREF_IS_PIN_CODE_UPDATED = "PREF_IS_PIN_CODE_UPDATED";
#Override
protected void onResume() {
super.onResume();
SharedPreferences prefs = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
Boolean isPinCodeUpdated = prefs.getBoolean(PREF_IS_PIN_CODE_UPDATED, false);
if (isPinCodeUpdated) {
// You can proceed
} else {
// Force the user to update the pin code, by prompting for instance a dialog where he can change the pin with setCancelable(false)
}
}
After you know that your user already updated the pin code you just need to set the preference to true.
SharedPreferences.Editor editor = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE).edit();
editor.putBoolean(PREF_IS_PIN_CODE_UPDATED, true);
editor.apply();
After this every time the user opens the app it will pass in the onResume() method and your isPinCodeUpdated var will be true and the app should proceed as usual.
From you question I am assuming that you didn't want a response in terms of UI but how could you have the information persisted.
Note: This implementation fails for multiple users in the same device. With few tweaks you can make it work for multiple users in the same device but in my opinion this verification should be done server side.

How to access BatteryManager's BATTERY_PROPERTY_CURRENT_NOW?

I'm trying to get the current from the API. There's a function at the bottom of the documentation (https://developer.android.com/reference/android/os/BatteryManager.html) called getIntProperty, so I presume that'd be the function I'd need. However, up to now I've been simply using the getIntExtra function on an ActionBatteryChanged intent, and that same method doesn't work for this. What do I need to do different?
That function is used to get the current value, not get updates like you do with a Broadcast and an Intent. You'd call batteryManager.getIntProperty(BATTERY_PROPERTY_CURRENT_NOW) to get the value. Any of the BATTERY_PROPERTY_X constants could work, but not every phone supports all of them.
A more comprehensive code samples:
Declare this at the class level
private BatteryManager mBatteryManager = null;
onCreate()
{
mBatteryManager = (BatteryManager) getSystemService(Context.BATTERY_SERVICE);
}
Create a timer and inside the timer routine, add this
int mBatteryCurrent = mBatteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW);
The current is in uA unit. a positive integer means drawing current out of
battery and a negative integer means charging current into battery.

GTM sets screenname to (not set)

I am trying to send screen-view hits to Google Analytics using Google Tag Manager, but in the real time view it is showing screenName value as (not set). Actual screenNames are also shown but along with them (not set) is also reported. Can someone please point out what I am missing.
The way I have set it up is to add a new tag to be able to track the screen-view separately:
----> Full config image example here <----
New tag in the GTM container with "Screen View" Track type
Add in "Fields to Set":
Field Name
screenName //Yes, exactly like that
Value
{{Item Name}} // Yes, exactly like that
Triggering: add a new trigger configuration with
Trigger Type
Custom
Trigger fires on
Some events
Event Name equals view_item
Then, on the Android tracking code:
Make sure you track it like this:
String yourScreenNameString = "Screen One"; //This is an example
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, yourScreenNameString);
_firebase.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle);
----> Example of how the GTM looks <----

How to pass String from onClick Edit Text field to Background task - Android

How can i take user input from popup dialogue and pass it into a BackGround Async Task?
I have a "createGarden" button. When i click it i want to retrieve a string from user, and pass it to my Background AsyncTask.
In my onClick, i have tried calling String myGardenName = getGardenName(), which returns input from dialogue. Then passing this into my Background task.
new HomeBackgroundTask().execute("create_garden", UserID_String,myGardenName );
I also tried using a value container, and passing this instead of "myGardenName":
String myGN = gnVC.getVal();
HomeBackgroundTask mhomebackgroundtask1 = new HomeBackgroundTask();
mhomebackgroundtask1.execute("create_garden", UserID_String, myGN);
instantiated my 'gardenValueContainer' value container as final in my "getGardenName()" method (enclosing class?) as well as instantiating it in my onCreate()
- I then try SETTING that value from within my onClick (inner class?)
--Also tried calling my HomeBackgroundTask directly from the onClick
Problem
Seems that my create garden always tries to insert a BLANK as the garden name. resulting in "garden "" already exists". When debugging, the user input get's passed through as a paramater, there was an issue with moving from "onPreExectute" to "doInBackground" but now when i'm debugging i get stuck in looper where i can't step over/into/out and my app just says freezes on connecting. (debug halts on a comment line, which might be bad?)
My php scripts work just fine with the same logic for registering a user.
No errors in my console!
http://pastebin.com/2AzWmcM5
Any help greatly appreciated!
"debug halts on a comment line, which might be bad"
Have you tried removing all breakpoints, or putting breakpoints on method implementations rather than on the, say, first line of the method?

Categories

Resources