Skip to content

Commit 3d3ae24

Browse files
Merge branch 'staging' into auto_user_props_save
2 parents cf4fa09 + 7ec98f9 commit 3d3ae24

File tree

6 files changed

+112
-33
lines changed

6 files changed

+112
-33
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
## XX.XX.XX
1+
## 24.1.4
22
* ! Minor breaking change ! User properties will now be automatically saved under the following conditions:
33
* When an event is recorded
44
* During an internal timer tick
55
* Upon flushing the event queue
6-
6+
* When a session call made
7+
* Cleaned up unused gradle dependencies from root build.gradle.
8+
79
## 24.1.3
810
* Extended minimum JDK support to 8.
911

1012
## 24.1.2
13+
1114
* !! Major Breaking Change !! Minimum JDK support is 19 for this minor.
1215

1316
* Migrated from Sonatype OSSRH.
@@ -219,3 +222,4 @@
219222

220223
* initial SDK release
221224
* MavenCentral rerelease
225+

build.gradle

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
repositories {
5-
google()
6-
mavenCentral()
7-
jcenter()
8-
maven {
9-
url "https://maven.google.com"
10-
}
11-
}
12-
dependencies {
13-
classpath 'com.android.tools.build:gradle:8.1.4'
14-
classpath 'com.github.dcendents:android-maven-plugin:1.2'
15-
classpath 'com.google.gms:google-services:4.4.2'
16-
17-
// NOTE: Do not place your application dependencies here; they belong
18-
// in the individual module build.gradle files
19-
}
4+
repositories {
5+
google()
6+
mavenCentral()
7+
}
208
}
219

2210
allprojects {
23-
ext.CLY_VERSION = "24.1.3"
24-
ext.POWERMOCK_VERSION = "1.7.4"
11+
ext.CLY_VERSION = "24.1.3"
12+
ext.POWERMOCK_VERSION = "1.7.4"
2513

26-
tasks.withType(Javadoc) {
27-
options.addStringOption('Xdoclint:none', '-quiet')
28-
}
29-
repositories {
30-
google()
31-
jcenter()
32-
//mavenLocal()
33-
maven {
34-
url "https://maven.google.com" // Google's Maven repository
35-
}
36-
}
14+
tasks.withType(Javadoc) {
15+
options.addStringOption('Xdoclint:none', '-quiet')
16+
}
17+
repositories {
18+
google()
19+
mavenCentral()
20+
}
3721
}

sdk-java/build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ buildscript {
88
//mavenLocal()
99
}
1010
dependencies {
11-
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.28.0' //for publishing
11+
// Load publish plugin ONLY when publish task is requested
12+
if (gradle.startParameter.taskNames.any { it.toLowerCase().contains("publish") }) {
13+
// This requires minimum java 11 to work
14+
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.28.0'
15+
}
1216
}
1317
}
1418

@@ -28,4 +32,6 @@ dependencies {
2832
//testImplementation 'com.squareup.okhttp3:mockwebserver:3.7.0'
2933
}
3034

31-
apply plugin: "com.vanniktech.maven.publish"
35+
if (gradle.startParameter.taskNames.any { it.toLowerCase().contains("publish") }) {
36+
apply plugin: "com.vanniktech.maven.publish"
37+
}

sdk-java/src/main/java/ly/count/sdk/java/Config.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ public String toString() {
14891489
* - When an event is recorded
14901490
* - During an internal timer tick
14911491
* - Upon flushing the event queue
1492+
* - When a session call made
14921493
*
14931494
* @return {@code this} instance for method chaining
14941495
*/

sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ Future<Boolean> begin(Long now) {
118118
}
119119

120120
this.consents = SDKCore.instance.consents;
121+
if (config.isAutoSendUserPropertiesOnSessions() && config.sdk.userProfile() != null) {
122+
config.sdk.module(ModuleUserProfile.class).saveInternal();
123+
}
121124

122125
if (pushOnChange) {
123126
Storage.pushAsync(config, this);
@@ -157,6 +160,9 @@ Future<Boolean> update(Long now) {
157160
}
158161

159162
this.consents = SDKCore.instance.consents;
163+
if (config.isAutoSendUserPropertiesOnSessions() && config.sdk.userProfile() != null) {
164+
config.sdk.module(ModuleUserProfile.class).saveInternal();
165+
}
160166

161167
Long duration = updateDuration(now);
162168

@@ -192,6 +198,9 @@ Future<Boolean> end(Long now, final Tasks.Callback<Boolean> callback, String did
192198
ended = now == null ? System.nanoTime() : now;
193199

194200
this.consents = SDKCore.instance.consents;
201+
if (config.isAutoSendUserPropertiesOnSessions() && config.sdk.userProfile() != null) {
202+
config.sdk.module(ModuleUserProfile.class).saveInternal();
203+
}
195204

196205
if (currentView != null) {
197206
currentView.stop(true);

sdk-java/src/test/java/ly/count/sdk/java/internal/SessionImplTests.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,81 @@ public void view_stopStartedAndNext() {
629629
ModuleViewsTests.validateView("next", 0.0, 2, 3, false, true, null, TestUtils.keysValues[1], TestUtils.keysValues[0]);
630630
}
631631

632+
/**
633+
* Validates that when session calls are made, if any user properties are set,
634+
* they are sent before sending that session call
635+
* Validated with all session calls: begin, update, end
636+
*
637+
* @throws InterruptedException if thread is interrupted
638+
*/
639+
@Test
640+
public void userPropsOnSessions() throws InterruptedException {
641+
Countly.instance().init(TestUtils.getConfigSessions(Config.Feature.UserProfiles));
642+
Countly.instance().userProfile().setProperty("name", "John Doe");
643+
Countly.instance().userProfile().setProperty("custom_key", "custom_value");
644+
645+
Countly.session().begin();
646+
Map<String, String>[] RQ = TestUtils.getCurrentRQ();
647+
UserEditorTests.validateUserDetailsRequestInRQ(TestUtils.map("user_details", TestUtils.json("name", "John Doe", "custom", TestUtils.map("custom_key", "custom_value"))), 0, 2);
648+
Assert.assertEquals("1", RQ[1].get("begin_session"));
649+
650+
Thread.sleep(2000); // wait for session to update
651+
Countly.instance().userProfile().save();
652+
RQ = TestUtils.getCurrentRQ();
653+
Assert.assertEquals(2, RQ.length); // Validate that user properties are flushed
654+
655+
Countly.instance().userProfile().setProperty("email", "[email protected]");
656+
Countly.session().update();
657+
658+
RQ = TestUtils.getCurrentRQ();
659+
Assert.assertEquals(TestUtils.json("email", "[email protected]"), RQ[2].get("user_details"));
660+
Assert.assertEquals("2", RQ[3].get("session_duration"));
661+
662+
Thread.sleep(2000); // wait for session to update
663+
Countly.instance().userProfile().save();
664+
RQ = TestUtils.getCurrentRQ();
665+
Assert.assertEquals(4, RQ.length); // Validate that user properties are flushed with update call
666+
667+
Countly.instance().userProfile().setProperty("done", "yes");
668+
Countly.session().end();
669+
670+
RQ = TestUtils.getCurrentRQ();
671+
Assert.assertEquals(TestUtils.json("custom", TestUtils.map("done", "yes")), RQ[4].get("user_details"));
672+
Assert.assertEquals("1", RQ[5].get("end_session"));
673+
}
674+
675+
/**
676+
* Validates that when session calls are made, if any user properties are set,
677+
* they are not packed because auto-send is disabled
678+
*
679+
* @throws InterruptedException if thread is interrupted
680+
*/
681+
@Test
682+
public void userPropsOnSessions_reversed() throws InterruptedException {
683+
Countly.instance().init(TestUtils.getConfigSessions(Config.Feature.UserProfiles).disableAutoSendUserPropertiesOnSessions());
684+
Countly.instance().userProfile().setProperty("name", "John Doe");
685+
Countly.instance().userProfile().setProperty("custom_key", "custom_value");
686+
687+
Countly.session().begin();
688+
Map<String, String>[] RQ = TestUtils.getCurrentRQ();
689+
Assert.assertEquals(1, RQ.length);
690+
Assert.assertEquals("1", RQ[0].get("begin_session"));
691+
692+
Thread.sleep(2000); // wait for session to update
693+
Countly.session().update();
694+
RQ = TestUtils.getCurrentRQ();
695+
696+
Assert.assertEquals(2, RQ.length);
697+
Assert.assertEquals("2", RQ[1].get("session_duration"));
698+
699+
Thread.sleep(2000);
700+
Countly.session().end();
701+
RQ = TestUtils.getCurrentRQ();
702+
703+
Assert.assertEquals(3, RQ.length);
704+
Assert.assertEquals("1", RQ[2].get("end_session"));
705+
}
706+
632707
private void validateNotEquals(int idOffset, BiFunction<SessionImpl, SessionImpl, Consumer<Long>> setter) {
633708
Countly.instance().init(TestUtils.getConfigSessions());
634709
long ts = TimeUtils.timestampMs();

0 commit comments

Comments
 (0)