Android Open Source - tapad-android-sdk Install Referrer Receiver






From Project

Back to project page tapad-android-sdk.

License

The source code is released under:

MIT License

If you think the Android project tapad-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tapad.tracking;
/*from w ww .j a  v  a 2s.co  m*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import com.tapad.util.Logging;

import java.net.URLEncoder;

/**
 * Install referrer broadcast receiver for campaign tracking.
 * <p/>
 * <receiver android:name="com.tapad.tracking.InstallReferrerReceiver" android:exported="true">
 * <intent-filter>
 * <action android:name="com.android.vending.INSTALL_REFERRER" />
 * </intent-filter>
 * </receiver>
 * <p/>
 * To test referral:
 * <pre>
 *    adb shell
 *    am broadcast -a com.android.vending.INSTALL_REFERRER -n com.tapad.sample/com.tapad.tracking.InstallReferrerReceiver --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"
 * </pre>
 */
public class InstallReferrerReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        String referrerString = null;

        try {
            if (extras != null) {
                referrerString = extras.getString("referrer");
            }

            Tracking.setupAPI(context, null, null);

            if (referrerString == null) {
                Tracking.get().onEvent(Tracking.EVENT_INSTALL);
            } else {
                Tracking.get().onEvent(Tracking.EVENT_INSTALL, "android_referrer=" + URLEncoder.encode(referrerString, "UTF-8"));
            }
            // Register that the install event now has been sent
            PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(Tracking.PREF_INSTALL_SENT, true).commit();
        } catch (Exception e) {
            // Precautionary
            Logging.error("Tapad/InstallReferrerReceiver", "Unexpected error caught in INSTALL_REFERRER intent receiver. Install event will not be sent. " + e.getMessage());
        }
    }
}




Java Source Code List

com.tapad.adserving.AdRequestDispatcher.java
com.tapad.adserving.AdRequest.java
com.tapad.adserving.AdResource.java
com.tapad.adserving.AdResponse.java
com.tapad.adserving.AdServingServiceImpl.java
com.tapad.adserving.AdServingService.java
com.tapad.adserving.AdServing.java
com.tapad.adserving.AdSize.java
com.tapad.adserving.ui.AdView.java
com.tapad.sample.AdViewActivity.java
com.tapad.sample.MainActivity.java
com.tapad.sample.MainApplication.java
com.tapad.sample.ManualMarkupActivity.java
com.tapad.sample.SampleConstants.java
com.tapad.tracking.DeviceIdentifier.java
com.tapad.tracking.DeviceInfo.java
com.tapad.tracking.EventDispatcher.java
com.tapad.tracking.EventResource.java
com.tapad.tracking.Event.java
com.tapad.tracking.InstallReferrerReceiver.java
com.tapad.tracking.TrackingServiceImpl.java
com.tapad.tracking.TrackingService.java
com.tapad.tracking.Tracking.java
com.tapad.tracking.deviceidentification.AndroidId.java
com.tapad.tracking.deviceidentification.IdentifierSourceAggregator.java
com.tapad.tracking.deviceidentification.IdentifierSource.java
com.tapad.tracking.deviceidentification.PhoneId.java
com.tapad.tracking.deviceidentification.TypedIdentifier.java
com.tapad.tracking.deviceidentification.WifiMac.java
com.tapad.util.DigestUtil.java
com.tapad.util.HttpClientUtil.java
com.tapad.util.IoUtil.java
com.tapad.util.Logging.java