Skip to content

Commit

Permalink
Merge pull request #337 from xiv-gear-planner/more-analytics-events
Browse files Browse the repository at this point in the history
Add more analytics events
  • Loading branch information
xpdota authored Sep 29, 2024
2 parents 0d5946d + 754b593 commit 45cc081
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 13 deletions.
20 changes: 15 additions & 5 deletions packages/core/src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export function recordEvent(name: string, data?: ExtraData) {
}
}

export function recordCurrentSheetEvent(eventName: string, extraData: ExtraData) {
const sheet = window['currentSheet'];
if (sheet instanceof GearPlanSheet) {
recordSheetEvent(eventName, sheet, extraData);
}
else {
recordEvent(eventName, extraData);
}
}

export function recordSheetEvent(eventName: string, sheet: GearPlanSheet, extraData: ExtraData = {}) {
const fullData = {
// ...prepSheetData(sheet),
Expand All @@ -27,9 +37,9 @@ export function recordSheetEvent(eventName: string, sheet: GearPlanSheet, extraD
}

function prepSheetData(sheet: GearPlanSheet) {
return {
'job': sheet.classJobName,
'level': sheet.level,
'isync': sheet.ilvlSync
}
return {
'job': sheet.classJobName,
'level': sheet.level,
'isync': sheet.ilvlSync
}
}
14 changes: 13 additions & 1 deletion packages/frontend/src/scripts/components/gear_edit_toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {StatTierDisplay} from "./stat_tier_display";
import {CharacterGearSet} from "@xivgear/core/gear";
import {GearPlanSheet} from "@xivgear/core/sheet";
import {makeActionButton, redoIcon, undoIcon} from "@xivgear/common-ui/components/util";
import {recordEvent} from "@xivgear/core/analytics/analytics";
import {recordEvent, recordSheetEvent} from "@xivgear/core/analytics/analytics";

export class UndoArea extends HTMLDivElement {
private _currentSet: CharacterGearSet;
Expand Down Expand Up @@ -69,10 +69,22 @@ export class GearEditToolbar extends HTMLDivElement {
ilvlDiv.classList.add('ilvl-picker-area');
const itemIlvlRange = new ILvlRangePicker(itemDisplaySettings, 'minILvl', 'maxILvl', 'Gear:');
itemIlvlRange.addListener(displayUpdateCallback);
itemIlvlRange.addListener((min, max) => {
recordSheetEvent('itemIlvlRange', sheet, {
min: min,
max: max
});
});
ilvlDiv.appendChild(itemIlvlRange);

const foodIlvlRange = new ILvlRangePicker(itemDisplaySettings, 'minILvlFood', 'maxILvlFood', 'Food:');
foodIlvlRange.addListener(displayUpdateCallback);
foodIlvlRange.addListener((min, max) => {
recordSheetEvent('foodIlvlRange', sheet, {
min: min,
max: max
});
});
ilvlDiv.appendChild(foodIlvlRange);

this.appendChild(ilvlDiv);
Expand Down
7 changes: 6 additions & 1 deletion packages/frontend/src/scripts/components/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
import {
FieldBoundCheckBox,
FieldBoundIntField,
labeledCheckbox, makeActionButton,
labeledCheckbox,
makeActionButton,
makeTrashIcon,
quickElement
} from "@xivgear/common-ui/components/util";
Expand All @@ -44,6 +45,7 @@ import {GearPlanSheet} from "@xivgear/core/sheet";
import {makeRelicStatEditor} from "./relic_stats";
import {ShowHideButton} from "@xivgear/common-ui/components/show_hide_chevron";
import {BaseModal} from "@xivgear/common-ui/components/modal";
import {recordSheetEvent} from "@xivgear/core/analytics/analytics";

function statCellStylerRemover(cell: CustomCell<GearSlotItem, unknown>) {
cell.classList.remove("secondary");
Expand Down Expand Up @@ -605,6 +607,9 @@ export class GearItemsTable extends CustomTable<GearSlotItem, EquipmentSet> {
// TODO: just make the getters/setters on this class instead
data.push(makeShowHideRow(slot.name, gearSet.isSlotCollapsed(slotId), (val) => {
gearSet.setSlotCollapsed(slotId, val);
recordSheetEvent('hideSlot', sheet, {
hidden: val
});
this.updateShowHide();
}, extras));
let itemsInSlot = itemMapping.get(slot.gearSlot);
Expand Down
7 changes: 6 additions & 1 deletion packages/frontend/src/scripts/components/materia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
quickElement
} from "@xivgear/common-ui/components/util";
import {GearPlanSheet} from "@xivgear/core/sheet";
import {recordEvent} from "@xivgear/core/analytics/analytics";
import {recordCurrentSheetEvent, recordEvent} from "@xivgear/core/analytics/analytics";

/**
* Component for managing all materia slots on an item
Expand Down Expand Up @@ -426,6 +426,11 @@ export class MateriaPriorityPicker extends HTMLElement {
}
}]
});
minGcdInput.addListener(val => {
recordCurrentSheetEvent('currentSheet', {
gcd: val
});
});
minGcdInput.pattern = '\\d\\.\\d\\d?';
minGcdInput.title = 'Enter the minimum desired GCD in the form x.yz.\nSkS/SpS materia will be de-prioritized once this target GCD is met.';
minGcdInput.classList.add('min-gcd-input');
Expand Down
11 changes: 11 additions & 0 deletions packages/frontend/src/scripts/components/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {CustomFoodPopup, CustomItemPopup} from "./custom_item_manager";
import {confirmDelete} from "@xivgear/common-ui/components/delete_confirm";
import { SimulationGui } from "../sims/simulation_gui";
import { makeGui } from "../sims/sim_guis";
import {recordSheetEvent} from "@xivgear/core/analytics/analytics";

export type GearSetSel = SingleCellRowOrHeaderSelect<CharacterGearSet>;

Expand Down Expand Up @@ -1520,6 +1521,11 @@ export class GearPlanSheetGui extends GearPlanSheet {
},
[undefined, ...Object.keys(RACE_STATS) as RaceName[]]);
buttonsArea.appendChild(raceDropdown);
raceDropdown.addListener((val) => {
recordSheetEvent('changeRace', this, {
race: val
});
});

const partySizeDropdown = new FieldBoundDataSelect<GearPlanSheet, PartyBonusAmount>(
this,
Expand All @@ -1534,6 +1540,11 @@ export class GearPlanSheetGui extends GearPlanSheet {
},
rangeInc(0, MAX_PARTY_BONUS)
);
partySizeDropdown.addListener((val) => {
recordSheetEvent('changePartyBonus', this, {
partyBonus: val
});
});
buttonsArea.appendChild(partySizeDropdown);

if (this.saveKey) {
Expand Down
11 changes: 10 additions & 1 deletion packages/frontend/src/scripts/components/stat_tier_display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
vitToHp
} from "@xivgear/xivmath/xivmath";
import {GearPlanSheet} from "@xivgear/core/sheet";
import {recordSheetEvent} from "@xivgear/core/analytics/analytics";

interface Tiering {
lower: number,
Expand Down Expand Up @@ -174,7 +175,11 @@ export class StatTierDisplay extends HTMLDivElement {
// singleStatTierDisplay.addEventListener('click', () => this.toggleState());
singleStatTierDisplay.addEventListener('click', (ev) => {
if (ev.detail == 1) {
singleStatTierDisplay.expanded = !singleStatTierDisplay.expanded;
const expanded = singleStatTierDisplay.expanded = !singleStatTierDisplay.expanded;
recordSheetEvent('singleTierDisplayClick', this.sheet, {
expanded: expanded,
stat: stat
});
}
else if (ev.detail >= 2) {
// If this is a double click, the first click would have already toggled the state
Expand All @@ -183,6 +188,10 @@ export class StatTierDisplay extends HTMLDivElement {
for (const display of this.eleMap.values()) {
display.expanded = newState;
}
recordSheetEvent('allTierDisplayClick', this.sheet, {
expanded: newState,
stat: stat
});
}
});
}
Expand Down
12 changes: 8 additions & 4 deletions packages/frontend/src/scripts/settings/settings_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {BaseModal} from "@xivgear/common-ui/components/modal";
import {FieldBoundCheckBox} from "@xivgear/common-ui/components/util";
import {DISPLAY_SETTINGS} from "./display_settings";
import {BoolToggle} from "@xivgear/common-ui/components/bool_toggle";
import {recordEvent} from "@xivgear/core/analytics/analytics";


class SettingsModal extends BaseModal {
Expand All @@ -11,10 +12,12 @@ class SettingsModal extends BaseModal {
// TODO: consider using slide toggles

const settings = DISPLAY_SETTINGS;
const lightModeToggle = new BoolToggle(new FieldBoundCheckBox(settings, 'lightMode'), 'Light', 'Dark');
const modernThemeToggle = new BoolToggle(new FieldBoundCheckBox(settings, 'modernTheme'), 'Modern', 'Classic');
// const lightModeToggle = labeledCheckbox('Light Mode', new FieldBoundCheckBox(settings, 'lightMode'));
// const modernThemeToggle = labeledCheckbox('Modern Theme', new FieldBoundCheckBox(settings, 'modernTheme'));
const lightModeCb = new FieldBoundCheckBox(settings, 'lightMode');
const lightModeToggle = new BoolToggle(lightModeCb, 'Light', 'Dark');
lightModeCb.addListener(val => recordEvent('lightModeToggle', {lightMode: val}));
const modernThemeCb = new FieldBoundCheckBox(settings, 'modernTheme');
const modernThemeToggle = new BoolToggle(modernThemeCb, 'Modern', 'Classic');
modernThemeCb.addListener(val => recordEvent('modernTheme', {modernTheme: val}));

this.contentArea.append(lightModeToggle);
this.contentArea.append(modernThemeToggle);
Expand All @@ -25,6 +28,7 @@ class SettingsModal extends BaseModal {
export function showSettingsModal() {
const dialog = new SettingsModal();
dialog.attachAndShow();
recordEvent('openSettingsModal');
}

customElements.define('settings-modal', SettingsModal);

0 comments on commit 45cc081

Please sign in to comment.