Skip to content

Commit

Permalink
feat: added extended attribution info (mparticle-integrations#122)
Browse files Browse the repository at this point in the history
* feat: added extended attribution info

* updated the native sdk version
  • Loading branch information
tapasyat committed Mar 20, 2024
1 parent 84f1319 commit 5adc152
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -42,7 +42,7 @@ repositories {
}

dependencies {
api 'com.singular.sdk:singular_sdk:12.0.10'
api 'com.singular.sdk:singular_sdk:12.5.4'

androidTestImplementation 'androidx.test:runner:1.5.2'
testImplementation 'org.powermock:powermock-core:2.0.9'
Expand Down
34 changes: 34 additions & 0 deletions src/main/kotlin/com/mparticle/kits/SingularKit.kt
Expand Up @@ -21,8 +21,10 @@ import com.mparticle.kits.KitIntegration.CommerceListener
import com.mparticle.kits.KitIntegration.EventListener
import com.mparticle.kits.KitIntegration.PushListener
import com.mparticle.kits.KitIntegration.UserAttributeListener
import com.singular.sdk.SDIDAccessorHandler
import com.singular.sdk.Singular
import com.singular.sdk.SingularConfig
import com.singular.sdk.SingularDeviceAttributionHandler
import com.singular.sdk.internal.SingularLog
import org.json.JSONException
import org.json.JSONObject
Expand All @@ -31,6 +33,10 @@ import java.math.BigDecimal
open class SingularKit : KitIntegration(), ActivityListener, EventListener,
PushListener, CommerceListener, ApplicationStateListener, UserAttributeListener,
AttributeListener {

interface DeviceAttributionCallback : SingularDeviceAttributionHandler
interface SdidAccessorHandler : SDIDAccessorHandler

private val logger = SingularLog.getLogger(Singular::class.java.simpleName)
private var isInitialized = false
private var deviceToken: String? = null
Expand Down Expand Up @@ -83,6 +89,14 @@ open class SingularKit : KitIntegration(), ActivityListener, EventListener,
val linkParams = JSONObject()
linkParams.put(PASSTHROUGH, singularLinkParams.passthrough)
linkParams.put(IS_DEFERRED, singularLinkParams.isDeferred)
if (singularLinkParams.urlParameters != null) {
linkParams.put(QUERY_PARAMS,
(singularLinkParams.urlParameters as Map<*, *>?)?.let {
JSONObject(
it
)
})
}
attributionResult.parameters = linkParams
} catch (e: JSONException) {
e.printStackTrace()
Expand All @@ -96,6 +110,11 @@ open class SingularKit : KitIntegration(), ActivityListener, EventListener,
config.withLoggingEnabled()
config.withLogLevel(Log.DEBUG)
}

config.deviceAttributionHandler = deviceAttributionCallback;

config.withCustomSdid(customSdid, sdidAccessorHandler);

Singular.setWrapperNameAndVersion(MPARTICLE_WRAPPER_NAME, MPARTICLE_WRAPPER_VERSION)
config
} catch (ex: Exception) {
Expand Down Expand Up @@ -422,12 +441,27 @@ open class SingularKit : KitIntegration(), ActivityListener, EventListener,
// Singular Link Consts
private const val PASSTHROUGH = "passthrough"
private const val IS_DEFERRED = "is_deferred"
private const val QUERY_PARAMS = "query_params"

// Wrapper Consts
private const val MPARTICLE_WRAPPER_NAME = "mParticle"
private const val MPARTICLE_WRAPPER_VERSION = "1.0.1"
private const val CANT_BUILD_SINGULAR_CONFIG_MESSAGE =
"Can't build Singular Config in the mParticle Kit"
private var singularSettings: Map<String, String>? = null

private var deviceAttributionCallback: DeviceAttributionCallback? = null;
private var customSdid: String? = null;
private var sdidAccessorHandler: SdidAccessorHandler? = null;

@JvmStatic fun setDeviceAttributionCallback(deviceAttributionCallback: DeviceAttributionCallback?) {
this.deviceAttributionCallback = deviceAttributionCallback;
}

@JvmStatic fun setCustomSDID(customSDID: String?, sdidAccessorHandler: SdidAccessorHandler?) {
this.customSdid = customSDID
this.sdidAccessorHandler = sdidAccessorHandler
}

}
}

0 comments on commit 5adc152

Please sign in to comment.