安卓:我可以使用谷歌分析服务里面? [英] Android: can I use Google Analytics inside a Service?

查看:165
本文介绍了安卓:我可以使用谷歌分析服务里面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大部分时间在后台工作,即服务的应用程序。有很多的例子和教程网上关于如何使用谷歌Analytics(分析)API与EasyTracker库跟踪多个活动,但没有一个解释,如何使用谷歌Analytics(分析)API的服务。它甚至有可能?

I have an application which most of the time works in the background, as a Service. There is a lot of examples and tutorials online on how you can use Google Analytics API with EasyTracker library to track multiple Activities, but there is not a single one that explains, how to use Google Analytics API in a Service. Is it even possible?

推荐答案

好消息!您可以。这是相当容易的。

Good news! You can. and it's quite easy.

您需要的应​​用程序上下文姑且称之为mCtx 当你有这个需要GoogleAnalytics的一个实例,您可以通过调用得到它

You'll need the application context let's call it mCtx When you have this you need an instance of GoogleAnalytics, you can get it by calling

GoogleAnalytics mGaInstance = GoogleAnalytics.getInstance(mCtx);

现在你需要设置你想要的任何参数(其中使用EasyTracker时,你会normaly放在analytics.xml)。

now you need to set any parameters you want (which you would normaly put in analytics.xml when using EasyTracker).

现在你需要跟踪的实例:

now you need a Tracker instance:

Tracker mTracker = mGaInstance.getTracker("UA-XXXX-Y"); // your ID here

和这基本上它。现在,你可以用这个跟踪器发送事件

and that's basically it.. now you can send events with this tracker

mTracker.sendEvent(....);

等。

希望这有助于。这是最基础的,但GoogleAnalytics和Tracker更换EasyTracker。

Hope this helps. This is the very basics but GoogleAnalytics and Tracker replace the EasyTracker.

您可以阅读更多关于它在这里: 高级配置 - Android SDK中

You can read more about it here: Advanced Configuration - Android SDK

只是注意,直到你会看到GA网站上的报告,它可能需要长达24小时..所以要耐心等待:)或使用mGaInstance.setDebug(真)在logcat中看到,它已发送

Just note that until you'll see the reports on the GA website, it can take up to 24 hours.. so be patient :) or use mGaInstance.setDebug(true) to see in the logcat that it has been sent

这篇关于安卓:我可以使用谷歌分析服务里面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆