Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix Device Update/Delete events migration payload #481

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ internal class TrackingMigrationProcessor(
private val analytics: Analytics,
private val migrationSiteId: String
) : MigrationProcessor, Subscriber {

companion object {
private const val PAYLOAD_JSON_KEY_DEVICE = "device"
private const val PAYLOAD_JSON_KEY_TOKEN = "token"
private const val PAYLOAD_JSON_KEY_TYPE = "type"
private const val PAYLOAD_JSON_VALUE_ANDROID = "android"
}

private val logger: Logger = SDKComponent.logger
private val globalPreferenceStore = SDKComponent.android().globalPreferenceStore
private var subscriptionID: SubscriptionID? = null
Expand Down Expand Up @@ -101,12 +109,26 @@ internal class TrackingMigrationProcessor(
val deleteDeviceEvent = TrackEvent(
event = EventNames.DEVICE_DELETE,
properties = buildJsonObject {
put("token", oldDeviceToken)
put(
PAYLOAD_JSON_KEY_DEVICE,
buildJsonObject {
put(PAYLOAD_JSON_KEY_TOKEN, oldDeviceToken)
put(PAYLOAD_JSON_KEY_TYPE, PAYLOAD_JSON_VALUE_ANDROID)
}
)
}
)
analytics.process(deleteDeviceEvent) { event ->
event?.putInContextUnderKey("device", "token", oldDeviceToken)
event?.putInContextUnderKey("device", "type", "android")
event?.putInContextUnderKey(
PAYLOAD_JSON_KEY_DEVICE,
PAYLOAD_JSON_KEY_TOKEN,
oldDeviceToken
)
event?.putInContextUnderKey(
PAYLOAD_JSON_KEY_DEVICE,
PAYLOAD_JSON_KEY_TYPE,
PAYLOAD_JSON_VALUE_ANDROID
)
}
}
}
Expand Down Expand Up @@ -168,25 +190,53 @@ internal class TrackingMigrationProcessor(
event = EventNames.DEVICE_UPDATE,
properties = buildJsonObject {
putAll(task.attributes.toJsonObject())
put("token", task.token)
put(
PAYLOAD_JSON_KEY_DEVICE,
buildJsonObject {
put(PAYLOAD_JSON_KEY_TOKEN, task.token)
put(PAYLOAD_JSON_KEY_TYPE, PAYLOAD_JSON_VALUE_ANDROID)
}
)
}
),
enrichmentClosure = { event ->
event?.putInContextUnderKey("device", "token", task.token)
event?.putInContextUnderKey("device", "type", "android")
event?.putInContextUnderKey(
PAYLOAD_JSON_KEY_DEVICE,
PAYLOAD_JSON_KEY_TOKEN,
task.token
)
event?.putInContextUnderKey(
PAYLOAD_JSON_KEY_DEVICE,
PAYLOAD_JSON_KEY_TYPE,
PAYLOAD_JSON_VALUE_ANDROID
)
}
)

is MigrationTask.DeletePushToken -> MigrationEventData(
trackEvent = TrackEvent(
event = EventNames.DEVICE_DELETE,
properties = buildJsonObject {
put("token", task.token)
put(
PAYLOAD_JSON_KEY_DEVICE,
buildJsonObject {
put(PAYLOAD_JSON_KEY_TOKEN, task.token)
put(PAYLOAD_JSON_KEY_TYPE, PAYLOAD_JSON_VALUE_ANDROID)
}
)
}
),
enrichmentClosure = { event ->
event?.putInContextUnderKey("device", "token", task.token)
event?.putInContextUnderKey("device", "type", "android")
event?.putInContextUnderKey(
PAYLOAD_JSON_KEY_DEVICE,
PAYLOAD_JSON_KEY_TOKEN,
task.token
)
event?.putInContextUnderKey(
PAYLOAD_JSON_KEY_DEVICE,
PAYLOAD_JSON_KEY_TYPE,
PAYLOAD_JSON_VALUE_ANDROID
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ class TrackingMigrationProcessorTest : IntegrationTest() {
val deviceDeleteEvent = outputReaderPlugin.trackEvents.shouldHaveSingleItem()
deviceDeleteEvent.event shouldBeEqualTo EventNames.DEVICE_DELETE
deviceDeleteEvent.context.deviceToken shouldBeEqualTo oldDeviceToken
deviceDeleteEvent.properties shouldMatchTo mapOf("token" to oldDeviceToken)
val expectedPropertiesMap = mapOf(
"device" to mapOf(
"token" to oldDeviceToken,
"type" to "android"
)
)
deviceDeleteEvent.properties shouldMatchTo expectedPropertiesMap
}

@Test
Expand Down Expand Up @@ -391,7 +397,13 @@ class TrackingMigrationProcessorTest : IntegrationTest() {
deviceUpdateEvent.event shouldBeEqualTo EventNames.DEVICE_UPDATE
deviceUpdateEvent.context.deviceToken shouldBeEqualTo givenTask.token
deviceUpdateEvent.properties shouldBeEqualTo buildJsonObject {
put("token", givenTask.token)
put(
"device",
buildJsonObject {
put("token", givenTask.token)
put("type", "android")
}
)
}
}

Expand Down Expand Up @@ -419,7 +431,13 @@ class TrackingMigrationProcessorTest : IntegrationTest() {
deviceUpdateEvent.context.deviceToken shouldBeEqualTo givenTask.token
deviceUpdateEvent.properties shouldBeEqualTo buildJsonObject {
putAll(givenAttributes.toJsonObject())
put("token", givenTask.token)
put(
"device",
buildJsonObject {
put("token", givenTask.token)
put("type", "android")
}
)
}
}

Expand All @@ -439,7 +457,13 @@ class TrackingMigrationProcessorTest : IntegrationTest() {
deviceDeleteEvent.event shouldBeEqualTo EventNames.DEVICE_DELETE
deviceDeleteEvent.context.deviceToken shouldBeEqualTo givenTask.token
deviceDeleteEvent.properties shouldBeEqualTo buildJsonObject {
put("token", givenTask.token)
put(
"device",
buildJsonObject {
put("token", givenTask.token)
put("type", "android")
}
)
}
}

Expand Down
Loading