Skip to content
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
1 change: 1 addition & 0 deletions app/controllers/frontend_log_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class FrontendLogController < ApplicationController
idv_sdk_error_before_init
idv_sdk_selfie_image_capture_closed_without_photo
idv_sdk_selfie_image_capture_failed
idv_sdk_selfie_image_capture_initialized
idv_sdk_selfie_image_capture_opened
idv_selfie_image_added
idv_selfie_image_clicked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,13 @@ function AcuantCapture(
selfieAttempts.current += 1;
}

function onImageCaptureInitialized() {
trackEvent('idv_sdk_selfie_image_capture_initialized', {
captureAttempts,
selfie_attempts: selfieAttempts.current,
});
}

return (
<div className={[className, 'document-capture-acuant-capture'].filter(Boolean).join(' ')}>
{isCapturingEnvironment && !selfieCapture && (
Expand All @@ -731,6 +738,7 @@ function AcuantCapture(
onImageCaptureOpen={onSelfieCaptureOpen}
onImageCaptureClose={onSelfieCaptureClosed}
onImageCaptureFeedback={onImageCaptureFeedback}
onImageCaptureInitialized={onImageCaptureInitialized}
onSelfieTaken={onSelfieTaken}
>
<FullScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ interface AcuantSelfieCameraContextProps {
* React children node
*/
children: ReactNode;
/**
* Face detection is initialized and ready.
*/
onImageCaptureInitialized: () => void;
}

interface FaceCaptureCallback {
Expand All @@ -78,6 +82,7 @@ interface FaceDetectionStates {
}

function AcuantSelfieCamera({
onImageCaptureInitialized = () => {},
onImageCaptureSuccess = () => {},
onImageCaptureFailure = () => {},
onImageCaptureOpen = () => {},
Expand All @@ -94,6 +99,7 @@ function AcuantSelfieCamera({
// This callback is triggered when the face detector is ready.
// Until then, no actions are executed and the user sees only the camera stream.
// You can opt to display an alert before the callback is triggered.
onImageCaptureInitialized();
},
onDetection: (text) => {
onImageCaptureFeedback(text);
Expand Down
21 changes: 21 additions & 0 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,27 @@ def idv_sdk_selfie_image_capture_failed(
**extra,
)
end

# Camera is ready to detect face for capturing selfie
# @param [String] acuant_version
# @param [Integer] captureAttempts number of attempts to capture / upload an image
# (previously called "attempt")
# @param [Integer] selfie_attempts number of times SDK captured selfie, user may decide to retake
def idv_sdk_selfie_image_capture_initialized(
acuant_version:,
captureAttempts: nil,
selfie_attempts: nil,
**extra
)
track_event(
:idv_sdk_selfie_image_capture_initialized,
acuant_version: acuant_version,
captureAttempts: captureAttempts,
selfie_attempts: selfie_attempts,
**extra,
)
end

# rubocop:enable Naming/VariableName,Naming/MethodParameterName

# User opened the SDK to take a selfie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,29 @@ describe('document-capture/components/acuant-capture', () => {
}),
);
});

it('calls trackEvent from onImageCaptureInitialized', () => {
// In real use the `start` method opens the Acuant SDK full screen selfie capture window.
// Because we can't do that in test (AcuantSDK does not allow), this doesn't attempt to load
// the SDK. Instead, it simply calls the callback that happens when a photo is captured.
// This allows us to test everything about that callback -except- the Acuant SDK parts.
initialize({
selfieStart: sinon.stub().callsFake((callbacks) => {
callbacks.onDetectorInitialized();
}),
});

expect(trackEvent).to.be.calledWith('idv_selfie_image_clicked');
expect(trackEvent).to.be.calledWith('IdV: Acuant SDK loaded');

expect(trackEvent).to.have.been.calledWith(
'idv_sdk_selfie_image_capture_initialized',
sinon.match({
captureAttempts: sinon.match.number,
selfie_attempts: sinon.match.number,
}),
);
});
});

it('optionally disallows upload', () => {
Expand Down