android - 当我的 android 应用程序处于终止模式时如何触发 GA 事件?
问题描述
我已经使用 Xamarin 在我的 android 应用程序中实现了谷歌分析,它工作正常,我能够在我的应用程序处于后台或运行时触发 GA 事件。我得到的唯一问题是当我的应用程序处于终止模式时我无法触发我的 GA 事件?当我的应用程序处于终止模式时,我正在使用广播接收器发送本地通知,我想在其中触发我的 GA 事件。我找不到与此相关的任何信息,有人可以帮助我吗?
public class AlarmReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent){
//My implementation over here, in which I want to trigger GA events.
}
}
我已经初始化了我的 GA 实例并在单独的类中的以下方法中触发了 GA 事件。
public IAnalyticsManager InitWithId(string analyiticsId)
{
if(Android.App.Application.Context==null)
{
gaInstance = GoogleAnalytics.GetInstance(context);
}
else
{
gaInstance = GoogleAnalytics.GetInstance(Android.App.Application.Context);
}
//
gaInstance.SetLocalDispatchPeriod(10);
tracker = gaInstance.NewTracker(analyiticsId);
tracker.EnableExceptionReporting(true);
return this;
}public void TrackEvent(String screenName, String lineNo,IDictionary<string,string> allEvents)
{
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder();
builder.SetCategory(screenName);
builder.SetAction(lineNo);
builder.SetAll(allEvents);
builder.SetLabel(allEvents[EMADefines.KeyTimeStamp]);
tracker.SetClientId(allEvents[EMADefines.KeyUserName]);
tracker.Send(builder.Build());
}
解决方案
onReceive
像这样在您的方法中启动 GA -
gaInstance = GoogleAnalytics.GetInstance(context.getApplicationContext());
gaInstance.SetLocalDispatchPeriod(10);
tracker = gaInstance.NewTracker(analyiticsId);
tracker.EnableExceptionReporting(true);
然后调用该TrackEvent
方法,确保TrackEvent
您的类中也有该方法AlarmReceiver
。
推荐阅读
- php - 将脚本从 PHP 5.6 移动到 PHP 7
- angular - NET Core Angular 多个主题
- ios - 从通知中心托盘中删除特定的推送通知
- sql - 我有一个 lambda 函数,我在其中从 s3 获取一个 csv 文件,现在我想在 node.js 中对该数据运行 SQL 查询?
- c# - 根据标准对列表进行分区的最简单方法是什么?
- python - 如何使用带有 3D 张量输入的 keras 嵌入层?
- c# - FindNodeBiFieldValue 返回 null
- azure - 从 Cordova 客户端将文件和元数据上传到 Azure Blob 存储
- linux - 运行远程脚本的意外行为
- bash - 从文本文件中提取特定字符串并使用提取字符串创建 HTTP 请求