本文介绍了是否有必要在活动中的任何code,使ga_autoActivityTracking =真正将工作谷歌分析V4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在谷歌Analytics(分析)V3,自动跟踪为活动,我们需要有

  1. ga_autoActivityTracking 标记中的manifest.xml。
  2. GA $ C $在C ONSTART 的onStop

谷歌Analytics(分析)SDK为Android V3

 公共类myTrackedActivity延伸活动{

  @覆盖
  公共无效的OnStart(){
    super.onStart();
    ... //你的OnStart()code中的其余部分。
    EasyTracker.getInstance(本).activityStart(本); //添加此方法。
  }

  @覆盖
  公共无效的onStop(){
    super.onStop();
    ... //你的onStop()code中的其余部分。
    EasyTracker.getInstance(本).activityStop(本); //添加此方法。
  }
}

< XML版本=1.0编码=UTF-8&GT?;

<资源>
  <! - 替换占位符ID与你的跟踪ID  - >
  <字符串名称=ga_trackingId> UA-XXXX-Y< /串>

  <! - 启用自动活动跟踪 - >
  <布尔名=ga_autoActivityTracking>真< /布尔>

  <! - 启用自动例外跟踪 - >
  <布尔名=ga_reportUncaughtExceptions>真< /布尔>
< /资源>
 

然而,当涉及到新版本的谷歌Analytics(分析)V4,(https://developers.google.com/analytics/devguides/collection/android/v4/),我没有看到活动添加任何code需要从上面的文档,似乎我们只需要

  1. ga_autoActivityTracking 标记中的manifest.xml。

谷歌Analytics(分析)SDK V4

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
  &所述;整数名称=ga_sessionTimeout> 300℃/整数GT;

    <! - 启用自动测量活动 - >
    <布尔名=ga_autoActivityTracking>真< /布尔>

    <! - 将出现在报告中的网名 - >
    <屏幕名NAME =com.google.android.gms.analytics.samples.mobileplayground.ScreenviewFragment>
        AnalyticsSampleApp ScreenView
    < /屏幕名>
    <屏幕名NAME =com.google.android.gms.analytics.samples.mobileplayground.EcommerceFragment>
        AnalyticsSampleApp EcommerceView
    < /屏幕名>
    <! - 下面的值应替换为正确的属性ID。 - >
    <字符串名称=ga_trackingId> UA-XXXXXXX-Y< /串>
< /资源>
 

然而,测试后,似乎没有跟踪信息正在从活动

自动发送

时失去了一些东西的文档,谷歌Analytics(分析)V4?

解决方案

步骤1

添加 app_tracker.xml

        UA-42562848-1

 <! - 捕获和报告从应用程序捕获的异常 - >
<布尔名=ga_reportUncaughtExceptions>真< /布尔>

&所述;整数名称=ga_sessionTimeout> 300℃/整数GT;

<! - 启用自动测量活动 - >
<布尔名=ga_autoActivityTracking>真< /布尔>

<! - 将出现在报告中的网名 - >
&LT;屏幕名name="mypackage.BatchSellPortfolioFragmentActivity">BatchSellPortfolioFragmentActivity</screenName>
 

步骤2

添加 getTracker

 公共静态跟踪getTracker(){
    如果(假== isGooglePlayServicesAvailable()){
        返回null;
    }

    如果(追踪== NULL){
        GoogleAnalytics分析= GoogleAnalytics.getInstance(MyApplication.instance());
        跟踪器= analytics.newTracker(R.xml.app_tracker);
    }
    返回跟踪;
}
 

步骤3

在活动启动时打开GA

 公共类MyFragmentActivity扩展SherlockFragmentActivity {
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        Utils.getTracker();
 

In Google Analytics v3, to auto tracking for Activity, we need to have

  1. ga_autoActivityTracking flag in manifest.xml.
  2. GA code in onStart and onStop

Google Analytics SDK for Android v3

public class myTrackedActivity extends Activity {

  @Override
  public void onStart() {
    super.onStart();
    ... // The rest of your onStart() code.
    EasyTracker.getInstance(this).activityStart(this);  // Add this method.
  }

  @Override
  public void onStop() {
    super.onStop();
    ... // The rest of your onStop() code.
    EasyTracker.getInstance(this).activityStop(this);  // Add this method.
  }
}

<?xml version="1.0" encoding="utf-8" ?>

<resources>
  <!--Replace placeholder ID with your tracking ID-->
  <string name="ga_trackingId">UA-XXXX-Y</string>

  <!--Enable automatic activity tracking-->
  <bool name="ga_autoActivityTracking">true</bool>

  <!--Enable automatic exception tracking-->
  <bool name="ga_reportUncaughtExceptions">true</bool>
</resources>

However, when comes to newer version of Google Analytics v4, (https://developers.google.com/analytics/devguides/collection/android/v4/), I don't see any code need to be added in Activity. From the above documentation, it seems that we only need

  1. ga_autoActivityTracking flag in manifest.xml.

Google Analytics SDK v4

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <integer name="ga_sessionTimeout">300</integer>

    <!-- Enable automatic Activity measurement -->
    <bool name="ga_autoActivityTracking">true</bool>

    <!-- The screen names that will appear in reports -->
    <screenName name="com.google.android.gms.analytics.samples.mobileplayground.ScreenviewFragment">
        AnalyticsSampleApp ScreenView
    </screenName>
    <screenName name="com.google.android.gms.analytics.samples.mobileplayground.EcommerceFragment">
        AnalyticsSampleApp EcommerceView
    </screenName>
    <!--  The following value should be replaced with correct property id. -->
    <string name="ga_trackingId">UA-XXXXXXX-Y</string>
</resources>

However, after tested, it seems that there is no tracking information being automatically sent out from Activity.

Is the documentation for Google Analytics V4 missing something?

解决方案

Step 1

Add app_tracker.xml

UA-42562848-1

<!-- catch and report uncaught exceptions from the app -->
<bool name="ga_reportUncaughtExceptions">true</bool>

<integer name="ga_sessionTimeout">300</integer>

<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>

<!-- The screen names that will appear in reports -->
<screenName name="mypackage.BatchSellPortfolioFragmentActivity">BatchSellPortfolioFragmentActivity</screenName>

Step 2

Added getTracker

public static Tracker getTracker() {
    if (false == isGooglePlayServicesAvailable()) {
        return null;
    }

    if (tracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(MyApplication.instance());
        tracker = analytics.newTracker(R.xml.app_tracker);
    }
    return tracker;
}

Step 3

Turn on GA during activity startup

public class MyFragmentActivity extends SherlockFragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);

        Utils.getTracker();

这篇关于是否有必要在活动中的任何code,使ga_autoActivityTracking =真正将工作谷歌分析V4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 23:22