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

Add support for custom startInteraction start input events #66

Merged
merged 1 commit into from
Aug 4, 2024

Conversation

pyricau
Copy link
Member

@pyricau pyricau commented Jul 26, 2024

No description provided.

import kotlin.time.Duration

class InteractionStartInput(
val inputData: Any,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want papa responsible for inputData accounting? In the integration on register we'd probably carry any data through InteractionEvent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So yes, the general idea is that we have the custom timestamp passed in as a property of the sent event, and then in the interaction rule client, we read that and pass it in to startInteraction. In that specific case, we don't need inputData at all (so now that I think of it is should probs be inputData: Any? = null).

The inputData field is here for the receiving end, where we get the InteractionResult and pull out the input details

E.g. look for interactionInput usages here (Square internal link): https://github.com/squareup/android-register/blob/master/common/ui-latency/impl/src/main/java/com/squareup/uilatency/InteractionLatencyAnalytics.kt

ui_latency_trigger_frames = result.interactionInput?.framesSinceDelivery?.toLong()?: -1,

=> this needs access to the DeliveredInput which in this PR we shove inside InteractionStartInput.inputData

  private val InteractionResultData<InteractionEvent>.interactionType: String
    get() = interactionInput?.let {
      when (val inputEvent = it.event) {
        is MotionEvent -> "tap"
        is KeyEvent -> {
          "key ${inputEvent.name}"
        }

        else -> error("Unexpected input event type $inputEvent")
      }
    } ?: "unknown"

=> here we're mostly looking for a string description of the event.

  private val InteractionResultData<InteractionEvent>.triggerDuration: Duration?
    get() {
      val firstEvent = sentEvents.first()
      val triggerUptime = interactionInput?.eventUptime
      return triggerUptime?.let { firstEvent.uptime - it }
    }

=> This one only uses eventUptime which is carried over as inputUptime, so that one doesn't need inputData.

I'm thinking maybe I should turn InteractionStartInput into an interface implemented by DeliveredInput, that can be implemented by our custom things, and then I can remove inputData from it and just have inputUptime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@pyricau pyricau force-pushed the py/custom_timestamp branch 2 times, most recently from 82ef5e6 to cec58e1 Compare July 27, 2024 08:55
@pyricau pyricau force-pushed the py/custom_timestamp branch 2 times, most recently from 27d4496 to da92070 Compare July 27, 2024 09:40
@pyricau pyricau merged commit 2df69b6 into main Aug 4, 2024
4 of 14 checks passed
@pyricau pyricau deleted the py/custom_timestamp branch August 4, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants