Skip to content

Commit 8fe3376

Browse files
Merge pull request #743 from BranchMetrics/Staging
Release v4.1.0
2 parents a821265 + bc103c9 commit 8fe3376

File tree

10 files changed

+431
-9
lines changed

10 files changed

+431
-9
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.branch.referral;
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4;
4+
import io.branch.referral.Defines.RequestPath;
5+
import io.branch.referral.util.BranchCrossPlatformId;
6+
import io.branch.referral.util.BranchLastAttributedTouchData;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
/**
12+
* Created by --vbajpai on --2019-09-17 at --10:44 for --android-branch-deep-linking-attribution
13+
*/
14+
15+
@RunWith(AndroidJUnit4.class)
16+
public class BranchCPIDTest extends BranchEventTest {
17+
18+
@Test
19+
public void testGetCPID() throws Throwable{
20+
Branch branch = Branch.getInstance(getTestContext());
21+
22+
new BranchCrossPlatformId(null, getTestContext());
23+
24+
ServerRequestQueue queue = ServerRequestQueue.getInstance(getTestContext());
25+
Assert.assertEquals(2, queue.getSize());
26+
27+
ServerRequest cpidRequest = queue.peekAt(1);
28+
doFinalUpdate(cpidRequest);
29+
doFinalUpdateOnMainThread(cpidRequest);
30+
31+
Assert.assertEquals(cpidRequest.getRequestPath(), RequestPath.GetCPID.getPath());
32+
}
33+
34+
@Test
35+
public void testGetLATD() throws Throwable{
36+
Branch branch = Branch.getInstance(getTestContext());
37+
38+
new BranchLastAttributedTouchData(null, getTestContext());
39+
40+
ServerRequestQueue queue = ServerRequestQueue.getInstance(getTestContext());
41+
Assert.assertEquals(2, queue.getSize());
42+
43+
ServerRequest cpidRequest = queue.peekAt(1);
44+
doFinalUpdate(cpidRequest);
45+
doFinalUpdateOnMainThread(cpidRequest);
46+
47+
Assert.assertEquals(cpidRequest.getRequestPath(), RequestPath.GetLATD.getPath());
48+
}
49+
50+
}

Branch-SDK/src/io/branch/referral/Branch.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import android.view.View;
2525

2626
import io.branch.referral.Defines.PreinstallKey;
27+
import io.branch.referral.util.BranchCrossPlatformId;
28+
import io.branch.referral.util.BranchCrossPlatformId.BranchCrossPlatformIdListener;
29+
import io.branch.referral.util.BranchLastAttributedTouchData;
30+
import io.branch.referral.util.BranchLastAttributedTouchData.BranchLastAttributedTouchDataListener;
2731
import org.json.JSONArray;
2832
import org.json.JSONException;
2933
import org.json.JSONObject;
@@ -1882,7 +1886,16 @@ public void setIdentity(@NonNull String userId, @Nullable BranchReferralInitList
18821886
}
18831887
}
18841888
}
1885-
1889+
1890+
public void getCrossPlatformIds(BranchCrossPlatformIdListener callback) {
1891+
new BranchCrossPlatformId(callback, context_);
1892+
}
1893+
1894+
public void getLastAttributedTouchData(BranchLastAttributedTouchDataListener callback, int attributionWindow) {
1895+
prefHelper_.setLATDAttributonWindow(attributionWindow);
1896+
new BranchLastAttributedTouchData(callback, context_);
1897+
}
1898+
18861899
/**
18871900
* Indicates whether or not this user has a custom identity specified for them. Note that this is independent of installs.
18881901
* If you call setIdentity, this device will have that identity associated with this user until logout is called.

Branch-SDK/src/io/branch/referral/Defines.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public enum Jsonkey {
9090
SdkVersion("sdk_version"),
9191
UIMode("ui_mode"),
9292
InstallMetadata("install_metadata"),
93+
LATDAttributionWindow("attribution_window"),
9394

9495
Clicked_Branch_Link("+clicked_branch_link"),
9596
IsFirstSession("+is_first_session"),
@@ -228,7 +229,9 @@ public enum RequestPath {
228229
DebugConnect("v1/debug/connect"),
229230
ContentEvent("v1/content-events"),
230231
TrackStandardEvent("v2/event/standard"),
231-
TrackCustomEvent("v2/event/custom");
232+
TrackCustomEvent("v2/event/custom"),
233+
GetCPID("v1/cpid"),
234+
GetLATD("v1/cpid/latd");
232235

233236
private String key = "";
234237

Branch-SDK/src/io/branch/referral/DeviceInfo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ void updateRequestWithV2Params(Context context, PrefHelper prefHelper, JSONObjec
193193
}
194194
}
195195

196+
/**
197+
* Update the given server request JSON with the set attribution window in the user data
198+
*
199+
* @param requestObj JSON object for Branch server request
200+
*/
201+
void updateRequestWithAttributionWindow(PrefHelper prefHelper, JSONObject requestObj) {
202+
try {
203+
if (prefHelper != null) {
204+
requestObj.put(Defines.Jsonkey.LATDAttributionWindow.getKey(), prefHelper.getLATDAttributonWindow());
205+
}
206+
} catch (JSONException ignore) {
207+
208+
}
209+
}
210+
196211
/**
197212
* get the package name for the this application
198213
*

Branch-SDK/src/io/branch/referral/PrefHelper.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public class PrefHelper {
6868
private static final String KEY_INSTALL_PARAMS = "bnc_install_params";
6969
private static final String KEY_USER_URL = "bnc_user_url";
7070
private static final String KEY_IS_REFERRABLE = "bnc_is_referrable";
71-
71+
private static final String KEY_LATD_ATTRIBUTION_WINDOW = "bnc_latd_attributon_window";
72+
7273
private static final String KEY_BUCKETS = "bnc_buckets";
7374
private static final String KEY_CREDIT_BASE = "bnc_credit_base_";
7475

@@ -907,6 +908,24 @@ public int getActionTotalCount(String action) {
907908
public int getActionUniqueCount(String action) {
908909
return getInteger(KEY_UNIQUE_BASE + action);
909910
}
911+
912+
/**
913+
* <p>Sets the latd attribution window</p>
914+
*
915+
* @param attributonWindow A {@link Integer} value containing the current attribution window passed
916+
*/
917+
public void setLATDAttributonWindow(int attributonWindow){
918+
setInteger(KEY_LATD_ATTRIBUTION_WINDOW, attributonWindow);
919+
}
920+
921+
/**
922+
* <p>Gets the latd attribution window</p>
923+
*
924+
* @return attributonWindow A {@link Integer} value containing the current attribution window set
925+
*/
926+
public int getLATDAttributonWindow(){
927+
return getInteger(KEY_LATD_ATTRIBUTION_WINDOW);
928+
}
910929

911930
// ALL GENERIC CALLS
912931

Branch-SDK/src/io/branch/referral/ServerRequest.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ enum PROCESS_WAIT_LOCK {
4242

4343
public enum BRANCH_API_VERSION {
4444
V1,
45+
V1_CPID,
46+
V1_LATD,
4547
V2
4648
}
4749

@@ -179,7 +181,23 @@ protected void setPost(JSONObject post) throws JSONException {
179181
DeviceInfo.getInstance().updateRequestWithV2Params(context_, prefHelper_, userDataObj);
180182
} catch (JSONException ignore) {
181183
}
182-
} else {
184+
} else if (getBranchRemoteAPIVersion() == BRANCH_API_VERSION.V1_CPID) {
185+
try {
186+
JSONObject userDataObj = new JSONObject();
187+
params_.put(Defines.Jsonkey.UserData.getKey(), userDataObj);
188+
DeviceInfo.getInstance().updateRequestWithV2Params(context_, prefHelper_, userDataObj);
189+
} catch (JSONException ignore) {
190+
}
191+
} else if (getBranchRemoteAPIVersion() == BRANCH_API_VERSION.V1_LATD) {
192+
try {
193+
JSONObject userDataObj = new JSONObject();
194+
params_.put(Defines.Jsonkey.UserData.getKey(), userDataObj);
195+
DeviceInfo.getInstance().updateRequestWithV2Params(context_, prefHelper_, userDataObj);
196+
DeviceInfo.getInstance().updateRequestWithAttributionWindow(prefHelper_, userDataObj);
197+
} catch (Exception ignore) {
198+
}
199+
}
200+
else {
183201
DeviceInfo.getInstance().updateRequestWithV1Params(params_);
184202
}
185203
}
@@ -372,7 +390,8 @@ private void updateGAdsParams() {
372390
String gaid = DeviceInfo.getInstance().getSystemObserver().getGAID();
373391
if (!TextUtils.isEmpty(gaid)) {
374392
try {
375-
if (version == BRANCH_API_VERSION.V2) {
393+
if (version == BRANCH_API_VERSION.V2 || version == BRANCH_API_VERSION.V1_CPID ||
394+
version == BRANCH_API_VERSION.V1_LATD) {
376395
JSONObject userDataObj = params_.optJSONObject(Defines.Jsonkey.UserData.getKey());
377396
if (userDataObj != null) {
378397
userDataObj.put(Defines.Jsonkey.AAID.getKey(), gaid);
@@ -387,9 +406,10 @@ private void updateGAdsParams() {
387406
e.printStackTrace();
388407
}
389408
} else { // Add unidentified_device when neither GAID nor AndroidID are present
390-
if (version == BRANCH_API_VERSION.V2) {
409+
if (version == BRANCH_API_VERSION.V2 || version == BRANCH_API_VERSION.V1_CPID) {
391410
try {
392-
if (version == BRANCH_API_VERSION.V2) {
411+
if (version == BRANCH_API_VERSION.V2 || version == BRANCH_API_VERSION.V1_CPID ||
412+
version == BRANCH_API_VERSION.V1_LATD) {
393413
JSONObject userDataObj = params_.optJSONObject(Defines.Jsonkey.UserData.getKey());
394414
if (userDataObj != null) {
395415
if (!userDataObj.has(Defines.Jsonkey.AndroidID.getKey())) {

0 commit comments

Comments
 (0)