Skip to content

Commit

Permalink
LIVE-4186 - LLM analytics for reborn update
Browse files Browse the repository at this point in the history
  • Loading branch information
LFBarreto committed Oct 13, 2022
1 parent 7593158 commit aa6abee
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-singers-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

LLM - analytics update for reborn
54 changes: 37 additions & 17 deletions apps/ledger-live-mobile/src/analytics/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ import {
lastSeenDeviceSelector,
sensitiveAnalyticsSelector,
firstConnectionHasDeviceSelector,
readOnlyModeEnabledSelector,
hasOrderedNanoSelector,
} from "../reducers/settings";
import { knownDevicesSelector } from "../reducers/ble";
import { satisfactionSelector } from "../reducers/ratings";
import type { State } from "../reducers";
import { NavigatorName } from "../const";
import { previousRouteNameRef, currentRouteNameRef } from "./screenRefs";

const sessionId = uuid();
const appVersion = `${VersionNumber.appVersion || ""} (${
VersionNumber.buildVersion || ""
})`;
let sessionId = uuid();
const appVersion = `${VersionNumber.appVersion || ""} (${VersionNumber.buildVersion || ""
})`;
const { ANALYTICS_LOGS, ANALYTICS_TOKEN } = Config;

export const updateSessionId = () => (sessionId = uuid());

const extraProperties = store => {
const state: State = store.getState();
const sensitiveAnalytics = sensitiveAnalyticsSelector(state);
Expand All @@ -56,14 +59,14 @@ const extraProperties = store => {
lastSeenDeviceSelector(state) || devices[devices.length - 1];
const deviceInfo = lastDevice
? {
deviceVersion: lastDevice.deviceInfo?.version,
deviceLanguage:
lastDevice.deviceInfo?.languageId !== undefined
? idsToLanguage[lastDevice.deviceInfo.languageId]
: undefined,
appLength: lastDevice?.appsInstalled,
modelId: lastDevice.modelId,
}
deviceVersion: lastDevice.deviceInfo?.version,
deviceLanguage:
lastDevice.deviceInfo?.languageId !== undefined
? idsToLanguage[lastDevice.deviceInfo.languageId]
: undefined,
appLength: lastDevice?.appsInstalled,
modelId: lastDevice.modelId,
}
: {};
const firstConnectionHasDevice = firstConnectionHasDeviceSelector(state);

Expand All @@ -83,8 +86,8 @@ const extraProperties = store => {
// $FlowFixMe
...(satisfaction
? {
satisfaction,
}
satisfaction,
}
: {}),
...deviceInfo,
};
Expand Down Expand Up @@ -112,6 +115,8 @@ export const start = async (store: any) => {
const { user, created } = await getOrCreateUser();
storeInstance = store;

if (ANALYTICS_LOGS) console.log("analytics:identify", user.id);

if (created) {
if (ANALYTICS_LOGS) console.log("analytics:identify", user.id);

Expand Down Expand Up @@ -165,9 +170,15 @@ export const track = (
level: "debug",
});

const state = storeInstance && storeInstance.getState();

const readOnlyMode = state && readOnlyModeEnabledSelector(state);
const hasOrderedNano = state && hasOrderedNanoSelector(state);

if (
!storeInstance ||
(!mandatory && !analyticsEnabledSelector(storeInstance.getState()))
!state ||
(!mandatory && !analyticsEnabledSelector(state)) ||
(readOnlyMode && hasOrderedNano) // do not track anything in the reborn state post purchase pre device setup
) {
return;
}
Expand Down Expand Up @@ -244,7 +255,16 @@ export const screen = (
level: "info",
});

if (!storeInstance || !analyticsEnabledSelector(storeInstance.getState())) {
const state = storeInstance && storeInstance.getState();

const readOnlyMode = state && readOnlyModeEnabledSelector(state);
const hasOrderedNano = state && hasOrderedNanoSelector(state);

if (
!state ||
!analyticsEnabledSelector(state) ||
(readOnlyMode && hasOrderedNano) // do not track anything in the reborn state post purchase pre device setup
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState } from "react";
import { Flex } from "@ledgerhq/native-ui";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { Device } from "@ledgerhq/live-common/hw/actions/types";
import connectManager from "@ledgerhq/live-common/hw/connectManager";
import { createAction } from "@ledgerhq/live-common/hw/actions/manager";
Expand All @@ -16,6 +16,7 @@ import {
setReadOnlyMode,
} from "../../../../../actions/settings";
import { updateUser } from "../../../../../user";
import { readOnlyModeEnabledSelector } from "../../../../../reducers/settings";

const action = createAction(connectManager);

Expand All @@ -27,28 +28,35 @@ const ConnectNanoScene = ({
deviceModelId: string;
}) => {
const dispatch = useDispatch();
const readOnlyMode = useSelector(readOnlyModeEnabledSelector);
const [device, setDevice] = useState<Device | undefined>();

const onSetDevice = useCallback(
async device => {
if (readOnlyMode) {
await updateUser();
await updateIdentify();
}
dispatch(setLastConnectedDevice(device));
setDevice(device);
dispatch(setReadOnlyMode(false));
dispatch(setHasOrderedNano(false));
},
[dispatch],
[dispatch, readOnlyMode],
);

const directNext = useCallback(
async device => {
await updateUser();
await updateIdentify();
if (readOnlyMode) {
await updateUser();
await updateIdentify();
}
dispatch(setLastConnectedDevice(device));
dispatch(setReadOnlyMode(false));
dispatch(setHasOrderedNano(false));
onNext();
},
[dispatch, onNext],
[dispatch, onNext, readOnlyMode],
);

const onResult = useCallback(
Expand Down

0 comments on commit aa6abee

Please sign in to comment.