我正在使用Android应用程序,我正在使用INSTALL_REFERRER
来了解我的应用程序的安装源。为此,我使用了第一个Google Analytics
Install_Referrer意图过滤器和我自己的一个自定义过滤器。
是否可以在Android中使用两个带有意图过滤器com.android.vending.INSTALL_REFERRER
的广播接收器条目?
Google Analytics Receiver
<receiver
android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
我的自定义广播接收器。
<receiver
android:name="com.xyz.broadcastreceiver.ReferrerCatcher"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
答案 0 :(得分:2)
不,我们不能有两个Install Referrer广播接收器。为此,我创建了自己的自定义广播接收器,以实现Google Analytics Source跟踪和我自己的功能。
<receiver
android:name="com.xyz.broadcastreceiver.ReferrerCatcher"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
在ReferrerCatcher
广播接收器
public class ReferrerCatcher extends BroadcastReceiver {
public static final String TAG = InstallReceiver.class.getCanonicalName();
@Override
public void onReceive(Context context, Intent intent) {
// Google Analytics
new CampaignTrackingReceiver().onReceive(context, intent);
Log.d(TAG, intent.getExtras().getString("referrer");
// my stuff here
}
}
答案 1 :(得分:1)
我一直在使用类似的应用程序,经过一些研究后我发现我们可以删除 Google Analytics Receiver (因为它什么都不做),而是使用自己的自定义接收器。当然,您仍然可以通过以下代码将应用程序发送到Google Analytics:
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker("UA-xxxxxxxx-1")
: (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
: analytics.newTracker("UA-xxxxxxxx-1");
mTrackers.put(trackerId, t);
} return mTrackers.get(trackerId);
}
// Get tracker.
Tracker t = getTracker(TrackerName.APP_TRACKER);
// Set screen name.
t.setScreenName("some string");
// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());
修改强>
下面的代码显示了我如何在AndroidManifest.xml中声明广播接收器:
<!-- Used for Google Play Store Campaign Measurement-->;
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
<receiver android:name=".app.service.CustomReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>