开发者

Is GoogleAnalyticsTracker.getInstance() required for tracking referrals?

I'm trying to track whether people have found my Android app from an ad, or elsewhere. So I found that google analytics can keep track of that via the carefully constructed url generated by this form:

http://code.google.com/mobile/analytics/docs/android/#android-market-tracking

which would look something like this:

http://market.android.com/search?q=pname:com.example.application&referrer=utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_campaign%3Dcampaign

...and then adding the analytics .jar to my project and adding this to my app's manifest:

<!-- Used for install referrer tracking -->
<receiver android:name="com.google.android.apps.analytics.AnalyticsReceiver" android:exported="true">
  <intent-filter>
    <action android:na开发者_高级运维me="com.android.vending.INSTALL_REFERRER" />
  </intent-filter>
</receiver>

So my question is: if I want to track only referrals and nothing more, do I need any of the GoogleAnalyticsTracker.*; code in my activities?


No, you don't need to use the GoogleAnalyticsTracker for that.

Just create your own Tracker class like that:

public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    String referrerString = extras.getString("referrer");

    Log.w("TEST", "### INSTALL_REFERRER EVENT: " + intent.getAction());     
    Log.w("TEST", "### REFFERER IS: " + referrerString);
}
}

And also add next lines into your AndroidManifest.xml

    <receiver android:name="MyReceiver" android:exported="true" >
      <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
      </intent-filter>
    </receiver>

That's it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜