Skip to content

Commit

Permalink
feat(onboarding): hook metrics to the new onboarding
Browse files Browse the repository at this point in the history
Fixes #17047
  • Loading branch information
jrainville committed Jan 24, 2025
1 parent 990f9ca commit b14dcf3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
23 changes: 12 additions & 11 deletions src/app/modules/onboarding/module.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import NimQml, chronicles, json
import logging

import io_interface
import view, controller
Expand Down Expand Up @@ -26,7 +27,8 @@ type SecondaryFlow* {.pure} = enum
CreateProfileWithKeycardExistingSeedphrase,
LoginWithSeedphrase,
LoginWithSyncing,
LoginWithKeycard
LoginWithKeycard,
ActualLogin, # TODO get the real name and value for this when it's implemented on the front-end

type
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
Expand All @@ -35,6 +37,7 @@ type
viewVariant: QVariant
controller: Controller
localPairingStatus: LocalPairingStatus
currentFlow: SecondaryFlow

proc newModule*[T](
delegate: T,
Expand Down Expand Up @@ -99,15 +102,15 @@ method inputConnectionStringForBootstrapping*[T](self: Module[T], connectionStri

method finishOnboardingFlow*[T](self: Module[T], flowInt: int, dataJson: string): string =
try:
let flow = SecondaryFlow(flowInt)
self.currentFlow = SecondaryFlow(flowInt)

let data = parseJson(dataJson)
let password = data["password"].str
let seedPhrase = data["seedphrase"].str

var err = ""

case flow:
case self.currentFlow:
# CREATE PROFILE FLOWS
of SecondaryFlow.CreateProfileWithPassword:
err = self.controller.createAccountAndLogin(password)
Expand Down Expand Up @@ -147,7 +150,7 @@ method finishOnboardingFlow*[T](self: Module[T], flowInt: int, dataJson: string)
# TODO implement keycard function
discard
else:
raise newException(ValueError, "Unknown flow: " & $flow)
raise newException(ValueError, "Unknown flow: " & $self.currentFlow)

return err
except Exception as e:
Expand All @@ -158,13 +161,11 @@ proc finishAppLoading2[T](self: Module[T]) =
self.delegate.appReady()

# TODO get the flow to send the right metric
# let currStateObj = self.view.currentStartupStateObj()
# if not currStateObj.isNil:
# var eventType = "user-logged-in"
# if currStateObj.flowType() != FlowType.AppLogin:
# eventType = "onboarding-completed"
# singletonInstance.globalEvents.addCentralizedMetricIfEnabled(eventType,
# $(%*{"flowType": currStateObj.flowType()}))
var eventType = "user-logged-in"
if self.currentFlow != SecondaryFlow.ActualLogin:
eventType = "onboarding-completed"
singletonInstance.globalEvents.addCentralizedMetricIfEnabled(eventType,
$(%*{"flowType": repr(self.currentFlow)}))

self.delegate.finishAppLoading()

Expand Down
2 changes: 1 addition & 1 deletion storybook/pages/OnboardingLayoutPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ SplitView {
let content = `Stack (${stack.depth}):`

for (let i = 0; i < stack.depth; i++)
content += " " + InspectionUtils.baseName(
content += " " + Utils.baseName(
stack.get(i, StackView.ForceLoad))

return content
Expand Down
21 changes: 4 additions & 17 deletions storybook/src/Storybook/InspectionUtils.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import QtQml 2.15
import QtQuick 2.15
import QtQuick.Controls 2.15

import utils 1.0

QtObject {
function isVisual(item) {
return item instanceof Text
Expand All @@ -14,21 +16,6 @@ QtObject {
|| item instanceof SpriteSequence
}

function baseName(item) {
const fullName = item.toString()
const underscoreIndex = fullName.indexOf("_")

if (underscoreIndex !== -1)
return fullName.substring(0, underscoreIndex)

const bracketIndex = fullName.indexOf("(")

if (bracketIndex !== -1)
return fullName.substring(0, bracketIndex)

return fullName
}

function baseTypeName(item) {
if (item instanceof Text)
return "Text"
Expand Down Expand Up @@ -57,7 +44,7 @@ QtObject {
}

function simpleName(item) {
const name = trimQQuickPrefix(baseName(item))
const name = trimQQuickPrefix(Utils.baseName(item))
const base = baseTypeName(item)

if (base)
Expand All @@ -77,7 +64,7 @@ QtObject {
while (stack.length) {
const item = stack.pop()

const name = baseName(item)
const name = Utils.baseName(item)
if (!onlyItems && name === "QQuickLoader") {
if(item.item)
stack.push(item.item)
Expand Down
1 change: 1 addition & 0 deletions ui/app/AppLayouts/Onboarding2/OnboardingLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Page {
property alias keycardPinInfoPageDelay: onboardingFlow.keycardPinInfoPageDelay

readonly property alias stack: stack
readonly property string currentPageName: stack.currentItem ? Utils.baseName(stack.currentItem) : ""

signal shareUsageDataRequested(bool enabled)

Expand Down
15 changes: 15 additions & 0 deletions ui/imports/utils/Utils.qml
Original file line number Diff line number Diff line change
Expand Up @@ -967,4 +967,19 @@ QtObject {

return ""
}

function baseName(item) {
const fullName = item.toString()
const underscoreIndex = fullName.indexOf("_")

if (underscoreIndex !== -1)
return fullName.substring(0, underscoreIndex)

const bracketIndex = fullName.indexOf("(")

if (bracketIndex !== -1)
return fullName.substring(0, bracketIndex)

return fullName
}
}
8 changes: 8 additions & 0 deletions ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ StatusWindow {
stack.clear()
stack.push(splashScreenV2, { runningProgressAnimation: true })
}

onShareUsageDataRequested: {
applicationWindow.metricsStore.toggleCentralizedMetrics(enabled)
if (enabled) {
Global.addCentralizedMetricIfEnabled("usage_data_shared", {placement: Constants.metricsEnablePlacement.onboarding})
}
}
onCurrentPageNameChanged: Global.addCentralizedMetricIfEnabled("navigation", {viewId: currentPageName})
}
}

Expand Down

0 comments on commit b14dcf3

Please sign in to comment.