- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 Google Analytics 添加到我当前的应用程序中,但我不明白如何在我的应用程序代码中实现它。我想把它放在几个 fragment 上,下面是其中一个类。
我正在使用 Google 的指南:[ https://developers.google.com/analytics/devguides/collection/android/v4/#activity-or-fragment][1]而且我仍然不明白如何将它连接到我当前的页面。
这些是我的代码:
LoginActivity2.java:
package com.example.tomgoldberg.tasker;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
/**
* Created by TomGoldberg on 20.3.16.
*/
public class LoginActivity2 extends Fragment implements View.OnClickListener , View.OnFocusChangeListener {
static FragmentManager fragmentManager;
private static final String TAG = "LoginActivity2";
View myView;
String email , password;
EditText _emailTextView;
EditText _passwordTextView;
private Button _logInView;
private Button _signup;
boolean verEmail = false;
boolean verPass = false;
boolean insert = false;
private Tracker mTracker;
//static DatabaseHelper _myDB;
FragmentActivity faActivity ;
public LoginActivity2() {
//Functions.initializeData_forPendingTasks();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.activity_login, container, false);
fragmentManager = getFragmentManager();
MyApplication application = (MyApplication) faActivity.getApplication();
mTracker = application.getDefaultTracker();
//Functions._drawerH1 = (TextView)myView.findViewById(R.id.navigationDrawer_h1);
//Functions._drawerH2 = (TextView)myView.findViewById(R.id.navigationDrawer_h2);
_logInView = (Button)myView.findViewById(R.id.loginBottun);
_logInView.setOnClickListener(this);
_signup = (Button)myView.findViewById(R.id.signUp_button);
_signup.setOnClickListener(this);
_emailTextView = (EditText)myView.findViewById(R.id.email_login_text);
//_emailTextView.setOnFocusChangeListener(this);
_passwordTextView = (EditText)myView.findViewById(R.id.password_login_text);
//_passwordTextView.setOnFocusChangeListener(this);
faActivity = getActivity();
Functions._myDB = new DatabaseHelper(faActivity);
Functions.insert();
Functions.initializeData_forAllTasksFragment();
Functions.initializeData_forPendingTasks();
Functions.initializeData_forPriorityTasks();
Functions.initializeData_forCategoryTasks();
return myView;
}
@Override
public void onClick(View v) {
if ( v.getId() == _logInView.getId() ){
email = _emailTextView.getText().toString();
password = _passwordTextView.getText().toString();
try{
if( Functions.checkingManager(email,password) ){
Snackbar.make(myView.findViewById(R.id.Login1mainLayout), "Welcome back manager " + Functions._userName , Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
try{
NavigationDrawer._drawerH1.setText(Functions._userName);
NavigationDrawer._drawerH2.setText(Functions._userEmail);
} catch (Exception E){
System.out.println("Unable to change...--> "+E.getMessage());
}
Fragment fragment = new MainMenu();
android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack("stack_MainMenu_after_LOGIN");
transaction.commit();
}
else if ( Functions.checkingMember(email, password)){
Snackbar.make(myView.findViewById(R.id.Login1mainLayout), "Welcome back member " + Functions._userName , Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
try{
NavigationDrawer._drawerH1.setText(Functions._userName);
NavigationDrawer._drawerH2.setText(Functions._userEmail);
} catch (Exception E){
System.out.println("Unable to change...--> "+E.getMessage());
}
Fragment fragment = new MainMenu();
android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack("stack_MainMenu_after_LOGIN");
transaction.commit();
}
else {
_logInView.setError("Some error");
Snackbar.make(myView.findViewById(R.id.Login1mainLayout), "Please provide your Email and Password", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
_logInView.setError(null);
}
} catch (Exception e){
_logInView.setError("Some error");
Snackbar.make(myView.findViewById(R.id.Login1mainLayout), "Please provide your Email and Password", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
_logInView.setError(null);
}
}
else if ( v.getId() == _signup.getId() ){
Fragment fragment = new SignUpAsManager();
android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack("stack_SignUp");
transaction.commit();
}
}
@Override
public void onFocusChange( View v , boolean hasFocus ) {
if ( v.getId() == _emailTextView.getId() && !hasFocus ) {
verifyEmail();
_emailTextView = (EditText)myView.findViewById(R.id.email_login_text);
}
if (v.getId() == _passwordTextView.getId() && !hasFocus) {
verifyPassword();
_passwordTextView = (EditText) myView.findViewById(R.id.password_login_text);
}
}
public void verifyEmail(){
String emailToCheck = _emailTextView.getText().toString();
if ( TextUtils.isEmpty(emailToCheck) || Functions.hasNoLetters(emailToCheck) || Functions.isEmail(emailToCheck)) {
_emailTextView.setError("Please Provide Your Email Address");
verEmail = false;
}
else if( TextUtils.isDigitsOnly(emailToCheck) ) {
_emailTextView.setError("Email Address Only");
verEmail = false;
}
else {
System.out.println("verifyEmail");
try{
verEmail = true ;
_logInView.setError(null);
}
catch (Exception e){
System.out.println(e.getMessage());
}
}
}
public void verifyPassword(){
String passwordToCheck = _passwordTextView.getText().toString();
if (TextUtils.isEmpty(passwordToCheck)||Functions.hasNoLetters(passwordToCheck)){
_passwordTextView.setError("Please Provide Your Password");
System.out.println("verifyPassword");
verPass = false;
}
else {
try{
verPass = true;
_logInView.setError(null);
}
catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("verifyPassword");
}
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
Log.i(TAG, "Setting screen name: " + name);
mTracker.setScreenName("Image~" + name);
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
mTracker.send(new HitBuilders.EventBuilder()
.setCategory("Action")
.setAction("Share")
.build());
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我的应用程序.java:
package com.example.tomgoldberg.tasker;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
/**
* Created by tommyahav on 07/04/2016.
*/
public class MyApplication extends Application {
private Tracker mTracker;
synchronized public Tracker getDefaultTracker() {
if (mTracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
mTracker = analytics.newTracker(R.xml.global_tracker);
}
return mTracker;
}
}
分析.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyDashes">
<!--Replace placeholder ID with your tracking ID-->
<string name="ga_trackingId">UA-75923329-1</string>
<!--Enable automatic activity tracking-->
<bool name="ga_autoActivityTracking">true</bool>
<!--Disable automatic exception tracking-->
<bool name="ga_reportUncaughtExceptions">false</bool>
</resources>
谢谢你的帮助。汤姆
最佳答案
Google Analytics 的那些屏幕名称和事件不会出现在您的应用程序日志文件中。
你必须去Google Analytics website并使用您用于创建配置文件的电子邮件帐户登录。
登录后,您必须选择您的项目默认 View ,然后您将被重定向到您的应用概览页面。
并且该页面在左侧提供了菜单。您必须选择实时 --> 屏幕选项来观察当前的操作。
你所做的每一个 Action 只会在 3-5 分钟后反射(reflect)出来。
关于java - 使用 fragment 的 android 应用程序上的谷歌分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36471700/
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
所以我正在开发一个黑 jack 程序,但我有点卡住了。我会警告大家,我对编程真的很陌生,而且,我正在项目中期......所以有一些松散的结局和未使用的变量,以及一些不必要的逻辑(用于测试),但这就是我
我正在尝试创建一个可用作 OpenGL 测试工具的示例程序。到目前为止,我的那个似乎可以工作,但似乎忽略了通过统一变量 MVPMatrix 传递的 MVP 矩阵。当我添加代码以读回制服并检查它是否确实
感谢您帮助我,这是有关我的代码的部分。 printf("Thank you, now please enter the logic gate"); scanf("%s", &C); if (C ==
public static void ejemplosString(String palabra){ char[] letras = palabra.toCharArray();
所以,我有一个 php 应用程序,通过 cgi 和 nginx 运行。我有一个 .jar 程序,用于在条形码打印机(Zebra)上打印条形码,猜猜看是什么!。 我的 php 应用程序使用 exec()
我遇到的唯一问题是 getAll() 方法,它似乎在 PersonnelController 类中的位置立即运行。我也曾在其他很多地方尝试过,但都没有成功。 setAll() 方法看起来不错,我已经测
我是一名优秀的程序员,十分优秀!