Android Google Analytics EasyTracker - java

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.

Related

How to Track "button clicks" in react js android application via Firebase?

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>
);
}

Add update Button to update the app if updates is available

I have below code from another forum and I'm using WVersionManager from github.
Add update with a button click
I have assigned to a button click, ie., if user clicks button it will check for new update.
public class about extends ActionBarActivity {
Button updateButton;
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
updateButton = (Button)findViewById(R.id.button_Update);
updateButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
WVersionManager versionManager = new WVersionManager(this);
versionManager.setVersionContentUrl("http://link_to_version_test_file/version.txt");
versionManager.setUpdateUrl("http://link_to_updated_apk_file/latest.apk");
versionManager.checkVersion();
}
});
}
2 . Contents of version.txt file
The version.txt contains these codes :
{"version_code":6,"content":"Version 1.5 <p>Added feature 1</p><li>Added feature 2</li><li>Added feature 3</li><li>Added feature 4</li><li>Added feature 5</li>"}
version_code and content:version is your application's version code and version name respectively as mentioned in manifest file.
to add more features, just add Added feature title
3 . Giving Internet permission to your app
and in mu application's manifest file.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Well This is all I have done by Far now, Now I want to If I could add code so that when Button pressed would Return Updating an app notification if new updates are available if not Return your app is up to date.
Any Help would be appreciated.

Android Studio showing errors on restart

I was working fine. My p.c powered off due to light. When I start again my android studio, there came a lot of errors in my all java files. How can I solve them?
public class MainActivity extends Activity {
private boolean detectEnabled;
private TextView textViewDetectState;
private Button buttonToggleDetect;
private Button buttonExit;
FlashLight flashLight;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewDetectState = (TextView) findViewById(R.id.textViewDetectState);
buttonToggleDetect = (Button) findViewById(R.id.buttonDetectToggle);
buttonToggleDetect.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDetectEnabled(!detectEnabled);
}
});
buttonExit = (Button) findViewById(R.id.buttonExit);
buttonExit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this , FlashLight.class);
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private void setDetectEnabled(boolean enable) {
detectEnabled = enable;
Intent intent = new Intent(this, CallDetectService.class);
if (enable) {
// start detect service
startService(intent);
buttonToggleDetect.setText("Turn off");
textViewDetectState.setText("Detecting");
}
else {
// stop detect service
stopService(intent);
buttonToggleDetect.setText("Turn on");
textViewDetectState.setText("Not detecting");
}
}
}
Here is a screenshot of my issue:
Because we don't have enough information, we can't tell you. This has happened to me before though, so I can give you a few tips:
Just wait until the gradle build is done, often times there are random errors which resolve themselves after a few minutes. This especially happens with resources that you are getting based on an id, R from R.id shows as an error until the gradle build is finished
Clean your project. Build->Clean Project
Rebuild Project. Build->Rebuild Project
Restart Android Studio
Restart Computer
Honestly, we can't give you more information than that until we get more details. Chances are it's number 1 that is the problem, so just wait.
{Rich}
Build--> Clean Project
Build-> Rebuild Project
Go to File
Then Invalidate Cache/ Restart
After that hit Invalidate and Restart
It's not a pleasant moment when your computer suddenly turns off and corrupting your project files. Sadly, when using Windows, you have a small hope that your files integrity are still intact when the Windows suddenly turn off due to power failure or having a friendly BSOD. I've experienced project error twice in a month because of it. Windows can't be counted for reliability, tried Linux instead.
To prevent another files error (or should I says, corrupted files?), you should always back up your project. Use a Version control systems (VCS) like git. Then copy/clone your project to USB flash drive. Or you can use a free private repository for git:
Bitbucket
GitLab
Always, always, always backup.
Build->Clean Project. This will solve your problem.

Android: Add button to YouTubePlayerView

I'm wanting to add a button to the YouTubePlayerView but don't know the best way to go about doing so. I would like the button only to be present when the user clicks on the screen to bring up the youtube controls (play/pause, timeline, share, etc.) that fades away after a few seconds just as the controls fade. I've looked into ViewGroupOverlay but not sure if this is the best way to do so and I'm not sure how to only have the button added to the overlay when the controls are available. It feels like I have to override one of the YouTubePlayer or YouTubePlayerView functions to know when the controls are visible but I'm just making a hypothesis here. I'm relatively new to android and it's been a while since I've done anything serious in Java. Any direction here would be great if others don't know the exact answer. I've looked around for about 2 hours before posting this :)
package com.example.something.exampletube;
import android.os.Bundle;
import android.view.ViewGroupOverlay;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
/**
* Created by Nicholas Dwyer on 4/17/2015.
* This class is used to play youtube videos
*/
public class PlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
YouTubePlayerView playerView;
ViewGroupOverlay groupOverlay;
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_player);
playerView = (YouTubePlayerView) findViewById(R.id.player_view);
playerView.initialize(YoutubeConnector.KEY, this);
groupOverlay = playerView.getOverlay();
}
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean restored) {
if(!restored) {
youTubePlayer.cueVideo(getIntent().getStringExtra("VIDEO_ID"));
}
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
String errorMessage = "There was an error initializing the YouTubePlayer" + youTubeInitializationResult.toString();
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
//Toast.makeText(this,getString(R.string.failed), Toast.LENGTH_LONG).show();
}
}
It is not possible to add buttons as overlays above the player as specified by Google:
https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerView
Note that while videos are playing, this View has a minimum size of
200x110 dp. If you make the view any smaller, videos will
automatically stop playing. Also, it is not permitted to overlay the
view with other views while a video is playing.
See also here Is it possible to overlay some views on YouTube Android Player?
If any view only partially overlaps (or YouTubeVideoView is only partially scrolled outside the visible screen), the video is stopped after approximately one second. Google supposedly does that to prevent abuse of videos for advertising outside YouTube.
Alternatives: Use a WebView and embed it.
Another good alternative is to used Exoplayer, to overlay your video with view. It is not part of the android sdk, but it's recommended by google and included in android developer documentation :
http://google.github.io/ExoPlayer/
https://developer.android.com/guide/topics/media/exoplayer.html
Exoplayer allow you to stream any kind of video, not only Youtubes videos.
It's also good to mention that Exoplayer is used in Youtube application.
Instead of adding button as a layer above the player, you can add it INSIDE the player:
Button b = new Button(this);
b.setBackgroundResource(R.drawable.close);
((ViewGroup)((ViewGroup) youTubePlayerView.getChildAt(0)).getChildAt(0)).addView(b);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
Working for me.

GoogleMap Cannot be resolved to a type, Android api v2

I am able to display a map and update my location. However I added this button to take a screenshot of the current map. I believe I have all the proper imports and the google play library because the map is displaying properly. Eclipse tells me in this:
new GoogleMap.OnMapLoadedCallback()
"GoogleMap.OnMapLoadedCallback cannot be resolved to a type"
Here is the code.
Button screen = (Button) findViewById(R.id.button5);
screen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "ScreenShot in sdcard",
Toast.LENGTH_SHORT).show();
mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
public void onMapLoaded() {
mMap.snapshot(new GoogleMap.SnapshotReadyCallback() {
public void onSnapshotReady(Bitmap bitmap) {
// Write image to disk
FileOutputStream out = new FileOutputStream("/mnt/sdcard/map.png");
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
}
});
}
});
What do I need to do to make this resolve to a type and what does that mean?
An update to the Google Play services Library was released November 2013 (Google Play services 4.0.30). The previous library did not include the OnMapLoadedCallback interface.
Instructions for installation of the update for incorporation into your android project can be found at
http://developer.android.com/google/play-services/setup.html

Categories

Resources