I am new in dealing with react native apps and I am trying to find out how to track few buttons that is being available on my android application.
In my react native app, there is a "submit" button while signing up into the app and I want to track that button via Firebase, but have no idea on how to do that in android studio project for an react native application. Although I know the similar code which I need to put but not sure how to identify the button class element right here.
Here's the similar code what I need to put:
``
Button b1= findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Bundle bundle= new Bundle();
bundle.putString("Button_text","Sign_up");
mFirebaseAnalytics.logEvent("Sign_up_button",bundle);
}
``
This is my react native app, and I don't know where is the right button I am trying to find out
RNFirebase should be integrated into the react-native project.
As explained in the document the event tracking for the button action should be handled in onPress callback method
import react, { useEffect } from 'react';
import { View, Button } from 'react-native';
import analytics from '#react-native-firebase/analytics';
function App() {
return (
<View>
<Button
title="Add To Basket"
onPress={async () =>
await analytics().logEvent('Event Name', {
Data Object
})
}
/>
</View>
);
}
Related
Image to my error
I'm new to Android app development and I created a new settings activity from the provided templates. I'd like to create a button which redirects the user back to the main screen(I figured this part out), though I am unable to create a .
the image shows where I'm currently stuck
In PreferenceCategory tag add
<Preference android:title="Exit" android:key="exit"/>
Then in class add this code:
Preference button = (Preference)getPreferenceManager().findPreference("exit");
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
#Override
public boolean onPreferenceClick(Preference arg0) {
finish();
return true;
}
});
I have a listview that i show post on it.
what i want is a listener when user moves his finger down and listview can't scroll.(Like Update Listener On Gmail Android App Inbox that when you move your finger from top to down it updates Inbox).
How Can I Do That?
What you're wanting is a SwipeRefreshLayout, which is in the google v4 support libraries.
In order to use it, you need to wrap your scrollable layout in <android.support.v4.widget.SwipeRefreshLayout> tags. You can then create a listener for when someone swipes to refresh in the code for your activity
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
....
#Override public void onRefresh() {
new Handler().postDelayed(new Runnable() {
#Override public void run() {
swipeLayout.setRefreshing(false);
}
}, 5000);
}
More info can be found on this website, and on this page here on Google's developer pages.
I am very new to mobile development, this isn't homework I am working ahead of my class, I developed a simple app that has a button and when it's pressed it shows a message "Hello Android". I would like to build on this and change the color of the background when the onClickListener is called, I will post my code below, I am asking for the best approach to achieve my goal (change background). I want to iterate that this code below works, and that I am not asking for anything to do with the code I have presented, I want to add to it to change the background color (it's currently white, I'm assuming by default). Oh and I have never worked with Java before (very difficult course teaching android/iOS/WinMobile in 1 class). Thank you.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupMessageButton();
}
private void setupMessageButton() {
// 1. Get a reference to the button
final Button messageButton = (Button) findViewById(R.id.helloDroidButton);
//Set the click listener to run my code.
//Code will run when user clicks button.
messageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Anonymous class? --> not sure what he means
Log.i("DemoButtonApp", "Hello Android!");
Toast.makeText(
MainActivity.this,
"Hello Android!",
Toast.LENGTH_LONG
).show();
}
});
}
Android support feature called Selector , that help you to change the background of any view in each state of it like pressed , forces and so one , take look on this useful tutorial and feed me back in any not obvious point
http://www.mkyong.com/android/android-imagebutton-selector-example/
hope it help you
I'm trying to use Google Analytics in my Android application with
Google Configuration
Add .jar in my project
Insert this in AndroidManifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Add this in my java file
public class MainActivity extends Activity {
GoogleAnalyticsTracker tracker;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tracker = GoogleAnalyticsTracker.getInstance();
tracker.startNewSession("My-UA–XXXXXXXX", this);
setContentView(R.layout.main);
Button createEventButton = (Button)findViewById(R.id.NewEventButton);
createEventButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
tracker.trackEvent(
"Clicks", // Category
"Button", // Action
"clicked", // Label
77); // Value
}
});
setContentView(R.layout.main);
Button createPageButton = (Button)findViewById(R.id.NewPageButton);
createPageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Add a Custom Variable to this pageview, with name of "Medium" and value "MobileApp" and
// scope of session-level.
tracker.setCustomVar(1, "Navigation Type", "Button click", 2);
// Track a page view. This is probably the best way to track which parts of your application
// are being used.
// E.g.
// tracker.trackPageView("/help"); to track someone looking at the help screen.
// tracker.trackPageView("/level2"); to track someone reaching level 2 in a game.
// tracker.trackPageView("/uploadScreen"); to track someone using an upload screen.
tracker.trackPageView("/testApplicationHomeScreen");
}
});
Button quitButton = (Button)findViewById(R.id.QuitButton);
quitButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
Button dispatchButton = (Button)findViewById(R.id.DispatchButton);
dispatchButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Manually start a dispatch, not needed if the tracker was started with a dispatch
// interval.
tracker.dispatch();
}
});
}
#Override
protected void onDestroy() {
super.onDestroy();
// Stop the tracker when it is no longer needed.
tracker.stopSession();
}
}
==> And it's ok, no error, compiling and executing but i have created my ua account yesterday (more 24h) and i have nothing in my google analytics panel.
My Question : is there an error in my code or i want to wait again ? Live trafic works for Android application (like tradicional website) ???
I have no information about Live trafic (when i play my app, i would like to show the number of person using my application) and Saved trafic (with viewed pages, time)
Thank you for your replies and excuse my poor english :)
bye
UPDATE 1 :
i've used this tuto : http://www.xatik.com/2012/03/27/how-to-use-google-analytics-in-android-applications/ and i've got this in my Logcat :
04-07 14:21:59.669: INFO/GoogleAnalyticsTracker(864): Host: www.google-analytics.com
04-07 14:21:59.669: INFO/GoogleAnalyticsTracker(864): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.2; en-us; sdk Build/FRF91)
04-07 14:21:59.669: INFO/GoogleAnalyticsTracker(864): GET /__utm.gif?utmwv=4.8.1ma&utmn=235327630&utme=8(1!Navigation%20Type)9(1!Button%20click)11(1!2)&utmcs=UTF-8&utmsr=240x320&utmul=en-US&utmp=%2FtestApplicationHomeScreen&utmac=BLIBLUBLIBLO–1&utmcc=more_and_more
in progress but nothing in my Live Analytics panel....
i've added EasyTracker .jar in my project
Here my Activity Code:
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
import com.google.android.apps.analytics.easytracking.EasyTracker;
import com.google.android.apps.analytics.easytracking.TrackedActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends TrackedActivity {
GoogleAnalyticsTracker tracker;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button quitButton = (Button)findViewById(R.id.QuitButton);
quitButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
EasyTracker.getTracker().trackEvent("ButtonClick", "MyButtonName", "", 0);
}
});
}
#Override
protected void onDestroy() {
super.onDestroy();
//How can i stop the tracking onDestroy ???
}
}
I know this is a couple months old but I'll give a response to potentially help others. I am the person who wrote the guide that was referenced in Update 1 of the OP. One issue I originally ran into was the fact that I was using a custom ROM on my phone. A lot of custom ROMs have modified 'hosts' files that block an apps access to display ads or in this case blocks the sending of data to Google Analytics. If you do have a custom ROM on your phone, you can check the 'hosts' file to see if Google Analytics is listed in there. The fastest way to do this is to open the file in a text editor on your computer. To do this:
Get a file explorer app on you android device (I use 'ES File Explorer').
Navigate to '/etc'.
Locate and copy the 'hosts' file to a known location on your SD card.
Connect phone/SD card to computer and open the 'hosts' file in a text editor (Notepad++ is nice and free).
Search through file for anything that relates to Google Analytics and delete it. I first searched for 'analytics', went through all results, and deleted everything that had something to do with Google attached to the name (there are other analytic sites). Then I searched for 'google', went through all the results, and deleted anything that still related to Analytics.
Save 'hosts' file.
Disconnect from computer and use file explorer to copy the 'hosts' file from SD card back to '/etc' and overwrite.
This should allow your phone to send data to Google Analytics. I will update my guide to include this somewhere.
I am trying to understand the tab activities in android.. and working around with few examples.I have three tabs Tab1,Tab2,Tab3.. in which when I click each tab it will display a simple textview.this is fine for me.Now, I added a button in Tab1 and I tired to handle the click event... its not working for me.It says "App has stopped".
Below is the Tab1 activity....
EDIT1:I am a starter..In Android sdk it comes with a default API demo project.In that project, for 2.x Andriod OS.. the same method works.They are able to handle this click event in that ta activity.
public class Tab1 extends Activity
{
private Button bt_AddAcc = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bt_addaccount);
bt_AddAcc = (Button)findViewById(R.layout.bt_addaccount);
bt_AddAcc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), "Uername:",Toast.LENGTH_LONG).show();
}
});
}
}
TabActivity is already deprecated.
I suggest you look at the ActionBar or when you want to develop for Android 2.x as well then take a look at ActionBarSherlock. This is a third party library which implements the ActionBar on older devices.