Skip to content

Commit 63efc37

Browse files
committed
Install referrer refactoring
1 parent 7d1998e commit 63efc37

File tree

11 files changed

+395
-324
lines changed

11 files changed

+395
-324
lines changed

Adjust/adjust/src/main/java/com/adjust/sdk/ActivityHandler.java

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ public void finishedTrackingActivity(ResponseData responseData) {
331331
}
332332
// redirect sdk click responses to attribution handler to check for attribution information
333333
if (responseData instanceof SdkClickResponseData) {
334+
checkForInstallReferrerInfo((SdkClickResponseData) responseData);
334335
attributionHandler.checkSdkClickResponse((SdkClickResponseData)responseData);
335336
return;
336337
}
@@ -424,11 +425,21 @@ public void run() {
424425
}
425426

426427
@Override
427-
public void sendReferrer() {
428+
public void sendReftagReferrer() {
428429
scheduledExecutor.submit(new Runnable() {
429430
@Override
430431
public void run() {
431-
sendReferrerI();
432+
sendReftagReferrerI();
433+
}
434+
});
435+
}
436+
437+
@Override
438+
public void sendInstallReferrer(final long clickTime, final long installBegin, final String installReferrer) {
439+
scheduledExecutor.submit(new Runnable() {
440+
@Override
441+
public void run() {
442+
sendInstallReferrerI(clickTime, installBegin, installReferrer);
432443
}
433444
});
434445
}
@@ -746,7 +757,7 @@ public void run() {
746757

747758
installReferrer = new InstallReferrer(adjustConfig.context, this);
748759

749-
sendReferrerI();
760+
sendReftagReferrerI();
750761
}
751762

752763
private void readConfigFile(Context context) {
@@ -1264,12 +1275,37 @@ private void setAskingAttributionI(boolean askingAttribution) {
12641275
writeActivityStateI();
12651276
}
12661277

1267-
private void sendReferrerI() {
1278+
private void sendReftagReferrerI() {
12681279
if (!isEnabledI()) {
12691280
return;
12701281
}
12711282

1272-
sdkClickHandler.sendSavedReferrers();
1283+
sdkClickHandler.sendReftagReferrers();
1284+
}
1285+
1286+
private void sendInstallReferrerI(final long clickTime, final long installBegin, final String installReferrer) {
1287+
if (!isEnabledI()) {
1288+
return;
1289+
}
1290+
1291+
if (activityState.clickTime == clickTime
1292+
&& activityState.installBegin == installBegin
1293+
&& activityState.installReferrer.equals(installReferrer)) {
1294+
// Same click already sent before, nothing to be done.
1295+
return;
1296+
}
1297+
1298+
// Create sdk click
1299+
ActivityPackage sdkClickPackage = PackageFactory.buildInstallReferrerSdkClickPackage(
1300+
installReferrer,
1301+
clickTime,
1302+
installBegin,
1303+
activityState,
1304+
adjustConfig,
1305+
deviceInfo,
1306+
sessionParameters);
1307+
1308+
sdkClickHandler.sendSdkClick(sdkClickPackage);
12731309
}
12741310

12751311
private void readOpenUrlI(Uri url, long clickTime) {
@@ -1835,4 +1871,16 @@ private boolean toSendI(boolean sdkClickHandlerOnly) {
18351871
// doesn't have the option -> depends on being on the background/foreground
18361872
return internalState.isInForeground();
18371873
}
1874+
1875+
private void checkForInstallReferrerInfo(final SdkClickResponseData responseData) {
1876+
if (!responseData.isInstallReferrer) {
1877+
return;
1878+
}
1879+
1880+
activityState.clickTime = responseData.clickTime;
1881+
activityState.installBegin = responseData.installBegin;
1882+
activityState.installReferrer = responseData.installReferrer;
1883+
1884+
writeActivityStateI();
1885+
}
18381886
}

Adjust/adjust/src/main/java/com/adjust/sdk/ActivityState.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
import java.io.Serializable;
1818
import java.util.Calendar;
1919
import java.util.LinkedList;
20-
import java.util.List;
2120
import java.util.Locale;
2221

2322
public class ActivityState implements Serializable, Cloneable {
2423
private static final long serialVersionUID = 9039439291143138148L;
25-
private static int ORDER_ID_MAXCOUNT = 10;
24+
private static final int ORDER_ID_MAXCOUNT = 10;
2625
private transient ILogger logger;
2726
private static final ObjectStreamField[] serialPersistentFields = {
2827
new ObjectStreamField("uuid", String.class),
@@ -39,6 +38,9 @@ public class ActivityState implements Serializable, Cloneable {
3938
new ObjectStreamField("orderIds", (Class<LinkedList<String>>)(Class) LinkedList.class),
4039
new ObjectStreamField("pushToken", String.class),
4140
new ObjectStreamField("adid", String.class),
41+
new ObjectStreamField("clickTime", long.class),
42+
new ObjectStreamField("installBegin", long.class),
43+
new ObjectStreamField("installReferrer", String.class),
4244
};
4345

4446
// persistent data
@@ -65,13 +67,16 @@ public class ActivityState implements Serializable, Cloneable {
6567
protected String pushToken;
6668
protected String adid;
6769

70+
protected long clickTime;
71+
protected long installBegin;
72+
protected String installReferrer;
73+
6874
protected ActivityState() {
6975
logger = AdjustFactory.getLogger();
7076
// create UUID for new devices
7177
uuid = Util.createUuid();
7278
enabled = true;
7379
askingAttribution = false;
74-
7580
eventCount = 0; // no events yet
7681
sessionCount = 0; // the first session just started
7782
subsessionCount = -1; // we don't know how many subsessions this first session will have
@@ -83,6 +88,9 @@ protected ActivityState() {
8388
orderIds = null;
8489
pushToken = null;
8590
adid = null;
91+
clickTime = 0;
92+
installBegin = 0;
93+
installReferrer = null;
8694
}
8795

8896
protected void resetSessionAttributes(long now) {
@@ -127,19 +135,22 @@ public boolean equals(Object other) {
127135
if (getClass() != other.getClass()) return false;
128136
ActivityState otherActivityState = (ActivityState) other;
129137

130-
if (!Util.equalString(uuid, otherActivityState.uuid)) return false;
131-
if (!Util.equalBoolean(enabled, otherActivityState.enabled)) return false;
132-
if (!Util.equalBoolean(askingAttribution, otherActivityState.askingAttribution)) return false;
133-
if (!Util.equalInt(eventCount, otherActivityState.eventCount)) return false;
134-
if (!Util.equalInt(sessionCount, otherActivityState.sessionCount)) return false;
135-
if (!Util.equalInt(subsessionCount, otherActivityState.subsessionCount)) return false;
136-
if (!Util.equalLong(sessionLength, otherActivityState.sessionLength)) return false;
137-
if (!Util.equalLong(timeSpent, otherActivityState.timeSpent)) return false;
138-
if (!Util.equalLong(lastInterval, otherActivityState.lastInterval)) return false;
139-
if (!Util.equalBoolean(updatePackages, otherActivityState.updatePackages)) return false;
138+
if (!Util.equalString(uuid, otherActivityState.uuid)) return false;
139+
if (!Util.equalBoolean(enabled, otherActivityState.enabled)) return false;
140+
if (!Util.equalBoolean(askingAttribution, otherActivityState.askingAttribution)) return false;
141+
if (!Util.equalInt(eventCount, otherActivityState.eventCount)) return false;
142+
if (!Util.equalInt(sessionCount, otherActivityState.sessionCount)) return false;
143+
if (!Util.equalInt(subsessionCount, otherActivityState.subsessionCount)) return false;
144+
if (!Util.equalLong(sessionLength, otherActivityState.sessionLength)) return false;
145+
if (!Util.equalLong(timeSpent, otherActivityState.timeSpent)) return false;
146+
if (!Util.equalLong(lastInterval, otherActivityState.lastInterval)) return false;
147+
if (!Util.equalBoolean(updatePackages, otherActivityState.updatePackages)) return false;
140148
if (!Util.equalObject(orderIds, otherActivityState.orderIds)) return false;
141149
if (!Util.equalString(pushToken, otherActivityState.pushToken)) return false;
142150
if (!Util.equalString(adid, otherActivityState.adid)) return false;
151+
if (!Util.equalLong(clickTime, otherActivityState.clickTime)) return false;
152+
if (!Util.equalLong(installBegin, otherActivityState.installBegin)) return false;
153+
if (!Util.equalString(installReferrer, otherActivityState.installReferrer)) return false;
143154
return true;
144155
}
145156

@@ -159,6 +170,9 @@ public int hashCode() {
159170
hashCode = 37 * hashCode + Util.hashObject(orderIds);
160171
hashCode = 37 * hashCode + Util.hashString(pushToken);
161172
hashCode = 37 * hashCode + Util.hashString(adid);
173+
hashCode = 37 * hashCode + Util.hashLong(clickTime);
174+
hashCode = 37 * hashCode + Util.hashLong(installBegin);
175+
hashCode = 37 * hashCode + Util.hashString(installReferrer);
162176
return hashCode;
163177
}
164178

@@ -179,13 +193,14 @@ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFo
179193
askingAttribution = Util.readBooleanField(fields, "askingAttribution", false);
180194

181195
updatePackages = Util.readBooleanField(fields, "updatePackages", false);
182-
183196
orderIds = Util.readObjectField(fields, "orderIds", null);
184-
185197
pushToken = Util.readStringField(fields, "pushToken", null);
186-
187198
adid = Util.readStringField(fields, "adid", null);
188199

200+
clickTime = Util.readLongField(fields, "clickTime", -1l);
201+
installBegin = Util.readLongField(fields, "installBegin", -1l);
202+
installReferrer = Util.readStringField(fields, "installReferrer", null);
203+
189204
// create UUID for migrating devices
190205
if (uuid == null) {
191206
uuid = Util.createUuid();

Adjust/adjust/src/main/java/com/adjust/sdk/AdjustInstance.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void onCreate(final AdjustConfig adjustConfig) {
5656

5757
activityHandler = AdjustFactory.getActivityHandler(adjustConfig);
5858

59-
setSendingReferrersAsUnsend(adjustConfig.context);
59+
setSendingReferrersAsNotSent(adjustConfig.context);
6060
}
6161

6262
/**
@@ -152,7 +152,7 @@ public void sendReferrer(final String rawReferrer, final Context context) {
152152

153153
if (checkActivityHandler("referrer")) {
154154
if (activityHandler.isEnabled()) {
155-
activityHandler.sendReferrer();
155+
activityHandler.sendReftagReferrer();
156156
}
157157
}
158158
}
@@ -456,9 +456,9 @@ private void savePushToken(final String pushToken, final Context context) {
456456
sharedPreferencesManager.savePushToken(pushToken);
457457
}
458458

459-
private void setSendingReferrersAsUnsend(final Context context) {
459+
private void setSendingReferrersAsNotSent(final Context context) {
460460
SharedPreferencesManager sharedPreferencesManager = new SharedPreferencesManager(context);
461-
sharedPreferencesManager.setSendingReferrersAsUnsend();
461+
sharedPreferencesManager.setSendingReferrersAsNotSent();
462462
}
463463

464464
/**

Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface Constants {
3232
String CLIENT_SDK = "android4.12.0";
3333
String LOGTAG = "Adjust";
3434
String REFTAG = "reftag";
35+
String INSTALL_REFERRER = "install_referrer";
3536
String DEEPLINK = "deeplink";
3637
String PUSH = "push";
3738
String THREAD_PREFIX = "Adjust-";

Adjust/adjust/src/main/java/com/adjust/sdk/IActivityHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public interface IActivityHandler {
3333

3434
void launchAttributionResponseTasks(AttributionResponseData attributionResponseData);
3535

36-
void sendReferrer();
36+
void sendReftagReferrer();
37+
38+
void sendInstallReferrer(long clickTime, long installBegin, String installReferrer);
3739

3840
void setOfflineMode(boolean enabled);
3941

Adjust/adjust/src/main/java/com/adjust/sdk/ISdkClickHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public interface ISdkClickHandler {
3434
void sendSdkClick(ActivityPackage sdkClick);
3535

3636
/**
37-
* Send sdk_click packages made from all the persisted referrers.
37+
* Send sdk_click packages made from all the persisted intent type referrers.
3838
*/
39-
void sendSavedReferrers();
39+
void sendReftagReferrers();
4040

4141
/**
4242
* Teardown SdkClickHandler instance.

0 commit comments

Comments
 (0)