Skip to content

Instantly share code, notes, and snippets.

@ggrell
Last active December 31, 2017 21:48
Show Gist options
  • Save ggrell/1877105 to your computer and use it in GitHub Desktop.
Save ggrell/1877105 to your computer and use it in GitHub Desktop.
A BroadcastReceiver for handling install referrer market broadcasts
public class InstallReferrerReceiver extends BroadcastReceiver {
private static final String TAG = "InstallReferrerReceiver";
@Override
public void onReceive(Context context, Intent intent) {
HashMap<String, String> values = new HashMap<String, String>();
try {
if (intent.hasExtra("referrer")) {
String referrers[] = intent.getStringExtra("referrer").split("&");
for (String referrerValue : referrers) {
String keyValue[] = referrerValue.split("=");
values.put(URLDecoder.decode(keyValue[0]), URLDecoder.decode(keyValue[1]));
}
}
} catch (Exception e) {
}
Log.d(TAG, "referrer: " + values);
AnalyticsTrackerFactory.getTracker(context).event("Installed", values);
}
}
@trullock
Copy link

what @ganesh-gbg said. Came here after googling from this same code on your blog.

@ggrell
Copy link
Author

ggrell commented Dec 31, 2017

I think AnalyticsTrackerFactory was some general wrapper around analytics, so I could use any analytics package, or multiple at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment