diff --git a/datapipeline/api/datapipeline.api b/datapipeline/api/datapipeline.api index cb3dbd970..036746a32 100644 --- a/datapipeline/api/datapipeline.api +++ b/datapipeline/api/datapipeline.api @@ -5,27 +5,25 @@ public final class io/customer/datapipeline/BuildConfig { public fun ()V } -public final class io/customer/datapipeline/DataPipelineModuleConfig : io/customer/sdk/module/CustomerIOModuleConfig { - public synthetic fun (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun getApiKey ()Ljava/lang/String; +public final class io/customer/datapipeline/DataPipelineModuleConfig { + public synthetic fun (Ljava/lang/String;Landroid/app/Application;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getApplication ()Landroid/app/Application; + public final fun getConfiguration ()Lkotlin/jvm/functions/Function1; + public final fun getWriteKey ()Ljava/lang/String; } -public final class io/customer/datapipeline/DataPipelineModuleConfig$Builder : io/customer/sdk/module/CustomerIOModuleConfig$Builder { - public fun (Ljava/lang/String;)V - public fun build ()Lio/customer/datapipeline/DataPipelineModuleConfig; - public synthetic fun build ()Lio/customer/sdk/module/CustomerIOModuleConfig; - public final fun getApiKey ()Ljava/lang/String; +public final class io/customer/datapipeline/DataPipelineModuleConfig$Builder { + public fun (Ljava/lang/String;Landroid/app/Application;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Ljava/lang/String;Landroid/app/Application;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun build ()Lio/customer/datapipeline/DataPipelineModuleConfig; + public final fun getApplication ()Landroid/app/Application; + public final fun getConfiguration ()Lkotlin/jvm/functions/Function1; } -public final class io/customer/datapipeline/ModuleDataPipeline : io/customer/sdk/module/CustomerIOModule { - public static final field Companion Lio/customer/datapipeline/ModuleDataPipeline$Companion; - public static final field moduleName Ljava/lang/String; +public final class io/customer/datapipeline/ModuleDataPipeline { public fun (Lio/customer/datapipeline/DataPipelineModuleConfig;)V - public fun (Lio/customer/datapipeline/DataPipelineModuleConfig;Lio/customer/sdk/di/CustomerIOComponent;)V public final fun alias (Ljava/lang/String;)V - public fun getModuleConfig ()Lio/customer/datapipeline/DataPipelineModuleConfig; - public synthetic fun getModuleConfig ()Lio/customer/sdk/module/CustomerIOModuleConfig; - public fun getModuleName ()Ljava/lang/String; + public final fun getConfig ()Lio/customer/datapipeline/DataPipelineModuleConfig; public final fun group (Ljava/lang/String;)V public final fun group (Ljava/lang/String;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;)V public final fun group (Ljava/lang/String;Lkotlinx/serialization/json/JsonObject;)V @@ -38,7 +36,8 @@ public final class io/customer/datapipeline/ModuleDataPipeline : io/customer/sdk public final fun identify (Lkotlinx/serialization/json/JsonObject;)V public static synthetic fun identify$default (Lio/customer/datapipeline/ModuleDataPipeline;Ljava/lang/String;Lkotlinx/serialization/json/JsonObject;ILjava/lang/Object;)V public static synthetic fun identify$default (Lio/customer/datapipeline/ModuleDataPipeline;Lkotlinx/serialization/json/JsonObject;ILjava/lang/Object;)V - public fun initialize ()V + public final fun initialize ()V + public final fun reset ()Lkotlin/Unit; public final fun screen (Ljava/lang/String;)V public final fun screen (Ljava/lang/String;Ljava/lang/Object;Lkotlinx/serialization/SerializationStrategy;Ljava/lang/String;)V public final fun screen (Ljava/lang/String;Lkotlinx/serialization/json/JsonObject;)V @@ -51,10 +50,3 @@ public final class io/customer/datapipeline/ModuleDataPipeline : io/customer/sdk public static synthetic fun track$default (Lio/customer/datapipeline/ModuleDataPipeline;Ljava/lang/String;Lkotlinx/serialization/json/JsonObject;ILjava/lang/Object;)V } -public final class io/customer/datapipeline/ModuleDataPipeline$Companion { -} - -public final class io/customer/datapipeline/di/DIGraphDataPipelineKt { - public static final fun dataPipeline (Lio/customer/sdk/CustomerIO;)Lio/customer/datapipeline/ModuleDataPipeline; -} - diff --git a/datapipeline/src/main/java/io/customer/datapipeline/ModuleDataPipeline.kt b/datapipeline/src/main/java/io/customer/datapipeline/ModuleDataPipeline.kt index 16bacfb59..db03edf59 100644 --- a/datapipeline/src/main/java/io/customer/datapipeline/ModuleDataPipeline.kt +++ b/datapipeline/src/main/java/io/customer/datapipeline/ModuleDataPipeline.kt @@ -27,7 +27,6 @@ class ModuleDataPipeline( } } - // Analytic event specific APIs /** @@ -55,7 +54,9 @@ class ModuleDataPipeline( * @see Track Documentation */ fun track( - name: String, properties: T, serializationStrategy: SerializationStrategy + name: String, + properties: T, + serializationStrategy: SerializationStrategy ) { analytics?.track(name, properties, serializationStrategy) } @@ -70,7 +71,8 @@ class ModuleDataPipeline( * @see Track Documentation */ inline fun track( - name: String, properties: T + name: String, + properties: T ) { track(name, properties, JsonAnySerializer.serializersModule.serializer()) } @@ -114,7 +116,9 @@ class ModuleDataPipeline( * @see Identify Documentation */ fun identify( - userId: String, traits: T, serializationStrategy: SerializationStrategy + userId: String, + traits: T, + serializationStrategy: SerializationStrategy ) { analytics?.identify(userId, traits, serializationStrategy) } @@ -176,7 +180,8 @@ class ModuleDataPipeline( * @see Identify Documentation */ fun identify( - traits: T, serializationStrategy: SerializationStrategy + traits: T, + serializationStrategy: SerializationStrategy ) { identify(Json.encodeToJsonElement(serializationStrategy, traits).jsonObject) } @@ -198,7 +203,8 @@ class ModuleDataPipeline( * @see Identify Documentation */ inline fun identify( - userId: String, traits: T + userId: String, + traits: T ) { identify(userId, traits, JsonAnySerializer.serializersModule.serializer()) } @@ -215,7 +221,9 @@ class ModuleDataPipeline( */ @JvmOverloads fun screen( - title: String, properties: JsonObject = emptyJsonObject, category: String = "" + title: String, + properties: JsonObject = emptyJsonObject, + category: String = "" ) { analytics?.screen(title, properties, category) } @@ -238,7 +246,9 @@ class ModuleDataPipeline( category: String = "" ) { screen( - title, Json.encodeToJsonElement(serializationStrategy, properties).jsonObject, category + title, + Json.encodeToJsonElement(serializationStrategy, properties).jsonObject, + category ) } @@ -253,7 +263,9 @@ class ModuleDataPipeline( * @see Screen Documentation */ inline fun screen( - title: String, properties: T, category: String = "" + title: String, + properties: T, + category: String = "" ) { screen(title, properties, JsonAnySerializer.serializersModule.serializer(), category) } @@ -287,7 +299,9 @@ class ModuleDataPipeline( * @see Group Documentation */ fun group( - groupId: String, traits: T, serializationStrategy: SerializationStrategy + groupId: String, + traits: T, + serializationStrategy: SerializationStrategy ) { group(groupId, Json.encodeToJsonElement(serializationStrategy, traits).jsonObject) } @@ -304,7 +318,8 @@ class ModuleDataPipeline( * @see Group Documentation */ inline fun group( - groupId: String, traits: T + groupId: String, + traits: T ) { group(groupId, traits, JsonAnySerializer.serializersModule.serializer()) } @@ -323,5 +338,4 @@ class ModuleDataPipeline( } fun reset() = analytics?.reset() - } diff --git a/datapipeline/src/main/java/io/customer/datapipeline/di/DIGraphDataPipeline.kt b/datapipeline/src/main/java/io/customer/datapipeline/di/DIGraphDataPipeline.kt index 43d58fb01..30db8a98f 100644 --- a/datapipeline/src/main/java/io/customer/datapipeline/di/DIGraphDataPipeline.kt +++ b/datapipeline/src/main/java/io/customer/datapipeline/di/DIGraphDataPipeline.kt @@ -1,9 +1 @@ package io.customer.datapipeline.di - -import io.customer.datapipeline.ModuleDataPipeline -import io.customer.sdk.CustomerIO - -fun CustomerIO.dataPipeline(): ModuleDataPipeline { - return diGraph.sdkConfig.modules[ModuleDataPipeline.moduleName] as? ModuleDataPipeline - ?: throw IllegalStateException("ModuleDataPipeline not initialized") -} diff --git a/sdk/api/sdk.api b/sdk/api/sdk.api index 21ae46179..5f98628b1 100644 --- a/sdk/api/sdk.api +++ b/sdk/api/sdk.api @@ -2,6 +2,7 @@ public final class io/customer/sdk/CustomerIO : io/customer/sdk/CustomerIOInstan public static final field Companion Lio/customer/sdk/CustomerIO$Companion; public fun clearIdentify ()V public fun deleteDeviceToken ()V + public final fun getDataPipeline ()Lio/customer/datapipeline/ModuleDataPipeline; public fun getDeviceAttributes ()Ljava/util/Map; public final fun getDiGraph ()Lio/customer/sdk/di/CustomerIOComponent; public fun getProfileAttributes ()Ljava/util/Map; @@ -24,7 +25,9 @@ public final class io/customer/sdk/CustomerIO : io/customer/sdk/CustomerIOInstan } public final class io/customer/sdk/CustomerIO$Builder { - public fun (Ljava/lang/String;Ljava/lang/String;Landroid/app/Application;)V + public fun (Ljava/lang/String;Landroid/app/Application;)V + public fun (Ljava/lang/String;Landroid/app/Application;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Ljava/lang/String;Landroid/app/Application;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun (Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;Landroid/app/Application;)V public synthetic fun (Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;Landroid/app/Application;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun (Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;Landroid/app/Application;Ljava/util/Map;)V @@ -39,7 +42,6 @@ public final class io/customer/sdk/CustomerIO$Builder { public final fun setClient (Lio/customer/sdk/data/store/Client;)Lio/customer/sdk/CustomerIO$Builder; public final fun setLogLevel (Lio/customer/sdk/util/CioLogLevel;)Lio/customer/sdk/CustomerIO$Builder; public final fun setOverrideDiGraph (Lio/customer/sdk/di/CustomerIOComponent;)V - public final fun setRegion (Lio/customer/sdk/data/model/Region;)Lio/customer/sdk/CustomerIO$Builder; public final fun setRequestTimeout (J)Lio/customer/sdk/CustomerIO$Builder; public final fun setTrackingApiURL (Ljava/lang/String;)Lio/customer/sdk/CustomerIO$Builder; } @@ -61,22 +63,23 @@ public final class io/customer/sdk/CustomerIOActivityLifecycleCallbacks : androi public final class io/customer/sdk/CustomerIOConfig { public static final field Companion Lio/customer/sdk/CustomerIOConfig$Companion; - public fun (Lio/customer/sdk/data/store/Client;Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;JZZIDDLio/customer/sdk/util/CioLogLevel;Ljava/lang/String;Ljava/util/Map;)V + public fun (Lio/customer/sdk/data/store/Client;ZZIDDLio/customer/sdk/util/CioLogLevel;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;J)V + public synthetic fun (Lio/customer/sdk/data/store/Client;ZZIDDLio/customer/sdk/util/CioLogLevel;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;JILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Lio/customer/sdk/data/store/Client; - public final fun component10 ()D - public final fun component11 ()Lio/customer/sdk/util/CioLogLevel; - public final fun component12 ()Ljava/lang/String; - public final fun component13 ()Ljava/util/Map; - public final fun component2 ()Ljava/lang/String; - public final fun component3 ()Ljava/lang/String; - public final fun component4 ()Lio/customer/sdk/data/model/Region; - public final fun component5 ()J - public final fun component6 ()Z - public final fun component7 ()Z - public final fun component8 ()I - public final fun component9 ()D - public final fun copy (Lio/customer/sdk/data/store/Client;Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;JZZIDDLio/customer/sdk/util/CioLogLevel;Ljava/lang/String;Ljava/util/Map;)Lio/customer/sdk/CustomerIOConfig; - public static synthetic fun copy$default (Lio/customer/sdk/CustomerIOConfig;Lio/customer/sdk/data/store/Client;Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;JZZIDDLio/customer/sdk/util/CioLogLevel;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lio/customer/sdk/CustomerIOConfig; + public final fun component10 ()Ljava/lang/String; + public final fun component11 ()Ljava/lang/String; + public final fun component12 ()Lio/customer/sdk/data/model/Region; + public final fun component13 ()J + public final fun component2 ()Z + public final fun component3 ()Z + public final fun component4 ()I + public final fun component5 ()D + public final fun component6 ()D + public final fun component7 ()Lio/customer/sdk/util/CioLogLevel; + public final fun component8 ()Ljava/util/Map; + public final fun component9 ()Ljava/lang/String; + public final fun copy (Lio/customer/sdk/data/store/Client;ZZIDDLio/customer/sdk/util/CioLogLevel;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;J)Lio/customer/sdk/CustomerIOConfig; + public static synthetic fun copy$default (Lio/customer/sdk/CustomerIOConfig;Lio/customer/sdk/data/store/Client;ZZIDDLio/customer/sdk/util/CioLogLevel;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lio/customer/sdk/data/model/Region;JILjava/lang/Object;)Lio/customer/sdk/CustomerIOConfig; public fun equals (Ljava/lang/Object;)Z public final fun getApiKey ()Ljava/lang/String; public final fun getAutoTrackDeviceAttributes ()Z diff --git a/sdk/src/main/java/io/customer/sdk/CustomerIO.kt b/sdk/src/main/java/io/customer/sdk/CustomerIO.kt index 3c4e5a776..b5f3769a0 100644 --- a/sdk/src/main/java/io/customer/sdk/CustomerIO.kt +++ b/sdk/src/main/java/io/customer/sdk/CustomerIO.kt @@ -45,25 +45,29 @@ interface CustomerIOInstance { fun identify(identifier: String) fun identify( - identifier: String, attributes: Map + identifier: String, + attributes: Map ) fun track(name: String) fun track( - name: String, attributes: Map + name: String, + attributes: Map ) fun screen(name: String) fun screen( - name: String, attributes: Map + name: String, + attributes: Map ) fun screen(activity: Activity) fun screen( - activity: Activity, attributes: Map + activity: Activity, + attributes: Map ) fun clearIdentify() @@ -73,7 +77,9 @@ interface CustomerIOInstance { fun deleteDeviceToken() fun trackMetric( - deliveryID: String, event: MetricEvent, deviceToken: String + deliveryID: String, + event: MetricEvent, + deviceToken: String ) } @@ -126,7 +132,8 @@ class CustomerIO internal constructor( @JvmStatic @Synchronized fun instanceOrNull( - context: Context, modules: List> = emptyList() + context: Context, + modules: List> = emptyList() ): CustomerIO? = try { instance() } catch (ex: Exception) { @@ -200,7 +207,10 @@ class CustomerIO internal constructor( CustomerIOConfig.Companion.AnalyticsConstants.BACKGROUND_QUEUE_SECONDS_DELAY constructor( - siteId: String, apiKey: String, region: Region = Region.US, appContext: Application + siteId: String, + apiKey: String, + region: Region = Region.US, + appContext: Application ) : this("$siteId:$apiKey", appContext) // added a `config` in the secondary constructor so users stick to our advised primary constructor @@ -242,8 +252,10 @@ class CustomerIO internal constructor( setClient(Client.fromRawValue(source = source, sdkVersion = version)) } - when (val minNumberOfTasks = - config[CustomerIOConfig.Companion.Keys.BACKGROUND_QUEUE_MIN_NUMBER_OF_TASKS]) { + when ( + val minNumberOfTasks = + config[CustomerIOConfig.Companion.Keys.BACKGROUND_QUEUE_MIN_NUMBER_OF_TASKS] + ) { is Int -> { setBackgroundQueueMinNumberOfTasks(backgroundQueueMinNumberOfTasks = minNumberOfTasks) } @@ -319,14 +331,16 @@ class CustomerIO internal constructor( fun build(): CustomerIO { require(writeKey.isNotBlank()) { "write key needed" } - val config = CustomerIOConfig(client = client, + val config = CustomerIOConfig( + client = client, autoTrackScreenViews = shouldAutoRecordScreenViews, autoTrackDeviceAttributes = autoTrackDeviceAttributes, backgroundQueueMinNumberOfTasks = backgroundQueueMinNumberOfTasks, backgroundQueueSecondsDelay = backgroundQueueSecondsDelay, backgroundQueueTaskExpiredSeconds = Seconds.fromDays(3).value, logLevel = logLevel, - modules = modules.entries.associate { entry -> entry.key to entry.value }) + modules = modules.entries.associate { entry -> entry.key to entry.value } + ) val dataPipeline = ModuleDataPipeline( config = DataPipelineModuleConfig.Builder( @@ -412,7 +426,8 @@ class CustomerIO internal constructor( * @return Action which can be accessed via `execute` or `enqueue` */ override fun identify( - identifier: String, attributes: CustomAttributes + identifier: String, + attributes: CustomAttributes ) = dataPipeline.identify(identifier, attributes) /** @@ -430,7 +445,8 @@ class CustomerIO internal constructor( * @return Action which can be accessed via `execute` or `enqueue` */ override fun track( - name: String, attributes: CustomAttributes + name: String, + attributes: CustomAttributes ) = dataPipeline.track(name, attributes) /** @@ -447,7 +463,8 @@ class CustomerIO internal constructor( * @return Action which can be accessed via `execute` or `enqueue` */ override fun screen( - name: String, attributes: CustomAttributes + name: String, + attributes: CustomAttributes ) = dataPipeline.screen(name, attributes) /** @@ -464,7 +481,8 @@ class CustomerIO internal constructor( * @return Action which can be accessed via `execute` or `enqueue` */ override fun screen( - activity: Activity, attributes: CustomAttributes + activity: Activity, + attributes: CustomAttributes ) = recordScreenViews(activity, attributes) /** @@ -494,9 +512,13 @@ class CustomerIO internal constructor( * Track a push metric */ override fun trackMetric( - deliveryID: String, event: MetricEvent, deviceToken: String + deliveryID: String, + event: MetricEvent, + deviceToken: String ) = trackRepository.trackMetric( - deliveryID = deliveryID, event = event, deviceToken = deviceToken + deliveryID = deliveryID, + event = event, + deviceToken = deviceToken ) /** @@ -527,7 +549,8 @@ class CustomerIO internal constructor( val packageManager = activity.packageManager return try { val info = packageManager.getActivityInfo( - activity.componentName, PackageManager.GET_META_DATA + activity.componentName, + PackageManager.GET_META_DATA ) val activityLabel = info.loadLabel(packageManager) diff --git a/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt b/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt index 62250a1cd..cf4f743b7 100644 --- a/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt +++ b/sdk/src/main/java/io/customer/sdk/CustomerIOConfig.kt @@ -27,9 +27,24 @@ data class CustomerIOConfig( */ val backgroundQueueTaskExpiredSeconds: Double, val logLevel: CioLogLevel, - val modules: Map> + val modules: Map>, + var trackingApiUrl: String? = null, + + val siteId: String = "", + val apiKey: String = "", + val region: Region = Region.US, + val timeout: Long = 0 ) { + internal val trackingApiHostname: String + get() { + return this.trackingApiUrl ?: this.region.let { selectedRegion -> + when (selectedRegion) { + Region.US -> "https://track-sdk.customer.io/" + Region.EU -> "https://track-sdk-eu.customer.io/" + } + } + } companion object { /**