From 3fd2009e25a42a3411faa091824ecdb102d97976 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 5 Apr 2024 11:43:05 +0200 Subject: [PATCH 01/10] chore: move internal classes to `internal` package --- .../src/main/java/com/example/InternalDebugOnlyData.java | 2 +- example/src/main/java/com/example/MainActivity.java | 2 +- .../java/com/parsely/parselyandroid/FunctionalTests.kt | 1 + .../main/java/com/parsely/parselyandroid/ParselyTracker.kt | 1 + .../{ => internal}/AdvertisementIdProvider.kt | 4 ++-- .../com/parsely/parselyandroid/{ => internal}/Clock.kt | 2 +- .../{ => internal}/ConnectivityStatusProvider.kt | 5 +++-- .../parselyandroid/{ => internal}/DeviceInfoRepository.kt | 4 ++-- .../parselyandroid/{ => internal}/EngagementManager.kt | 5 +++-- .../parsely/parselyandroid/{ => internal}/EventQueuer.kt | 2 +- .../parsely/parselyandroid/{ => internal}/EventsBuilder.kt | 7 +++---- .../parsely/parselyandroid/{ => internal}/FlushManager.kt | 2 +- .../parsely/parselyandroid/{ => internal}/FlushQueue.kt | 6 +++--- .../{ => internal}/HeartbeatIntervalCalculator.kt | 2 +- .../parselyandroid/{ => internal}/InMemoryBuffer.kt | 4 ++-- .../parselyandroid/{ => internal}/JsonSerializer.kt | 2 +- .../{ => internal}/LocalStorageRepository.kt | 4 ++-- .../com/parsely/parselyandroid/{ => internal}/Logging.kt | 2 +- .../parselyandroid/{ => internal}/ParselyAPIConnection.kt | 2 +- .../parselyandroid/{ => internal}/ParselyCoroutineScope.kt | 2 +- .../{ => internal}/ParselyTrackerInternal.kt | 5 ++++- .../parselyandroid/AndroidDeviceInfoRepositoryTest.kt | 1 + .../com/parsely/parselyandroid/AndroidIdProviderTest.kt | 1 + .../com/parsely/parselyandroid/EngagementManagerTest.kt | 5 ++++- .../java/com/parsely/parselyandroid/EventsBuilderTest.kt | 3 +++ .../java/com/parsely/parselyandroid/FlushManagerTest.kt | 1 + .../test/java/com/parsely/parselyandroid/FlushQueueTest.kt | 5 +++++ .../parselyandroid/HeartbeatIntervalCalculatorTest.kt | 5 +++-- .../java/com/parsely/parselyandroid/InMemoryBufferTest.kt | 2 ++ .../parsely/parselyandroid/LocalStorageRepositoryTest.kt | 1 + .../com/parsely/parselyandroid/ParselyAPIConnectionTest.kt | 1 + 31 files changed, 58 insertions(+), 33 deletions(-) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/AdvertisementIdProvider.kt (93%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/Clock.kt (86%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/ConnectivityStatusProvider.kt (85%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/DeviceInfoRepository.kt (92%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/EngagementManager.kt (94%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/EventQueuer.kt (65%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/EventsBuilder.kt (92%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/FlushManager.kt (96%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/FlushQueue.kt (91%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/HeartbeatIntervalCalculator.kt (94%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/InMemoryBuffer.kt (92%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/JsonSerializer.kt (95%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/LocalStorageRepository.kt (96%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/Logging.kt (88%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/ParselyAPIConnection.kt (97%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/ParselyCoroutineScope.kt (86%) rename parsely/src/main/java/com/parsely/parselyandroid/{ => internal}/ParselyTrackerInternal.kt (97%) diff --git a/example/src/main/java/com/example/InternalDebugOnlyData.java b/example/src/main/java/com/example/InternalDebugOnlyData.java index 59a0f2f3..00ad0591 100644 --- a/example/src/main/java/com/example/InternalDebugOnlyData.java +++ b/example/src/main/java/com/example/InternalDebugOnlyData.java @@ -1,6 +1,6 @@ package com.example; -import com.parsely.parselyandroid.ParselyTrackerInternal; +import com.parsely.parselyandroid.internal.ParselyTrackerInternal; import org.jetbrains.annotations.Nullable; diff --git a/example/src/main/java/com/example/MainActivity.java b/example/src/main/java/com/example/MainActivity.java index 89ecbca5..c5164f9e 100644 --- a/example/src/main/java/com/example/MainActivity.java +++ b/example/src/main/java/com/example/MainActivity.java @@ -8,7 +8,7 @@ import android.widget.TextView; import com.parsely.parselyandroid.ParselyTracker; -import com.parsely.parselyandroid.ParselyTrackerInternal; +import com.parsely.parselyandroid.internal.ParselyTrackerInternal; import com.parsely.parselyandroid.ParselyVideoMetadata; import java.util.ArrayList; diff --git a/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt b/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt index 4d555df3..79ca72ba 100644 --- a/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt +++ b/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.core.type.TypeReference import com.fasterxml.jackson.databind.ObjectMapper +import com.parsely.parselyandroid.internal.ParselyTrackerInternal import java.io.File import java.io.FileInputStream import java.io.ObjectInputStream diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt index 3ee7a63a..24ca772b 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt @@ -16,6 +16,7 @@ package com.parsely.parselyandroid import android.content.Context +import com.parsely.parselyandroid.internal.ParselyTrackerInternal import org.jetbrains.annotations.TestOnly /** diff --git a/parsely/src/main/java/com/parsely/parselyandroid/AdvertisementIdProvider.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/AdvertisementIdProvider.kt similarity index 93% rename from parsely/src/main/java/com/parsely/parselyandroid/AdvertisementIdProvider.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/AdvertisementIdProvider.kt index 87e93a84..14227241 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/AdvertisementIdProvider.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/AdvertisementIdProvider.kt @@ -1,9 +1,9 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import android.content.Context import android.provider.Settings import com.google.android.gms.ads.identifier.AdvertisingIdClient -import com.parsely.parselyandroid.Logging.log +import com.parsely.parselyandroid.internal.Logging.log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/parsely/src/main/java/com/parsely/parselyandroid/Clock.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/Clock.kt similarity index 86% rename from parsely/src/main/java/com/parsely/parselyandroid/Clock.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/Clock.kt index 3d64e171..3654d4e5 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/Clock.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/Clock.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import java.util.Calendar import java.util.TimeZone diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ConnectivityStatusProvider.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/ConnectivityStatusProvider.kt similarity index 85% rename from parsely/src/main/java/com/parsely/parselyandroid/ConnectivityStatusProvider.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/ConnectivityStatusProvider.kt index f7d90842..e8e0c5f5 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/ConnectivityStatusProvider.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/ConnectivityStatusProvider.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import android.content.Context import android.net.ConnectivityManager @@ -10,7 +10,8 @@ internal interface ConnectivityStatusProvider { fun isReachable(): Boolean } -internal class AndroidConnectivityStatusProvider(private val context: Context): ConnectivityStatusProvider { +internal class AndroidConnectivityStatusProvider(private val context: Context): + ConnectivityStatusProvider { override fun isReachable(): Boolean { val cm = context.getSystemService( diff --git a/parsely/src/main/java/com/parsely/parselyandroid/DeviceInfoRepository.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/DeviceInfoRepository.kt similarity index 92% rename from parsely/src/main/java/com/parsely/parselyandroid/DeviceInfoRepository.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/DeviceInfoRepository.kt index 61abdc4f..dbb86eec 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/DeviceInfoRepository.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/DeviceInfoRepository.kt @@ -1,7 +1,7 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import android.os.Build -import com.parsely.parselyandroid.Logging.log +import com.parsely.parselyandroid.internal.Logging.log internal interface DeviceInfoRepository{ fun collectDeviceInfo(): Map diff --git a/parsely/src/main/java/com/parsely/parselyandroid/EngagementManager.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/EngagementManager.kt similarity index 94% rename from parsely/src/main/java/com/parsely/parselyandroid/EngagementManager.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/EngagementManager.kt index 4bb39ac3..9269d3ad 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/EngagementManager.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/EngagementManager.kt @@ -1,6 +1,7 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal -import com.parsely.parselyandroid.Logging.log +import com.parsely.parselyandroid.internal.Logging.log +import com.parsely.parselyandroid.ParselyVideoMetadata import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.delay diff --git a/parsely/src/main/java/com/parsely/parselyandroid/EventQueuer.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/EventQueuer.kt similarity index 65% rename from parsely/src/main/java/com/parsely/parselyandroid/EventQueuer.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/EventQueuer.kt index 37b6ee63..02c68c48 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/EventQueuer.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/EventQueuer.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal internal interface EventQueuer { fun enqueueEvent(event: Map) diff --git a/parsely/src/main/java/com/parsely/parselyandroid/EventsBuilder.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/EventsBuilder.kt similarity index 92% rename from parsely/src/main/java/com/parsely/parselyandroid/EventsBuilder.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/EventsBuilder.kt index 945c8b33..5356c975 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/EventsBuilder.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/EventsBuilder.kt @@ -1,8 +1,7 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal -import com.parsely.parselyandroid.Logging.log -import java.util.Calendar -import java.util.TimeZone +import com.parsely.parselyandroid.internal.Logging.log +import com.parsely.parselyandroid.ParselyMetadata internal class EventsBuilder( private val deviceInfoRepository: DeviceInfoRepository, diff --git a/parsely/src/main/java/com/parsely/parselyandroid/FlushManager.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushManager.kt similarity index 96% rename from parsely/src/main/java/com/parsely/parselyandroid/FlushManager.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/FlushManager.kt index 5026c8d8..f633f239 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/FlushManager.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushManager.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job diff --git a/parsely/src/main/java/com/parsely/parselyandroid/FlushQueue.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushQueue.kt similarity index 91% rename from parsely/src/main/java/com/parsely/parselyandroid/FlushQueue.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/FlushQueue.kt index b5779d5f..a9ea2c0c 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/FlushQueue.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushQueue.kt @@ -1,7 +1,7 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal -import com.parsely.parselyandroid.JsonSerializer.toParselyEventsPayload -import com.parsely.parselyandroid.Logging.log +import com.parsely.parselyandroid.internal.JsonSerializer.toParselyEventsPayload +import com.parsely.parselyandroid.internal.Logging.log import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex diff --git a/parsely/src/main/java/com/parsely/parselyandroid/HeartbeatIntervalCalculator.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/HeartbeatIntervalCalculator.kt similarity index 94% rename from parsely/src/main/java/com/parsely/parselyandroid/HeartbeatIntervalCalculator.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/HeartbeatIntervalCalculator.kt index d50223ff..12624b5b 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/HeartbeatIntervalCalculator.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/HeartbeatIntervalCalculator.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes diff --git a/parsely/src/main/java/com/parsely/parselyandroid/InMemoryBuffer.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/InMemoryBuffer.kt similarity index 92% rename from parsely/src/main/java/com/parsely/parselyandroid/InMemoryBuffer.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/InMemoryBuffer.kt index 63f6e70a..8b49f32c 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/InMemoryBuffer.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/InMemoryBuffer.kt @@ -1,6 +1,6 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal -import com.parsely.parselyandroid.Logging.log +import com.parsely.parselyandroid.internal.Logging.log import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay diff --git a/parsely/src/main/java/com/parsely/parselyandroid/JsonSerializer.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/JsonSerializer.kt similarity index 95% rename from parsely/src/main/java/com/parsely/parselyandroid/JsonSerializer.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/JsonSerializer.kt index dde232ce..50efb81e 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/JsonSerializer.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/JsonSerializer.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import com.fasterxml.jackson.databind.ObjectMapper import java.io.IOException diff --git a/parsely/src/main/java/com/parsely/parselyandroid/LocalStorageRepository.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/LocalStorageRepository.kt similarity index 96% rename from parsely/src/main/java/com/parsely/parselyandroid/LocalStorageRepository.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/LocalStorageRepository.kt index f8dc30fe..b7051228 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/LocalStorageRepository.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/LocalStorageRepository.kt @@ -1,7 +1,7 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import android.content.Context -import com.parsely.parselyandroid.Logging.log +import com.parsely.parselyandroid.internal.Logging.log import java.io.EOFException import java.io.FileNotFoundException import java.io.ObjectInputStream diff --git a/parsely/src/main/java/com/parsely/parselyandroid/Logging.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/Logging.kt similarity index 88% rename from parsely/src/main/java/com/parsely/parselyandroid/Logging.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/Logging.kt index cdee406a..e2ee3f84 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/Logging.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/Logging.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import java.util.Formatter diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyAPIConnection.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyAPIConnection.kt similarity index 97% rename from parsely/src/main/java/com/parsely/parselyandroid/ParselyAPIConnection.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyAPIConnection.kt index c1c1e422..c4fec063 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyAPIConnection.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyAPIConnection.kt @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import java.net.HttpURLConnection import java.net.URL diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyCoroutineScope.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyCoroutineScope.kt similarity index 86% rename from parsely/src/main/java/com/parsely/parselyandroid/ParselyCoroutineScope.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyCoroutineScope.kt index 1c7be0fe..938489d6 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyCoroutineScope.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyCoroutineScope.kt @@ -1,4 +1,4 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTrackerInternal.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyTrackerInternal.kt similarity index 97% rename from parsely/src/main/java/com/parsely/parselyandroid/ParselyTrackerInternal.kt rename to parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyTrackerInternal.kt index a88a999c..6c0c817d 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTrackerInternal.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyTrackerInternal.kt @@ -1,9 +1,12 @@ -package com.parsely.parselyandroid +package com.parsely.parselyandroid.internal import android.content.Context import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.ProcessLifecycleOwner +import com.parsely.parselyandroid.ParselyMetadata +import com.parsely.parselyandroid.ParselyTracker +import com.parsely.parselyandroid.ParselyVideoMetadata import java.util.UUID internal class ParselyTrackerInternal internal constructor( diff --git a/parsely/src/test/java/com/parsely/parselyandroid/AndroidDeviceInfoRepositoryTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/AndroidDeviceInfoRepositoryTest.kt index 08ef47b8..e1f3f345 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/AndroidDeviceInfoRepositoryTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/AndroidDeviceInfoRepositoryTest.kt @@ -1,5 +1,6 @@ package com.parsely.parselyandroid +import com.parsely.parselyandroid.internal.AndroidDeviceInfoRepository import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test diff --git a/parsely/src/test/java/com/parsely/parselyandroid/AndroidIdProviderTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/AndroidIdProviderTest.kt index eaf24427..49e11288 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/AndroidIdProviderTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/AndroidIdProviderTest.kt @@ -3,6 +3,7 @@ package com.parsely.parselyandroid import android.app.Application import android.provider.Settings import androidx.test.core.app.ApplicationProvider +import com.parsely.parselyandroid.internal.AndroidIdProvider import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test diff --git a/parsely/src/test/java/com/parsely/parselyandroid/EngagementManagerTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/EngagementManagerTest.kt index 45b797c5..7612d4a3 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/EngagementManagerTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/EngagementManagerTest.kt @@ -1,6 +1,9 @@ package com.parsely.parselyandroid -import androidx.test.core.app.ApplicationProvider +import com.parsely.parselyandroid.internal.Clock +import com.parsely.parselyandroid.internal.EngagementManager +import com.parsely.parselyandroid.internal.EventQueuer +import com.parsely.parselyandroid.internal.HeartbeatIntervalCalculator import kotlin.time.Duration import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds diff --git a/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt index 05af5efb..2c3963cd 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt @@ -1,5 +1,8 @@ package com.parsely.parselyandroid +import com.parsely.parselyandroid.internal.Clock +import com.parsely.parselyandroid.internal.DeviceInfoRepository +import com.parsely.parselyandroid.internal.EventsBuilder import kotlin.time.Duration import kotlin.time.Duration.Companion.hours import org.assertj.core.api.Assertions.assertThat diff --git a/parsely/src/test/java/com/parsely/parselyandroid/FlushManagerTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/FlushManagerTest.kt index 02842a2c..efdb57a5 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/FlushManagerTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/FlushManagerTest.kt @@ -1,5 +1,6 @@ package com.parsely.parselyandroid +import com.parsely.parselyandroid.internal.ParselyFlushManager import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.advanceTimeBy diff --git a/parsely/src/test/java/com/parsely/parselyandroid/FlushQueueTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/FlushQueueTest.kt index 0dea4b1a..cda6dce4 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/FlushQueueTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/FlushQueueTest.kt @@ -1,5 +1,10 @@ package com.parsely.parselyandroid +import com.parsely.parselyandroid.internal.ConnectivityStatusProvider +import com.parsely.parselyandroid.internal.FlushManager +import com.parsely.parselyandroid.internal.FlushQueue +import com.parsely.parselyandroid.internal.QueueRepository +import com.parsely.parselyandroid.internal.RestClient import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest diff --git a/parsely/src/test/java/com/parsely/parselyandroid/HeartbeatIntervalCalculatorTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/HeartbeatIntervalCalculatorTest.kt index eb5c420e..8d4bc584 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/HeartbeatIntervalCalculatorTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/HeartbeatIntervalCalculatorTest.kt @@ -1,7 +1,8 @@ package com.parsely.parselyandroid -import com.parsely.parselyandroid.HeartbeatIntervalCalculator.Companion.MAX_TIME_BETWEEN_HEARTBEATS -import java.util.Calendar +import com.parsely.parselyandroid.internal.HeartbeatIntervalCalculator.Companion.MAX_TIME_BETWEEN_HEARTBEATS +import com.parsely.parselyandroid.internal.Clock +import com.parsely.parselyandroid.internal.HeartbeatIntervalCalculator import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds import org.assertj.core.api.Assertions.assertThat diff --git a/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt index e4f354ff..7335a185 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/InMemoryBufferTest.kt @@ -1,5 +1,7 @@ package com.parsely.parselyandroid +import com.parsely.parselyandroid.internal.InMemoryBuffer +import com.parsely.parselyandroid.internal.QueueRepository import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.cancel diff --git a/parsely/src/test/java/com/parsely/parselyandroid/LocalStorageRepositoryTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/LocalStorageRepositoryTest.kt index 47a60057..e6fbc414 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/LocalStorageRepositoryTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/LocalStorageRepositoryTest.kt @@ -2,6 +2,7 @@ package com.parsely.parselyandroid import android.content.Context import androidx.test.core.app.ApplicationProvider +import com.parsely.parselyandroid.internal.LocalStorageRepository import java.io.File import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runCurrent diff --git a/parsely/src/test/java/com/parsely/parselyandroid/ParselyAPIConnectionTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/ParselyAPIConnectionTest.kt index 497e5d5c..94004c53 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/ParselyAPIConnectionTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/ParselyAPIConnectionTest.kt @@ -1,5 +1,6 @@ package com.parsely.parselyandroid +import com.parsely.parselyandroid.internal.ParselyAPIConnection import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest From 329735f94378c0e4a56828aebba17d1c9654bbb6 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 5 Apr 2024 13:57:17 +0200 Subject: [PATCH 02/10] feat: introduce `SiteIdSource` and allow SDK users to provide custom `siteId` per event --- .../main/java/com/example/MainActivity.java | 7 ++++--- .../parsely/parselyandroid/ParselyTracker.kt | 8 +++++++- .../com/parsely/parselyandroid/SiteIdSource.kt | 18 ++++++++++++++++++ .../parselyandroid/internal/EventsBuilder.kt | 11 ++++++++--- .../internal/ParselyTrackerInternal.kt | 15 ++++++++++----- .../parselyandroid/EventsBuilderTest.kt | 8 ++++++++ 6 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 parsely/src/main/java/com/parsely/parselyandroid/SiteIdSource.kt diff --git a/example/src/main/java/com/example/MainActivity.java b/example/src/main/java/com/example/MainActivity.java index c5164f9e..adebbb5f 100644 --- a/example/src/main/java/com/example/MainActivity.java +++ b/example/src/main/java/com/example/MainActivity.java @@ -8,6 +8,7 @@ import android.widget.TextView; import com.parsely.parselyandroid.ParselyTracker; +import com.parsely.parselyandroid.SiteIdSource; import com.parsely.parselyandroid.internal.ParselyTrackerInternal; import com.parsely.parselyandroid.ParselyVideoMetadata; @@ -96,14 +97,14 @@ public void trackPageview(View view) { // the post has an internet-accessible URL, we will crawl it. urlMetadata is only used // in the case of app-only content that we can't crawl. ParselyTracker.sharedInstance().trackPageview( - "http://example.com/article1.html", "http://example.com/", null, null + "http://example.com/article1.html", "http://example.com/", null, null, SiteIdSource.Default.INSTANCE ); } public void startEngagement(View view) { final Map extraData = new HashMap<>(); extraData.put("product-id", "12345"); - ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/", extraData); + ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/", extraData, SiteIdSource.Default.INSTANCE); updateEngagementStrings(); } @@ -124,7 +125,7 @@ public void trackPlay(View view) { 90 ); // NOTE: For videos embedded in an article, "url" should be the URL for that article. - ParselyTracker.sharedInstance().trackPlay("http://example.com/app-videos", "", metadata, null); + ParselyTracker.sharedInstance().trackPlay("http://example.com/app-videos", "", metadata, null, SiteIdSource.Default.INSTANCE); } diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt index 24ca772b..d9393e49 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt @@ -37,12 +37,14 @@ public interface ParselyTracker { * content). Do not use this for **content also hosted on** URLs Parse.ly * would normally crawl. * @param extraData A Map of additional information to send with the event. + * @param siteIdSource The source of the site ID to use for the event. */ public fun trackPageview( url: String, urlRef: String = "", urlMetadata: ParselyMetadata? = null, extraData: Map? = null, + siteIdSource: SiteIdSource = SiteIdSource.Default, ) /** @@ -60,11 +62,13 @@ public interface ParselyTracker { * @param url The URL of the tracked article (eg: “http://example.com/some-old/article.html“) * @param urlRef The url of the page that linked to the page being engaged with. Analogous to HTTP referer * @param extraData A map of additional information to send with the generated `heartbeat` events + * @param siteIdSource The source of the site ID to use for the event. */ public fun startEngagement( url: String, urlRef: String = "", - extraData: Map? = null + extraData: Map? = null, + siteIdSource: SiteIdSource = SiteIdSource.Default, ) /** @@ -97,12 +101,14 @@ public interface ParselyTracker { * @param urlRef The url of the page that linked to the page being engaged with. Analogous to HTTP referer * @param videoMetadata Metadata about the tracked video * @param extraData A Map of additional information to send with the event + * @param siteIdSource The source of the site ID to use for the event. */ public fun trackPlay( url: String, urlRef: String = "", videoMetadata: ParselyVideoMetadata, extraData: Map? = null, + siteIdSource: SiteIdSource = SiteIdSource.Default, ) /** diff --git a/parsely/src/main/java/com/parsely/parselyandroid/SiteIdSource.kt b/parsely/src/main/java/com/parsely/parselyandroid/SiteIdSource.kt new file mode 100644 index 00000000..b72f90e2 --- /dev/null +++ b/parsely/src/main/java/com/parsely/parselyandroid/SiteIdSource.kt @@ -0,0 +1,18 @@ +package com.parsely.parselyandroid + +/** + * Configuration for the site ID to be used for an event. + */ +public sealed class SiteIdSource { + /** + * Instruct SDK to use site ID provided during [ParselyTracker.init]. + */ + public data object Default : SiteIdSource() + + /** + * Instruct SDK to override the site ID for the event. + * + * @param siteId The Parsely public site ID (e.g. "example.com") to use for the event. + */ + public data class Custom(val siteId: String) : SiteIdSource() +} diff --git a/parsely/src/main/java/com/parsely/parselyandroid/internal/EventsBuilder.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/EventsBuilder.kt index 5356c975..977a6d40 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/internal/EventsBuilder.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/EventsBuilder.kt @@ -2,10 +2,11 @@ package com.parsely.parselyandroid.internal import com.parsely.parselyandroid.internal.Logging.log import com.parsely.parselyandroid.ParselyMetadata +import com.parsely.parselyandroid.SiteIdSource internal class EventsBuilder( private val deviceInfoRepository: DeviceInfoRepository, - private val siteId: String, + private val initializationSiteId: String, private val clock: Clock, ) { /** @@ -23,7 +24,8 @@ internal class EventsBuilder( action: String, metadata: ParselyMetadata?, extraData: Map?, - uuid: String + uuid: String, + siteIdSource: SiteIdSource, ): Map { log("buildEvent called for %s/%s", action, url) @@ -31,7 +33,10 @@ internal class EventsBuilder( val event: MutableMap = HashMap() event["url"] = url event["urlref"] = urlRef - event["idsite"] = siteId + event["idsite"] = when (siteIdSource) { + is SiteIdSource.Default -> initializationSiteId + is SiteIdSource.Custom -> siteIdSource.siteId + } event["action"] = action // Make a copy of extraData and add some things. diff --git a/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyTrackerInternal.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyTrackerInternal.kt index 6c0c817d..aca85eb4 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyTrackerInternal.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/ParselyTrackerInternal.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.ProcessLifecycleOwner import com.parsely.parselyandroid.ParselyMetadata import com.parsely.parselyandroid.ParselyTracker import com.parsely.parselyandroid.ParselyVideoMetadata +import com.parsely.parselyandroid.SiteIdSource import java.util.UUID internal class ParselyTrackerInternal internal constructor( @@ -92,6 +93,7 @@ internal class ParselyTrackerInternal internal constructor( urlRef: String, urlMetadata: ParselyMetadata?, extraData: Map?, + siteIdSource: SiteIdSource, ) { if (url.isBlank()) { Logging.log("url cannot be empty") @@ -108,7 +110,8 @@ internal class ParselyTrackerInternal internal constructor( "pageview", urlMetadata, extraData, - pageViewUuid + pageViewUuid, + siteIdSource ) ) } @@ -116,7 +119,8 @@ internal class ParselyTrackerInternal internal constructor( override fun startEngagement( url: String, urlRef: String, - extraData: Map? + extraData: Map?, + siteIdSource: SiteIdSource, ) { if (url.isBlank()) { Logging.log("url cannot be empty") @@ -133,7 +137,7 @@ internal class ParselyTrackerInternal internal constructor( // Start a new EngagementTask val event = - eventsBuilder.buildEvent(url, urlRef, "heartbeat", null, extraData, pageViewUuid) + eventsBuilder.buildEvent(url, urlRef, "heartbeat", null, extraData, pageViewUuid, siteIdSource) engagementManager = EngagementManager( this, DEFAULT_ENGAGEMENT_INTERVAL_MILLIS.toLong(), @@ -157,6 +161,7 @@ internal class ParselyTrackerInternal internal constructor( urlRef: String, videoMetadata: ParselyVideoMetadata, extraData: Map?, + siteIdSource: SiteIdSource, ) { if (url.isBlank()) { Logging.log("url cannot be empty") @@ -179,12 +184,12 @@ internal class ParselyTrackerInternal internal constructor( // Enqueue the videostart val videostartEvent = - eventsBuilder.buildEvent(url, urlRef, "videostart", videoMetadata, extraData, uuid) + eventsBuilder.buildEvent(url, urlRef, "videostart", videoMetadata, extraData, uuid, siteIdSource) enqueueEvent(videostartEvent) // Start a new engagement manager for the video. val hbEvent = - eventsBuilder.buildEvent(url, urlRef, "vheartbeat", videoMetadata, extraData, uuid) + eventsBuilder.buildEvent(url, urlRef, "vheartbeat", videoMetadata, extraData, uuid, siteIdSource) // TODO: Can we remove some metadata fields from this request? videoEngagementManager = EngagementManager( this, diff --git a/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt index 2c3963cd..358a235a 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt @@ -33,6 +33,7 @@ internal class EventsBuilderTest { null, null, TEST_UUID, + SiteIdSource.Default, ) // then @@ -52,6 +53,7 @@ internal class EventsBuilderTest { null, null, TEST_UUID, + SiteIdSource.Default, ) // then @@ -71,6 +73,7 @@ internal class EventsBuilderTest { null, null, TEST_UUID, + SiteIdSource.Default, ) // then @@ -90,6 +93,7 @@ internal class EventsBuilderTest { null, null, TEST_UUID, + SiteIdSource.Default, ) // then @@ -112,6 +116,7 @@ internal class EventsBuilderTest { null, extraData, TEST_UUID, + SiteIdSource.Default, ) // then @@ -135,6 +140,7 @@ internal class EventsBuilderTest { null, extraData, TEST_UUID, + SiteIdSource.Default, ) // then @@ -156,6 +162,7 @@ internal class EventsBuilderTest { metadata, null, TEST_UUID, + SiteIdSource.Default, ) // then @@ -177,6 +184,7 @@ internal class EventsBuilderTest { metadata, null, TEST_UUID, + SiteIdSource.Default, ) // then From 3c1e4d06078aefd7d29adb1d05728532db5ad9c2 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 5 Apr 2024 14:02:33 +0200 Subject: [PATCH 03/10] tests: provide unit tests for building events with custom `sideId` per event --- .../parselyandroid/EventsBuilderTest.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt b/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt index 358a235a..34172215 100644 --- a/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt +++ b/parsely/src/test/java/com/parsely/parselyandroid/EventsBuilderTest.kt @@ -191,6 +191,44 @@ internal class EventsBuilderTest { assertThat(event).containsKey("metadata") } + @Test + fun `given default site id is provided, when creating a pixel, then use the default site id`() { + // when + val event: Map = sut.buildEvent( + TEST_URL, + "", + "pageview", + null, + null, + TEST_UUID, + SiteIdSource.Default, + ) + + // then + assertThat(event).containsEntry("idsite", TEST_SITE_ID) + } + + + @Test + fun `given custom site id is provided, when creating a pixel, then use the custom site id`() { + // given + val customSiteId = "Custom Site ID" + + // when + val event: Map = sut.buildEvent( + TEST_URL, + "", + "pageview", + null, + null, + TEST_UUID, + SiteIdSource.Custom(customSiteId), + ) + + // then + assertThat(event).containsEntry("idsite", customSiteId) + } + private fun MapAssert.sharedPixelAssertions() = hasSize(6) .containsEntry("url", TEST_URL) From e4d96e7f28d9ca3a9e87cd8b0ee1c8ad3888bbd0 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 5 Apr 2024 14:29:00 +0200 Subject: [PATCH 04/10] tests: add functional test for "custom site id in engagement session" --- .../parsely/parselyandroid/FunctionalTests.kt | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt b/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt index 79ca72ba..15e11a83 100644 --- a/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt +++ b/parsely/src/androidTest/java/com/parsely/parselyandroid/FunctionalTests.kt @@ -21,6 +21,7 @@ import kotlin.io.path.Path import kotlin.time.Duration import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.parse import kotlin.time.Duration.Companion.seconds import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeoutOrNull @@ -283,6 +284,46 @@ class FunctionalTests { } } + /** + * In this scenario, the consumer app starts an engagement session and configures siteId + * with a custom value for the session. + * + * Intervals: + * With current implementation of `HeartbeatIntervalCalculator`, the next intervals are: + * - 10500ms for the first interval + * - 13650ms for the second interval + * + * So after ~27,2s we should observe 2 `heartbeat` events from `startEngagement`. + * + * They both should have the same custom site id. + */ + @Test + fun customSiteIdIsAppliedToConcurrentEventsInEngagementSession() { + ActivityScenario.launch(SampleActivity::class.java).use { scenario -> + // given + val customSiteId = "customSiteId" + val flushInterval = 30.seconds + scenario.onActivity { activity: Activity -> + beforeEach(activity) + server.enqueue(MockResponse().setResponseCode(200)) + initializeTracker(activity, flushInterval) + + // when + parselyTracker.trackPageview("engagementUrl") + parselyTracker.startEngagement("engagementUrl", siteIdSource = SiteIdSource.Custom(customSiteId)) + } + + // then + val request = server.takeRequest().toMap()["events"]!! + + assertThat(request.filter { it.action=="heartbeat" }).hasSize(2) + .allSatisfy { + assertThat(it.idsite).isEqualTo(customSiteId) + } + } + + } + private fun RecordedRequest.toMap(): Map> { val listType: TypeReference>> = object : TypeReference>>() {} From 7f2782e42327e777ea64277fd508f8ef2135cfe9 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 5 Apr 2024 14:46:01 +0200 Subject: [PATCH 05/10] feat: log json payload in dry run --- .../java/com/parsely/parselyandroid/internal/FlushQueue.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushQueue.kt b/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushQueue.kt index a9ea2c0c..724c349b 100644 --- a/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushQueue.kt +++ b/parsely/src/main/java/com/parsely/parselyandroid/internal/FlushQueue.kt @@ -31,13 +31,13 @@ internal class FlushQueue( return@launch } + val jsonPayload = toParselyEventsPayload(eventsToSend) if (skipSendingEvents) { - log("Debug mode on. Not sending to Parse.ly. Otherwise, would sent ${eventsToSend.size} events") + log("Debug mode on. Not sending to Parse.ly. Otherwise, would sent ${eventsToSend.size} events: $jsonPayload") repository.remove(eventsToSend) return@launch } log("Sending request with %d events", eventsToSend.size) - val jsonPayload = toParselyEventsPayload(eventsToSend) log("POST Data %s", jsonPayload) log("Requested %s", ParselyTrackerInternal.ROOT_URL) restClient.send(jsonPayload) From 227337050b19e55f4e6eeae4a645d4965c7f017b Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Fri, 5 Apr 2024 14:46:19 +0200 Subject: [PATCH 06/10] feat: add edit text for testing custom site id in `example/MainActivity` --- .../main/java/com/example/MainActivity.java | 19 +++++++++++++++---- example/src/main/res/layout/activity_main.xml | 14 +++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/example/src/main/java/com/example/MainActivity.java b/example/src/main/java/com/example/MainActivity.java index adebbb5f..0bd5f6da 100644 --- a/example/src/main/java/com/example/MainActivity.java +++ b/example/src/main/java/com/example/MainActivity.java @@ -4,7 +4,9 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.text.Editable; import android.view.View; +import android.widget.EditText; import android.widget.TextView; import com.parsely.parselyandroid.ParselyTracker; @@ -24,6 +26,7 @@ */ public class MainActivity extends Activity { + public static final String DEFAULT_SITE_ID = "example.com"; private InternalDebugOnlyData internalDebugOnlyData; @Override @@ -32,7 +35,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); // initialize the Parsely tracker with your site id and the current Context - ParselyTracker.init("example.com", 30, this, true); + ParselyTracker.init(DEFAULT_SITE_ID, 30, this, true); internalDebugOnlyData = new InternalDebugOnlyData((ParselyTrackerInternal) ParselyTracker.sharedInstance()); final TextView intervalView = (TextView) findViewById(R.id.interval); @@ -97,14 +100,14 @@ public void trackPageview(View view) { // the post has an internet-accessible URL, we will crawl it. urlMetadata is only used // in the case of app-only content that we can't crawl. ParselyTracker.sharedInstance().trackPageview( - "http://example.com/article1.html", "http://example.com/", null, null, SiteIdSource.Default.INSTANCE + "http://example.com/article1.html", "http://example.com/", null, null, getSiteId() ); } public void startEngagement(View view) { final Map extraData = new HashMap<>(); extraData.put("product-id", "12345"); - ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/", extraData, SiteIdSource.Default.INSTANCE); + ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/", extraData, getSiteId()); updateEngagementStrings(); } @@ -125,7 +128,7 @@ public void trackPlay(View view) { 90 ); // NOTE: For videos embedded in an article, "url" should be the URL for that article. - ParselyTracker.sharedInstance().trackPlay("http://example.com/app-videos", "", metadata, null, SiteIdSource.Default.INSTANCE); + ParselyTracker.sharedInstance().trackPlay("http://example.com/app-videos", "", metadata, null, getSiteId()); } @@ -136,4 +139,12 @@ public void trackPause(View view) { public void trackReset(View view) { ParselyTracker.sharedInstance().resetVideo(); } + + private SiteIdSource getSiteId() { + Editable fromEditText = ((EditText) findViewById(R.id.custom_site_id)).getText(); + if (fromEditText == null || fromEditText.toString().isEmpty()) { + return SiteIdSource.Default.INSTANCE; + } + return new SiteIdSource.Custom(fromEditText.toString()); + } } diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index e86a9223..bae2bae9 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -7,19 +7,27 @@ android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > - + - + + +