gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:02:57 29 4
gpt4 key购买 nike

我正在尝试将 Google Analytics(分析)包含到我的 Android 项目中。我上次使用的是 V2,效果很好。

现在我遇到了这个问题

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>

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

也向 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" />

当我启用 Dry Run 时,我在日志中看到它收集 ID 和其他信息以供发送。但是当禁用时什么也不会发生。

最佳答案

不知道是否为时已晚,但我和你有同样的事情,因为我正在按照来自 here 的 Google 教程进行操作。还有一个here .

但是,在测试时,我发现 list 文件中没有定义几个服务,我找到了解决方案 here ,因为您已经正确地做到了这一点。

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

在第一个 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 -->

我在 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;
}

至于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>

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

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

有了这个,我就没有那些配置名称无法识别警告,并且我在 Analytics Overview 上收到了点击

enter image description here

希望我能帮上忙:)

关于android - Google Analytics V4 - 字符串 xml 配置名称无法识别 : ga_trackingId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33637999/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com