Skip to content

Commit

Permalink
Log interaction across pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sethonyango committed Sep 17, 2024
1 parent a1015b0 commit a235ed7
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import io.falu.identity.capture.upload.UploadCaptureFragment
import io.falu.identity.confirmation.ConfirmationFragment
import io.falu.identity.documents.DocumentCaptureMethodsFragment
import io.falu.identity.documents.DocumentSelectionFragment
import io.falu.identity.error.ErrorFragment
import io.falu.identity.error.ScanCaptureErrorFragment
import io.falu.identity.error.SelfieCaptureErrorFragment
import io.falu.identity.selfie.SelfieFragment
import io.falu.identity.support.SupportFragment
import io.falu.identity.verification.IdentificationVerificationFragment
Expand All @@ -33,6 +36,9 @@ internal class IdentityVerificationFragmentFactory(
ConfirmationFragment::class.java.name -> ConfirmationFragment(factory, callback)
SupportFragment::class.java.name -> SupportFragment(factory)
SelfieFragment::class.java.name -> SelfieFragment(factory)
ErrorFragment::class.java.name -> ErrorFragment(factory)
SelfieCaptureErrorFragment::class.java.name -> SelfieCaptureErrorFragment(factory)
ScanCaptureErrorFragment::class.java.name -> ScanCaptureErrorFragment(factory)
IdentificationVerificationFragment::class.java.name -> IdentificationVerificationFragment(factory)
TaxPinVerificationFragment::class.java.name -> TaxPinVerificationFragment(factory)
else -> super.instantiate(classLoader, className)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ internal class IdentityAnalyticsRequestBuilder(
)
)

fun screenPresented(scanType: ScanDisposition.DocumentScanType? = null, screenName: String) = createRequest(
EVENT_SCREEN_PRESENTED,
makeEventParameters(
KEY_DOCUMENT_SCAN_TYPE to scanType?.name,
KEY_SCREEN_NAME to screenName
)
)

companion object {
const val CLIENT = "identity-sdk-mobile"
const val ORIGIN = "falu-identity-android"
Expand All @@ -137,6 +145,7 @@ internal class IdentityAnalyticsRequestBuilder(
const val EVENT_CAMERA_PERMISSION_DENIED = "camera_permission_denied"
const val EVENT_CAMERA_PERMISSION_GRANTED = "camera_permission_granted"
const val EVENT_IDENTITY_DOCUMENT_TIMEOUT = "document_timeout"
const val EVENT_SCREEN_PRESENTED = "screen_presented"
const val EVENT_SELFIE_TIMEOUT = "selfie_timeout"
const val EVENT_MODEL_PERFORMANCE = "model_performance"
const val EVENT_CAMERA_INFO = "camera_info"
Expand All @@ -162,5 +171,16 @@ internal class IdentityAnalyticsRequestBuilder(
const val KEY_FRAMES = "frames"
const val KEY_CAMERA_ROTATION = "camera_rotation"
const val KEY_VIEW_RESULT = "view_result"
const val KEY_SCREEN_NAME = "screen_name"

const val SCREEN_NAME_ERROR = "error"
const val SCREEN_NAME_WELCOME = "welcome"
const val SCREEN_NAME_DOCUMENT_SELECTION = "document_selection"
const val SCREEN_NAME_DOCUMENT_CAPTURE_METHODS = "document_capture_methods"
const val SCREEN_NAME_MANUAL_CAPTURE = "manual_capture"
const val SCREEN_NAME_AUTO_CAPTURE = "auto_capture"
const val SCREEN_NAME_UPLOAD_CAPTURE = "upload_capture"
const val SCREEN_NAME_SUPPORT = "support"
const val SCREEN_NAME_SELFIE = "selfie"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import io.falu.identity.R
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_MANUAL_CAPTURE
import io.falu.identity.api.DocumentUploadDisposition
import io.falu.identity.api.models.DocumentSide
import io.falu.identity.api.models.IdentityDocumentType
Expand Down Expand Up @@ -55,6 +56,10 @@ internal class ManualCaptureFragment(identityViewModelFactory: ViewModelProvider

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
identityViewModel.reportTelemetry(
identityViewModel.analyticsRequestBuilder.screenPresented(screenName = SCREEN_NAME_MANUAL_CAPTURE)
)

binding.cardDocumentBack.visibility =
if (isPassport) View.GONE else View.VISIBLE
binding.buttonContinue.isEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import io.falu.identity.IdentityVerificationViewModel
import io.falu.identity.R
import io.falu.identity.ai.DocumentDetectionOutput
import io.falu.identity.analytics.AnalyticsDisposition
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_AUTO_CAPTURE
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_MANUAL_CAPTURE
import io.falu.identity.api.models.IdentityDocumentType
import io.falu.identity.api.models.verification.Verification
import io.falu.identity.api.models.verification.VerificationCapture
Expand Down Expand Up @@ -54,6 +56,11 @@ internal class ScanCaptureFragment(identityViewModelFactory: ViewModelProvider.F

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

identityViewModel.reportTelemetry(
identityViewModel.analyticsRequestBuilder.screenPresented(screenName = SCREEN_NAME_AUTO_CAPTURE)
)

identityDocumentType =
requireArguments().serializable(DocumentSelectionFragment.KEY_IDENTITY_DOCUMENT_TYPE)!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import io.falu.identity.R
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_UPLOAD_CAPTURE
import io.falu.identity.api.DocumentUploadDisposition
import io.falu.identity.api.models.DocumentSide
import io.falu.identity.api.models.IdentityDocumentType
Expand All @@ -30,6 +31,11 @@ internal class UploadCaptureFragment(identityViewModelFactory: ViewModelProvider

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

identityViewModel.reportTelemetry(
identityViewModel.analyticsRequestBuilder.screenPresented(screenName = SCREEN_NAME_UPLOAD_CAPTURE)
)

binding.cardDocumentBack.visibility =
if (isPassport) View.GONE else View.VISIBLE
binding.buttonContinue.isEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.navigation.fragment.findNavController
import io.falu.identity.IdentityVerificationViewModel
import io.falu.identity.R
import io.falu.identity.analytics.AnalyticsDisposition
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_DOCUMENT_CAPTURE_METHODS
import io.falu.identity.api.models.IdentityDocumentType
import io.falu.identity.api.models.UploadMethod
import io.falu.identity.api.models.verification.Verification
Expand All @@ -39,6 +40,11 @@ internal class DocumentCaptureMethodsFragment(private val factory: ViewModelProv

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.reportTelemetry(
viewModel.analyticsRequestBuilder.screenPresented(screenName = SCREEN_NAME_DOCUMENT_CAPTURE_METHODS)
)

identityDocumentType =
(requireArguments().getSerializable(DocumentSelectionFragment.KEY_IDENTITY_DOCUMENT_TYPE)
as IdentityDocumentType?)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import io.falu.identity.IdentityVerificationViewModel
import io.falu.identity.R
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_DOCUMENT_SELECTION
import io.falu.identity.api.models.IdentityDocumentType
import io.falu.identity.api.models.country.SupportedCountry
import io.falu.identity.api.models.verification.Verification
import io.falu.identity.api.models.verification.VerificationUpdateOptions
import io.falu.identity.api.models.verification.VerificationType
import io.falu.identity.api.models.verification.VerificationUpdateOptions
import io.falu.identity.countries.CountriesAdapter
import io.falu.identity.databinding.FragmentDocumentSelectionBinding
import io.falu.identity.utils.navigateToApiResponseProblemFragment
Expand Down Expand Up @@ -43,6 +44,10 @@ class DocumentSelectionFragment(private val factory: ViewModelProvider.Factory)

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.reportTelemetry(viewModel.analyticsRequestBuilder
.screenPresented(screenName = SCREEN_NAME_DOCUMENT_SELECTION))

viewModel.observerForSupportedCountriesResults(
viewLifecycleOwner,
onSuccess = { onSupportedCountriesListed(it.toList()) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import io.falu.identity.IdentityVerificationResultCallback
import io.falu.identity.IdentityVerificationViewModel
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_ERROR
import io.falu.identity.databinding.FragmentErrorBinding

internal abstract class AbstractErrorFragment : Fragment() {
internal abstract class AbstractErrorFragment(identityViewModelFactory: ViewModelProvider.Factory) : Fragment() {
private var _binding: FragmentErrorBinding? = null
protected val binding get() = _binding!!

private val identityViewModel: IdentityVerificationViewModel by activityViewModels { identityViewModelFactory }

protected lateinit var callback: IdentityVerificationResultCallback

override fun onAttach(context: Context) {
Expand All @@ -33,6 +39,13 @@ internal abstract class AbstractErrorFragment : Fragment() {
return binding.root
}

override fun onViewStateRestored(savedInstanceState: Bundle?) {
super.onViewStateRestored(savedInstanceState)
identityViewModel.reportTelemetry(
identityViewModel.analyticsRequestBuilder.screenPresented(screenName = SCREEN_NAME_ERROR)
)
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.View
import androidx.annotation.IdRes
import androidx.core.os.bundleOf
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import io.falu.identity.IdentityVerificationResult
Expand All @@ -14,7 +15,8 @@ import io.falu.identity.api.models.requirements.RequirementError.Companion.canNa
import io.falu.identity.utils.getErrorDescription
import software.tingle.api.HttpApiResponseProblem

internal class ErrorFragment : AbstractErrorFragment() {
internal class ErrorFragment(identityViewModelFactory: ViewModelProvider.Factory) :
AbstractErrorFragment(identityViewModelFactory) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package io.falu.identity.error

import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import io.falu.identity.R

internal class ScanCaptureErrorFragment : AbstractErrorFragment() {
internal class ScanCaptureErrorFragment(identityViewModelFactory: ViewModelProvider.Factory) :
AbstractErrorFragment(identityViewModelFactory) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package io.falu.identity.error

import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import io.falu.identity.IdentityVerificationResult
import io.falu.identity.R

internal class SelfieCaptureErrorFragment : AbstractErrorFragment() {
internal class SelfieCaptureErrorFragment(identityViewModelFactory: ViewModelProvider.Factory) :
AbstractErrorFragment(identityViewModelFactory) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.falu.identity.IdentityVerificationViewModel
import io.falu.identity.R
import io.falu.identity.ai.FaceDetectionOutput
import io.falu.identity.analytics.AnalyticsDisposition
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_SELFIE
import io.falu.identity.api.models.UploadMethod
import io.falu.identity.api.models.verification.Verification
import io.falu.identity.api.models.verification.VerificationSelfieUpload
Expand Down Expand Up @@ -56,6 +57,14 @@ internal class SelfieFragment(identityViewModelFactory: ViewModelProvider.Factor

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

identityViewModel.reportTelemetry(
identityViewModel.analyticsRequestBuilder.screenPresented(
scanType = ScanDisposition.DocumentScanType.SELFIE,
screenName = SCREEN_NAME_SELFIE
)
)

verificationRequest =
requireNotNull(VerificationUploadRequest.getFromBundle(requireArguments())) {
"Verification upload request is null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import io.falu.core.exceptions.ApiException
import io.falu.identity.IdentityVerificationViewModel
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_SUPPORT
import io.falu.identity.api.models.Support
import io.falu.identity.databinding.FragmentSupportBinding
import io.falu.identity.utils.navigateToApiResponseProblemFragment
Expand All @@ -35,6 +36,10 @@ internal class SupportFragment(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.reportTelemetry(
viewModel.analyticsRequestBuilder.screenPresented(screenName = SCREEN_NAME_SUPPORT)
)

viewModel.observeForVerificationResults(
viewLifecycleOwner,
onSuccess = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import io.falu.identity.IdentityVerificationResultCallback
import io.falu.identity.IdentityVerificationViewModel
import io.falu.identity.R
import io.falu.identity.analytics.AnalyticsDisposition
import io.falu.identity.analytics.IdentityAnalyticsRequestBuilder.Companion.SCREEN_NAME_WELCOME
import io.falu.identity.api.models.verification.Verification
import io.falu.identity.api.models.verification.VerificationUpdateOptions
import io.falu.identity.databinding.FragmentWelcomeBinding
Expand Down Expand Up @@ -44,6 +45,8 @@ internal class WelcomeFragment(

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.reportTelemetry(viewModel.analyticsRequestBuilder.screenPresented(screenName = SCREEN_NAME_WELCOME))

viewModel.observeForVerificationResults(
viewLifecycleOwner,
onSuccess = { onVerificationSuccessful(it) },
Expand Down

0 comments on commit a235ed7

Please sign in to comment.