Google市场推广统计
Google Play作为Android最大的应用市场,也存在这推广等常用的行为,那么如何统计呢,Google Analytics SDK或者其他的SDK都提供了方法,实际上是可以不需要任何sdk,完全可以自己实现的。
原理是这样的:当来自Play Store上的应用被安装之后,Play Store会发送一个指定的广播给被安装的包,广播的action为com.android.vending.INSTALL_REFERRER。内容数据类似于 utm_source%3Dgoooooogggggggggggggle%26utm_medium%3Dcpc%26utm_term%3Dandroid%252Bbrowser%26utm_content%3Dmaxthon%2520browser%2520for%2520android%26utm_campaign%3DYou%2520never%2520know%2520fast. 我们只需要接收这个广播处理即可。
首先在manifest中增加receiver来接收
<receiver android:name=".AnalyticsReceiver" android:exported="true" > <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver>
这里的AnalyticsReceiver是专门接收推广广播的。
代码很简单
package com.example.installreceiverdemo; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class AnalyticsReceiver extends BroadcastReceiver { private static final String LOGTAG = AnalyticsReceiver.class.getSimpleName(); @Override public void onReceive(Context context, Intent intent) { Log.i(LOGTAG + "_demo", "analyticsReceiver = " + intent + "data in String = " + intent.getStringExtra("referrer")); } }
这样基本上就完成了,关于简单测试,可以使用下列代码:
Intent it = new Intent("com.android.vending.INSTALL_REFERRER"); it.setPackage("com.example.installreceiverdemo"); it.putExtra("referrer", "utm_source%3Dgoooooogggggggggggggle%26utm_medium%3Dcpc%26utm_term%3Dandroid%252Bbrowser%26utm_content%3Dmaxthon%2520browser%2520for%2520android%26utm_campaign%3DYou%2520never%2520know%2520fast."); sendBroadcast(it);
相关文章推荐参考:
https://developers.google.com/analytics/devguides/collection/android/v2/campaigns
http://www.localytics.com/docs/android-market-campaign-analytics/
http://gyurigrell.com/2012/2/21/tracking-install-sources-android-apps