Skip to content

Commit

Permalink
对Umeng页面统计的修改
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Aug 23, 2017
1 parent 2a68c75 commit bdf9488
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/com/maning/gankmm/app/MyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.maning.librarycrashmonitor.main.MCrashMonitor;
import com.readystatesoftware.chuck.ChuckInterceptor;
import com.socks.library.KLog;
import com.umeng.analytics.MobclickAgent;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -60,6 +61,9 @@ public void onCreate() {
//初始化异常捕获
initCrash();

//Umeng统计相关
initUmeng();

//开启违例检测:StrictMode
if (BuildConfig.LOG_DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
Expand All @@ -68,8 +72,13 @@ public void onCreate() {

}

private void initUmeng() {
//禁止默认的页面统计方式
MobclickAgent.openActivityDurationTrack(false);
}

private void initLog() {
KLog.init(BuildConfig.LOG_DEBUG, "GankMM");
KLog.init(BuildConfig.LOG_DEBUG, "---GankMM---");
}


Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/maning/gankmm/ui/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,22 @@ protected void onDestroy() {
@Override
protected void onResume() {
super.onResume();
MobclickAgent.onPageStart(this.getClass().getSimpleName());
// MainActivity 内嵌套Fragment,应在Fragment中统计页面
String className = this.getClass().getSimpleName();
if (!"MainActivity".equals(className)) {
MobclickAgent.onPageStart(className); // 统计页面
}
MobclickAgent.onResume(this); //统计时长
}

@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPageStart(this.getClass().getSimpleName());
// MainActivity 内嵌套Fragment,应在Fragment中统计页面
String className = this.getClass().getSimpleName();
if (!"MainActivity".equals(className)) {
MobclickAgent.onPageEnd(className); // 统计页面
}
MobclickAgent.onPause(this);
}

Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/com/maning/gankmm/ui/base/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

public class BaseFragment extends Fragment {

//统计名字判断
public String className;

private SVProgressHUD mSVProgressHUD;


Expand All @@ -18,6 +21,8 @@ public class BaseFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

className = this.getClass().getSimpleName();

context = getActivity();

initDialog();
Expand All @@ -43,13 +48,20 @@ public void dissmissProgressDialog() {
@Override
public void onResume() {
super.onResume();
MobclickAgent.onPageStart(this.getClass().getSimpleName());
//CategoryFragment 内嵌套Fragment,统计子页面
if (!"CategoryFragment".equals(className)) {
MobclickAgent.onPageStart(className);
}
}

@Override
public void onPause() {
super.onPause();
MobclickAgent.onPageEnd(this.getClass().getSimpleName());
//CategoryFragment 内嵌套Fragment,统计子页面
if (!"CategoryFragment".equals(className)) {
MobclickAgent.onPageEnd(className);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import com.maning.gankmm.ui.base.BaseFragment;
import com.maning.gankmm.ui.iView.IPublicView;
import com.maning.gankmm.ui.presenter.impl.PublicPresenterImpl;
import com.maning.gankmm.utils.IntentUtils;
import com.maning.gankmm.utils.MySnackbar;
import com.socks.library.KLog;

import java.util.List;

Expand Down Expand Up @@ -55,14 +53,14 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
flagFragment = getArguments().getString(Constants.FlagFragment);
KLog.i("CommentFragment-----onCreate:" + flagFragment);
//这个页面单独统计
className = "CategoryFragment-" + flagFragment;
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
KLog.i("PublicFragment-----onCreateView");
View view = inflater.inflate(R.layout.fragment_common, container, false);
ButterKnife.bind(this, view);

Expand All @@ -76,8 +74,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
KLog.i("PublicFragment-----onViewCreated");

publicPresenter = new PublicPresenterImpl(getActivity(), this, flagFragment);

publicPresenter.getDBDatas();
Expand Down

0 comments on commit bdf9488

Please sign in to comment.