Created
December 16, 2017 06:41
-
-
Save emaillenin/3519a6b01349c29b8eb80dd89082c597 to your computer and use it in GitHub Desktop.
Branch Analytics and Referral Tracking for Custom APK files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onStart() { | |
super.onStart(); | |
Branch branch = Branch.getInstance(); | |
branch.initSession(new Branch.BranchReferralInitListener() { | |
@Override | |
public void onInitFinished(JSONObject referringParams, BranchError error) { | |
if (error == null) { | |
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app | |
// params will be empty if no data found | |
// ... insert custom logic here ... | |
// Log.i("com.duggout", "Branch Params: " + referringParams.toString()); | |
try { | |
if (referringParams.has("+clicked_branch_link") && | |
referringParams.getBoolean("+clicked_branch_link") && | |
referringParams.has("u")) { | |
SharedPreferences getPrefs = PreferenceManager | |
.getDefaultSharedPreferences(HomeActivity.this); | |
SharedPreferences.Editor e = getPrefs.edit(); | |
e.putInt(LoginUseCase.REFERRED_BY, referringParams.getInt("u")); | |
e.apply(); | |
mTracker.setReferrer(String.valueOf(referringParams.getInt("u"))); | |
mTracker.send(new HitBuilders.EventBuilder("Referral", "Started").build()); | |
if (referringParams.has("~referring_link") && !referringParams.getString("~referring_link").isEmpty()) { | |
mTracker.send(new HitBuilders.ScreenViewBuilder().setCampaignParamsFromUrl(referringParams.getString("~referring_link")).build()); | |
} | |
} | |
} catch (JSONException e) { | |
} | |
} else { | |
Log.i("com.duggout", error.getMessage()); | |
} | |
} | |
}, this.getIntent().getData(), this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment