I am trying to integrate 'reward for invites' logic. What I am trying to do for this is I generate a unique URl for every user. When a friend clicks on the URL he is directed to a page and then to the playstore. On the page, a cookie with the unique id is stored on the device.
Note - (User may open the link in any browser)
When the app on the device starts, I fetch for the cookies that was saved using above and if available send the same to the Server where the user is easily identified and rewarded.
This looked pretty straight forward, however I am stuck at the point where I have to read the cookie and extract the id.
I read this which says it isn't possible. :( I also tried the below
List<Cookie> cookies = new DefaultHttpClient().getCookieStore()
.getCookies();
if (cookies.isEmpty()) {
System.out.println("None Cookies");
} else {
for (int i = 0; i < cookies.size(); i++) {
System.out.println("Cookie - " + cookies.get(i).toString());
}
}
but no luck. I keep getting "None Cookies".
My Questions:
- Is it possible to read the cookie that was created? If yes how?
- If no, any alternative on how I can achieve the above functionality?
Thanks for stopping by.
I found an alternative to my above requirement using Campaign Measurement.
This can be done in 3 simple steps in addition to integrating google-play-services_lib.
Create your invitation URL.
Which will be play-store url + your unique code. For example my code is ABCDEX52362XYZ then the url will look like
https://play.google.com/store/apps/details?id=com.app.yourappspackagename&referrer=utm_source%3DABCDEX52362XYZ
&referrer=utm_source%3DABCDEX52362XYZ is the important key here. More details about creating this URL is here.
Google says -
When your app is downloaded from Google Play Store, the Play Store app broadcasts an INTENT_REFERRER to your app during installation. This intent contains the value of the referrer parameter of the link used to reach your app's Google Play Store page, if one was present.
Add the Google Analytics receiver to your AndroidManifest.xml file
Create ReferrerCatcher broadcast receiver to capture the invitation code.
Hope this helps. Happy coding. :)