Google Analytics V4 - 无法识别字符串xml配置名称:ga_trackingId

时间:2022-01-20 15:21:55

I am trying to include Google Analytics to my Android project. Last time i used it was V2 and worked well.

我正在尝试将Google Analytics包含到我的Android项目中。上次我使用它是V2并且运行良好。

Now i am having issue with this

现在我对此有疑问

11-10 20:15:35.493 1957-1957/com.xxx W/GAv4: Int xml configuration name not recognized: ga_sessionTimeout
11-10 20:15:35.508 1957-1957/com.xxx W/GAv4: Bool xml configuration name not recognized: ga_autoActivityTracking
11-10 20:15:35.508 1957-1957/com.xxx W/GAv4: String xml configuration name not recognized: ga_trackingId

global_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="TypographyDashes">
    <integer name="ga_sessionTimeout">300</integer>
    <bool name="ga_autoActivityTracking">true</bool>
    <string name="ga_trackingId">UA-10009718-55</string>

    <!-- the Local LogLevel for Analytics -->
    <string name="ga_logLevel">verbose</string>

    <!-- how often the dispatcher should fire -->
    <integer name="ga_dispatchPeriod">30</integer>

    <!-- Treat events as test events and don't send to google -->
    <bool name="ga_dryRun">false</bool>

    <screenName name=".MainActivity">MainActivity</screenName>

</resources>

app_tracker.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="TypographyDashes">
    <string name="ga_trackingId">UA-10009718-55</string>
    <bool name="ga_autoActivityTracking">true</bool>
    <bool name="ga_reportUncaughtExceptions">true</bool>
    <string name="ga_appName">GoogleAnalyticsApp</string>
    <string name="ga_appVersion">1.1.3</string>
    <bool name="ga_debug">true</bool>
    <item name="ga_dispatchPeriod" format="integer" type="integer">120</item>
    <bool name="ga_anonymizeIp">true</bool>
    <bool name="ga_dryRun">false</bool>
    <string name="ga_sampleFrequency">100.0</string>
    <integer name="ga_sessionTimeout">-1</integer>
    <string name="com.xxx">Sounds</string>

</resources>

Class

package com.xxx;


import java.util.HashMap;
import android.app.Application;
import android.util.Log;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;



public class GoogleAnalyticsApp extends Application {

    private static final String PROPERTY_ID = "UA-10009718-55";

    public static int GENERAL_TRACKER = 0;

    public enum TrackerName {
        APP_TRACKER, GLOBAL_TRACKER, ECOMMERCE_TRACKER,
    }

    public HashMap mTrackers = new HashMap();

    public GoogleAnalyticsApp() {
        super();
    }

    public synchronized Tracker getTracker(TrackerName appTracker) {
        if (!mTrackers.containsKey(appTracker)) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            Tracker t = (appTracker == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID) : (appTracker == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.app_tracker) : analytics.newTracker(R.xml.ecommerce_tracker);


           // Tracker t = analytics.newTracker(PROPERTY_ID);
            mTrackers.put(appTracker, t);
        }
        return (Tracker) mTrackers.get(appTracker);
    }
}

Added necessary lines to AndroidManifest too.

为AndroidManifest添加了必要的行。

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/global_tracker" />

<!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background
     dispatching on non-Google Play devices -->
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
    </intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.AnalyticsService" android:enabled="true" android:exported="false" />

<!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
             installation campaign reporting -->
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />

When i enable Dry Run i see in log that it collects ID and other info for sending. But when disabled nothing happens.

当我启用Dry Run时,我会在日志中看到它收集ID和其他发送信息。但是当残疾人什么都没发生

1 个解决方案

#1


7  

Don't know if it's too late or not, but I had the same things as you, since I was following the tutorial from Google from here and another one here.

不知道是否为时已晚,但我和你有同样的事情,因为我从这里开始关注谷歌的教程,另一个关注这里的教程。

However, when testing, I found out that a couple of services were not being defined in the Manifest file, and I found the solution for that here, as you might have also since you are already doing that correctly.

但是,在测试时,我发现Manifest文件中没有定义几个服务,我在这里找到了解决方案,因为您可能已经正确地执行了此操作。

Now, for the part that might be missing, I have two files defined in my res/xml folder, app_tracker.xml and global_tracker.xml.

现在,对于可能缺少的部分,我在res / xml文件夹app_tracker.xml和global_tracker.xml中定义了两个文件。

On the first one, app_tracker.xml I have defined the following:

在第一个,app_tracker.xml我定义了以下内容:

<!-- Replace placeholder ID with your tracking ID -->
<string name="ga_trackingId" tools:ignore="TypographyDashes" translatable="false">UA-????????-?</string>

<!-- Percentage of events to include in reports -->
<string name="ga_sampleFrequency" translatable="false">100.0</string>

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

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

<!-- How long a session exists before giving up -->
<integer name="ga_sessionTimeout">-1</integer>

<!-- Screen names Override -->
<screenName name="com.example.analytics.MainActivity">Main Screen</screenName>
<!-- other screens -->

And I am using app_tracker.xml when declaring it on the Application class, e.g.

我在Application类上声明它时使用app_tracker.xml,例如

public synchronized Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        mTracker = analytics.newTracker(R.xml.app_tracker);
    }
    return mTracker;
}

As for the global_tracker.xml, I have the following:

至于global_tracker.xml,我有以下内容:

<!-- the Local LogLevel for Analytics -->
<string name="ga_logLevel">verbose</string>

<!-- how often the dispatcher should fire -->
<integer name="ga_dispatchPeriod">60</integer>

<!-- Send hits to Google Analytics. true = don't send -->
<bool name="ga_dryRun">false</bool>

And I use it by defining it on the Manifest file, such as:

我通过在Manifest文件中定义它来使用它,例如:

<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/global_tracker" />

And with this, I do not have those configuration name not recognized warnings and I have the hits being received on the Analytics Overview

有了这个,我没有那些配置名称未被识别的警告,我在Analytics Overview上收到了点击

Google Analytics V4  - 无法识别字符串xml配置名称:ga_trackingId

Hope I was able to help :)

希望我能帮助:)

#1


7  

Don't know if it's too late or not, but I had the same things as you, since I was following the tutorial from Google from here and another one here.

不知道是否为时已晚,但我和你有同样的事情,因为我从这里开始关注谷歌的教程,另一个关注这里的教程。

However, when testing, I found out that a couple of services were not being defined in the Manifest file, and I found the solution for that here, as you might have also since you are already doing that correctly.

但是,在测试时,我发现Manifest文件中没有定义几个服务,我在这里找到了解决方案,因为您可能已经正确地执行了此操作。

Now, for the part that might be missing, I have two files defined in my res/xml folder, app_tracker.xml and global_tracker.xml.

现在,对于可能缺少的部分,我在res / xml文件夹app_tracker.xml和global_tracker.xml中定义了两个文件。

On the first one, app_tracker.xml I have defined the following:

在第一个,app_tracker.xml我定义了以下内容:

<!-- Replace placeholder ID with your tracking ID -->
<string name="ga_trackingId" tools:ignore="TypographyDashes" translatable="false">UA-????????-?</string>

<!-- Percentage of events to include in reports -->
<string name="ga_sampleFrequency" translatable="false">100.0</string>

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

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

<!-- How long a session exists before giving up -->
<integer name="ga_sessionTimeout">-1</integer>

<!-- Screen names Override -->
<screenName name="com.example.analytics.MainActivity">Main Screen</screenName>
<!-- other screens -->

And I am using app_tracker.xml when declaring it on the Application class, e.g.

我在Application类上声明它时使用app_tracker.xml,例如

public synchronized Tracker getDefaultTracker() {
    if (mTracker == null) {
        GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
        mTracker = analytics.newTracker(R.xml.app_tracker);
    }
    return mTracker;
}

As for the global_tracker.xml, I have the following:

至于global_tracker.xml,我有以下内容:

<!-- the Local LogLevel for Analytics -->
<string name="ga_logLevel">verbose</string>

<!-- how often the dispatcher should fire -->
<integer name="ga_dispatchPeriod">60</integer>

<!-- Send hits to Google Analytics. true = don't send -->
<bool name="ga_dryRun">false</bool>

And I use it by defining it on the Manifest file, such as:

我通过在Manifest文件中定义它来使用它,例如:

<meta-data android:name="com.google.android.gms.analytics.globalConfigResource" android:resource="@xml/global_tracker" />

And with this, I do not have those configuration name not recognized warnings and I have the hits being received on the Analytics Overview

有了这个,我没有那些配置名称未被识别的警告,我在Analytics Overview上收到了点击

Google Analytics V4  - 无法识别字符串xml配置名称:ga_trackingId

Hope I was able to help :)

希望我能帮助:)