Skip to content

Commit

Permalink
Adding some more analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Dec 18, 2024
1 parent 36251a9 commit 45799ee
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { UIBeanStorage } from '../../../services/uiBeanStorage';
import { UILog } from '../../../services/uiLog';
import { BEAN_CODE_ACTION } from '../../../enums/beans/beanCodeAction';
import { NfcService } from '../../../services/nfcService/nfc-service.service';
import BEAN_TRACKING from '../../../data/tracking/beanTracking';
import { UIAnalytics } from '../../../services/uiAnalytics';

@Component({
selector: 'app-bean-internal-share-code-generator.',
Expand All @@ -35,7 +37,8 @@ export class BeanInternalShareCodeGeneratorComponent implements OnInit {
private readonly uiAlert: UIAlert,
private readonly uiBeanStorage: UIBeanStorage,
private readonly uiLog: UILog,
private readonly nfcService: NfcService
private readonly nfcService: NfcService,
private readonly uiAnalytics: UIAnalytics,
) {}

ngOnInit() {}
Expand All @@ -54,11 +57,11 @@ export class BeanInternalShareCodeGeneratorComponent implements OnInit {
while (true) {
newShareCode = this.uiHelper.generateShortUUID().toUpperCase();
const indexFound = allBeanEntries.findIndex(
(b) => b.internal_share_code === newShareCode
(b) => b.internal_share_code === newShareCode,
);
if (indexFound === -1) {
this.uiLog.log(
'Generate QR Code - ' + newShareCode + ' - code not used yet.'
'Generate QR Code - ' + newShareCode + ' - code not used yet.',
);
/** This id isn't used yet**/
break;
Expand Down Expand Up @@ -92,6 +95,10 @@ export class BeanInternalShareCodeGeneratorComponent implements OnInit {
this.shareService.shareImage(this.imageSrc);
}
public writeNFC() {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.NFC_WRITE,
);
this.nfcService.writeNFCData(this.qrData);
}

Expand All @@ -103,7 +110,7 @@ export class BeanInternalShareCodeGeneratorComponent implements OnInit {
this.modalController.dismiss(
undefined,
undefined,
BeanInternalShareCodeGeneratorComponent.COMPONENT_ID
BeanInternalShareCodeGeneratorComponent.COMPONENT_ID,
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/app/beans/beans.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ export class BeansPage implements OnDestroy {
public async scanNFC() {
if (this.platform.is('capacitor')) {
try {
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.NFC_SCAN,
);
await this.nfcService.readNFCTag();
} catch (error) {
// Just log and do nothing else, it's likely the user just cancelled
Expand Down
39 changes: 25 additions & 14 deletions src/app/brew/brew-add/brew-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
private readonly visualizerService: VisualizerService,
private readonly changeDetectorRef: ChangeDetectorRef,
private readonly hapticService: HapticService,
private readonly uiHelper: UIHelper
private readonly uiHelper: UIHelper,
) {
// Initialize to standard in drop down
this.settings = this.uiSettingsStorage.getSettings();
Expand Down Expand Up @@ -178,7 +178,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
},
() => {
// No
}
},
);
} else {
this.dismiss();
Expand Down Expand Up @@ -238,7 +238,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
this.data.coordinates.speed = resp.coords.speed;
this.data.coordinates.longitude = resp.coords.longitude;
this.uiLog.info(
'BREW - Coordinates found - ' + JSON.stringify(this.data.coordinates)
'BREW - Coordinates found - ' + JSON.stringify(this.data.coordinates),
);
} catch (error) {
this.uiLog.error('BREW - No Coordinates found: ', error);
Expand Down Expand Up @@ -272,7 +272,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
try {
if (this.brewBrewing.brewBrewingGraphEl) {
Plotly.purge(
this.brewBrewing.brewBrewingGraphEl.profileDiv.nativeElement
this.brewBrewing.brewBrewingGraphEl.profileDiv.nativeElement,
);
}
} catch (ex) {}
Expand All @@ -281,7 +281,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
dismissed: true,
},
undefined,
BrewAddComponent.COMPONENT_ID
BrewAddComponent.COMPONENT_ID,
);
}

Expand Down Expand Up @@ -327,14 +327,25 @@ export class BrewAddComponent implements OnInit, OnDestroy {

if (this.uiBrewHelper.checkIfBeanPackageIsConsumed(this.data.getBean())) {
await this.uiBrewHelper.checkIfBeanPackageIsConsumedTriggerMessageAndArchive(
this.data.getBean()
this.data.getBean(),
);
}

this.uiAnalytics.trackEvent(
BREW_TRACKING.TITLE,
BREW_TRACKING.ACTIONS.ADD_FINISH
BREW_TRACKING.ACTIONS.ADD_FINISH,
);
this.uiAnalytics.trackEvent(
BREW_TRACKING.TITLE,
BREW_TRACKING.ACTIONS.ADD_FINISH_PREPARATION_TYPE,
addedBrewObj.getPreparation().type,
);
this.uiAnalytics.trackEvent(
BREW_TRACKING.TITLE,
BREW_TRACKING.ACTIONS.ADD_FINISH_PREPARATION_STYLE,
addedBrewObj.getPreparation().style_type,
);

if (
this.brewBrewing?.brewBrewingPreparationDeviceEl?.getDataPreparationDeviceType() ===
PreparationDeviceType.XENIA
Expand All @@ -349,11 +360,11 @@ export class BrewAddComponent implements OnInit, OnDestroy {
await this.uiBrewStorage.update(addedBrewObj);
} catch (ex) {
this.uiLog.log(
'We could not get the logs from xenia: ' + JSON.stringify(ex)
'We could not get the logs from xenia: ' + JSON.stringify(ex),
);
this.uiToast.showInfoToast(
'We could not get the logs from xenia: ' + JSON.stringify(ex),
false
false,
);
}
}
Expand All @@ -375,7 +386,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
) {
this.uiHealthKit.trackCaffeineConsumption(
this.data.getCaffeineAmount(),
moment(this.brewBrewing.customCreationDate).toDate()
moment(this.brewBrewing.customCreationDate).toDate(),
);
}
}
Expand Down Expand Up @@ -420,7 +431,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
if (checkData.manage_parameters.set_custom_brew_time) {
this.uiLog.log('Brew add - Step 6');
addedBrewObj.config.unix_timestamp = moment(
this.brewBrewing.customCreationDate
this.brewBrewing.customCreationDate,
).unix();
await this.uiBrewStorage.update(addedBrewObj);
}
Expand All @@ -438,7 +449,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
if (this.hasAnyFlowProfileRequisites()) {
this.uiLog.log('Brew add - Step 5');
const savedPath: string = await this.brewBrewing.saveFlowProfile(
addedBrewObj.config.uuid
addedBrewObj.config.uuid,
);
if (savedPath !== '') {
addedBrewObj.flow_profile = savedPath;
Expand All @@ -458,7 +469,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
addedBrewObj.reference_flow_profile.type === REFERENCE_GRAPH_TYPE.NONE
) {
const path = await this.brewBrewing.saveReferenceFlowProfile(
addedBrewObj.config.uuid
addedBrewObj.config.uuid,
);

addedBrewObj.reference_flow_profile = new ReferenceGraph();
Expand Down Expand Up @@ -503,7 +514,7 @@ export class BrewAddComponent implements OnInit, OnDestroy {
(_processNextHandler) => {
// Don't do anything.
this.confirmDismiss();
}
},
);
}
}
Expand Down
26 changes: 18 additions & 8 deletions src/app/brew/brew-edit/brew-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class BrewEditComponent implements OnInit {
private readonly bleManager: CoffeeBluetoothDevicesService,
private readonly uiAlert: UIAlert,
private readonly visualizerService: VisualizerService,
private readonly hapticService: HapticService
private readonly hapticService: HapticService,
) {
this.settings = this.uiSettingsStorage.getSettings();
// Moved from ionViewDidEnter, because of Ionic issues with ion-range
Expand Down Expand Up @@ -104,7 +104,7 @@ export class BrewEditComponent implements OnInit {
},
() => {
// No
}
},
);
} else {
this.dismiss();
Expand All @@ -121,7 +121,7 @@ export class BrewEditComponent implements OnInit {
try {
if (this.brewBrewing.brewBrewingGraphEl) {
Plotly.purge(
this.brewBrewing.brewBrewingGraphEl.profileDiv.nativeElement
this.brewBrewing.brewBrewingGraphEl.profileDiv.nativeElement,
);
}
} catch (ex) {}
Expand All @@ -130,7 +130,7 @@ export class BrewEditComponent implements OnInit {
dismissed: true,
},
undefined,
BrewEditComponent.COMPONENT_ID
BrewEditComponent.COMPONENT_ID,
);
}
private stopScaleTimer() {
Expand Down Expand Up @@ -189,7 +189,7 @@ export class BrewEditComponent implements OnInit {
.length > 0
) {
const savedPath: string = await this.brewBrewing.saveFlowProfile(
this.data.config.uuid
this.data.config.uuid,
);
if (savedPath !== '') {
this.data.flow_profile = savedPath;
Expand All @@ -212,7 +212,17 @@ export class BrewEditComponent implements OnInit {
this.uiToast.showInfoToast('TOAST_BREW_EDITED_SUCCESSFULLY');
this.uiAnalytics.trackEvent(
BREW_TRACKING.TITLE,
BREW_TRACKING.ACTIONS.EDIT_FINISH
BREW_TRACKING.ACTIONS.EDIT_FINISH,
);
this.uiAnalytics.trackEvent(
BREW_TRACKING.TITLE,
BREW_TRACKING.ACTIONS.EDIT_FINISH_PREPARATION_TYPE,
this.data.getPreparation().type,
);
this.uiAnalytics.trackEvent(
BREW_TRACKING.TITLE,
BREW_TRACKING.ACTIONS.EDIT_FINISH_PREPARATION_STYLE,
this.data.getPreparation().style_type,
);
this.dismiss();
}
Expand All @@ -235,15 +245,15 @@ export class BrewEditComponent implements OnInit {
}
this.uiAnalytics.trackEvent(
BREW_TRACKING.TITLE,
BREW_TRACKING.ACTIONS.EDIT
BREW_TRACKING.ACTIONS.EDIT,
);
if (this.settings.security_check_when_going_back === true) {
this.disableHardwareBack = this.platform.backButton.subscribeWithPriority(
9999,
(processNextHandler) => {
// Don't do anything.
this.confirmDismiss();
}
},
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export class PreparationAddTypeComponent implements OnInit {
private readonly uiToast: UIToast,
private readonly translate: TranslateService,
private readonly uiAnalytics: UIAnalytics,
private readonly uiPreparationHelper: UIPreparationHelper
private readonly uiPreparationHelper: UIPreparationHelper,
) {}

public ionViewWillEnter(): void {
this.uiAnalytics.trackEvent(
PREPARATION_TRACKING.TITLE,
PREPARATION_TRACKING.ACTIONS.ADD_TYPE
PREPARATION_TRACKING.ACTIONS.ADD_TYPE,
);
}

Expand Down Expand Up @@ -77,6 +77,17 @@ export class PreparationAddTypeComponent implements OnInit {
) {
await this.uiPreparationHelper.connectDevice(newPreparation);
}

this.uiAnalytics.trackEvent(
PREPARATION_TRACKING.TITLE,
PREPARATION_TRACKING.ACTIONS.ADD_TYPE_FINISH,
this.data.type,
);
this.uiAnalytics.trackEvent(
PREPARATION_TRACKING.TITLE,
PREPARATION_TRACKING.ACTIONS.ADD_STYLE_FINISH,
this.data.style_type,
);
}

public async dismiss(_added: boolean) {
Expand All @@ -86,7 +97,7 @@ export class PreparationAddTypeComponent implements OnInit {
added: _added,
},
undefined,
PreparationAddTypeComponent.COMPONENT_ID
PreparationAddTypeComponent.COMPONENT_ID,
);
}

Expand All @@ -95,7 +106,7 @@ export class PreparationAddTypeComponent implements OnInit {

if (this.data.type !== PREPARATION_TYPES.CUSTOM_PREPARATION) {
this.data.name = this.translate.instant(
'PREPARATION_TYPE_' + this.data.type
'PREPARATION_TYPE_' + this.data.type,
);
}
this.data.style_type = this.data.getPresetStyleType();
Expand Down
2 changes: 2 additions & 0 deletions src/data/tracking/beanTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export default {
SHOW_BREWS: 'SHOW_BREWS',
CUPPING: 'CUPPING',
UNARCHIVE: 'UNARCHIVE',
NFC_SCAN: 'NFC_SCAN',
NFC_WRITE: 'NFC_WRITE',
},
};
14 changes: 14 additions & 0 deletions src/data/tracking/bluetoothTracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
TITLE: 'BLUETOOTH',
ACTIONS: {
SCALE_CONNECTED: 'SCALE_CONNECTED',
PRESSURE_CONNECTED: 'PRESSURE_CONNECTED',
TEMPERATURE_CONNECTED: 'TEMPERATURE_CONNECTED',
REFRACTOMETER_CONNECTED: 'REFRACTOMETER_CONNECTED',

SCALE_USED: 'SCALE_USED',
PRESSURE_USED: 'PRESSURE_USED',
TEMPERATURE_USED: 'TEMPERATURE_USED',
REFRACTOMETER_USED: 'REFRACTOMETER_USED',
},
};
4 changes: 4 additions & 0 deletions src/data/tracking/brewTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ export default {
BRIX_CALCULATION: 'BRIX_CALCULATION',
RATIO_CALCULATION: 'RATIO_CALCULATION',
EXTRACTION_GRAPH: 'EXTRACTION_GRAPH',
ADD_FINISH_PREPARATION_TYPE: 'ADD_FINISH_PREPARATION_TYPE',
ADD_FINISH_PREPARATION_STYLE: 'ADD_FINISH_PREPARATION_STYLE',
EDIT_FINISH_PREPARATION_TYPE: 'EDIT_FINISH_PREPARATION_TYPE',
EDIT_FINISH_PREPARATION_STYLE: 'EDIT_FINISH_PREPARATION_STYLE',
},
};
9 changes: 9 additions & 0 deletions src/data/tracking/intentHandlerTracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
TITLE: 'INTENT_HANDLER',
ACTIONS: {
VISUALIZER_IMPORT: 'VISUALIZER_IMPORT',
IMPORT_ROASTER_BEAN: 'IMPORT_ROASTER_BEAN',
ADD_USER_SHARED_BEAN: 'ADD_USER_SHARED_BEAN',
INTERNAL_CALL: 'INTERNAL_CALL',
},
};
2 changes: 2 additions & 0 deletions src/data/tracking/preparationTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default {
ADD: 'ADD',
ADD_FINISH: 'ADD_FINISH',
ADD_TYPE: 'ADD_TYPE',
ADD_TYPE_FINISH: 'ADD_TYPE_FINISH',
ADD_STYLE_FINISH: 'ADD_STYLE_FINISH',
POPOVER_ACTIONS: 'POPOVER_ACTIONS',
REPEAT: 'REPEAT',
EDIT: 'EDIT',
Expand Down
Loading

0 comments on commit 45799ee

Please sign in to comment.