android - Properly tracking install referrals on Play Store -


i have simple task: want track referral id of app install , pass backend.

what did: created link parameter referrer , appended invite link. when opened, javascript detects if browser android mobile browser , prepares intent , issues redirect intent. while preparing intent, referrer field extracted url , appended intent this:

intent://scan/#intent;scheme=com.example.android;package=com.example.android&referrer=4;end 

and here code broadcastreceiver :

public class installreferrerreceiver extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {         tinydb tinydb = new tinydb(context);         string referrer = intent.getstringextra("referrer");         tinydb.putstring(appconstants.referral_id, referrer);         tinydb.putboolean(appconstants.referral_sent, false);     } } 

so, expect here value of referrer 4 based on above intent. value getting string utm_source=google-play&utm_medium=organic

what doing wrong , how can fix correct value referrer field?

edit

i don't have issues in creating url or extracting values referrer field once app installed.

once invite link clicked through button click or opened directly in mobile browser, use above "either open app if installed or open app's page on play store app users install it".

the issue is, how should pass value of referrer field invite link play store app through above intent play store receives value , passes app when installed.

you need test properly, posting mine use case, hope solve problem :)

refferal url -

https://play.google.com/store/apps/details?id=com.mypackage&referrer=utm_source%3dmobisoc%26utm_content%3d{transaction_id}%26utm_campaign%3d1 

code receive refferal -

public static final string key_utm_source = "utm_source"; public static final string key_utm_content = "utm_content"; public static final string key_utm_campaign = "utm_campaign"; public void onreceive(context context, intent intent) {     utils.log("referral received");     try {         string referrer = intent.getstringextra("referrer");         if (referrer != null && !referrer.equals("")) {             utils.log("referral received - " + referrer);             string[] referrerparts = referrer.split("&");             string utmsource = getdata(key_utm_source, referrerparts);             string utmcontent = getdata(key_utm_content, referrerparts);             string utmcampaign = getdata(key_utm_campaign, referrerparts);             if (utmsource != null && utmsource.equals("mobisoc")) {                 sendlogtomobisocserver(context, utmcontent);             } else if (utmsource != null && utmsource.equals("app_share")) {                 rawstorageprovider.getinstance(context).dumpdatatostorage(raghukakaconstants.refferal_for, utmcontent);             }             updaterkserverforreferral(context, utmsource, utmcampaign, utmcontent);         }     } catch (exception e) {         e.printstacktrace();     } }  private string getdata(string key, string[] alldata) {     (string selected : alldata)         if (selected.contains(key)) {             return selected.split("=")[1];         }     return ""; } 

now important part testing. can test referral locally. need attach phone, open shell prompt using adb shell. , broadcast referral data. here command sequence example -

c:\users\neo\desktop>adb shell $ broadcast -a com.android.vending.install_referrer -n com.mypackage/<classname of referralreceiver package> --es "referrer" "utm_source%3dmobisoc%26utm_content%3d{transaction_id}%26utm_campaign%3d1" 

additional -

https://play.google.com/store/apps/details?id=com.mypackage&referrer=utm_source%3dmobisoc%26utm_content%3d{transaction_id}%26utm_campaign%3d1

just see link. if user go playstore via link, , install app. first time when app launch, onreceive method fired automatically, , data after referrer=.

broadcast -

$ broadcast -a com.android.vending.install_referrer -n com.mypackage/<classname of referralreceiver package> --es "referrer" "utm_source%3dmobisoc%26utm_content%3d{transaction_id}%26utm_campaign%3d1" 

for testing no need publish app on playstore, put debug point on first point of onreceive, launch in debug mode, , fire command sequences have posted, data after "referrer" tag. can decide data need add while creating referrer link.

let me know in case of more clarification need :)


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -