INSR-8884: Better null/undefined handling for analytics events

This commit is contained in:
Alex Humphries 2026-04-21 17:24:21 -04:00
parent 9a7b452b98
commit 746b45e372
3 changed files with 17 additions and 15 deletions

View file

@ -44,7 +44,8 @@ export default {
return this.modelValue; return this.modelValue;
}, },
set(selectedMethod) { set(selectedMethod) {
this.pushEventToGA('submit_order', 'payment_type_selected', analyticsPaymentTypeMap.get(selectedMethod), true); const paymentMethod = analyticsPaymentTypeMap.get(this.piaType) ?? 'UNKNOWN';
this.pushEventToGA('submit_order', 'payment_type_selected', paymentMethod, true);
this.$emit('update:modelValue', selectedMethod); this.$emit('update:modelValue', selectedMethod);
} }
}, },

View file

@ -158,6 +158,7 @@ import widgetFields from '@/constants/cms-widget-fields';
import MaskaFormattedMasks from '@/constants/maska-masks'; import MaskaFormattedMasks from '@/constants/maska-masks';
import { containsRecalParts } from '@/helpers/recal-helper'; import { containsRecalParts } from '@/helpers/recal-helper';
import coverageType from '@/constants/coverage-type'; import coverageType from '@/constants/coverage-type';
import partTypeStrings from '@/constants/part-type-strings';
export default { export default {
name: 'payment-method', name: 'payment-method',
@ -511,26 +512,26 @@ export default {
handleAnalyticsEventsOnMounted() { handleAnalyticsEventsOnMounted() {
const mobileOrInshop = this.mainStore.isMobileAppointment ? 'mobile' : 'in_shop'; const mobileOrInshop = this.mainStore.isMobileAppointment ? 'mobile' : 'in_shop';
const verifiedOrNotVerified = this.mainStore.isVerified ? 'verified' : 'not_verified'; const verifiedOrNotVerified = this.mainStore.isVerified ? 'verified' : 'not_verified';
const repairOrReplace = this.mainStore.isRepair ? 'repair' : 'replace'; const repairOrReplace = this.mainStore.damage.isRepair ? 'repair' : 'replace';
this.pushEventToGA('order_summary', 'safelite', `${mobileOrInshop}_${repairOrReplace}_${verifiedOrNotVerified}`, true); this.pushEventToGA('order_summary', 'safelite', `${mobileOrInshop}_${repairOrReplace}_${verifiedOrNotVerified}`, true);
if (containsRecalParts(this.mainStore.lineItems)) { if (containsRecalParts(this.mainStore.lineItems)) {
let coverageType = ''; let coverageTypeForLabel = '';
if (this.mainStore.isITAC) { if (this.mainStore.isITAC) {
coverageType = 'ITAC'; coverageTypeForLabel = 'ITAC';
} else if (this.mainStore.isNoComp) { } else if (this.mainStore.isNoComp) {
coverageType = 'no_comp'; coverageTypeForLabel = 'no_comp';
} else if (this.mainStore.isVerified) { } else if (this.mainStore.isVerified) {
coverageType = 'verified'; coverageTypeForLabel = 'verified';
} else { } else {
coverageType = 'unverified'; coverageTypeForLabel = 'unverified';
} }
const recalibrationType = this.mainStore.lineItems.glassParts?.find((part) => part.requiresRecalibration)?.recalibrationType; const recalibrationType = this.mainStore.lineItems.glassParts?.find((part) => part.requiresRecalibration)?.recalibrationType;
this.pushEventToGA(`recalibration_added_${coverageType}`, this.mainStore.vehicle.carId, `recal_type_${recalibrationType}`.replace(/ /g, '_').toLowerCase(), true); this.pushEventToGA(`recalibration_added_${coverageTypeForLabel}`, this.mainStore.vehicle.carId, `recal_type_${recalibrationType}`.replace(/ /g, '_').toLowerCase(), true);
} }
const hasFrontWiper = this.mainStore.lineItems.vaps.some((part) => part.partType === partTypeStrings.FRONT_WIPER); const hasFrontWiper = this.mainStore.lineItems?.vaps?.some((part) => part.partType === partTypeStrings.FRONT_WIPER);
const hasRearWiper = this.mainStore.lineItems.vaps.some((part) => part.partType === partTypeStrings.REAR_WIPER); const hasRearWiper = this.mainStore.lineItems?.vaps?.some((part) => part.partType === partTypeStrings.REAR_WIPER);
const wiperEventLabel = `front_${hasFrontWiper ? 'advanced' : 'none'}_rear_${hasRearWiper ? 'advanced' : 'none'}`; const wiperEventLabel = `front_${hasFrontWiper ? 'advanced' : 'none'}_rear_${hasRearWiper ? 'advanced' : 'none'}`;
this.pushEventToGA('wipers', 'attached_to_order', wiperEventLabel, true); this.pushEventToGA('wipers', 'attached_to_order', wiperEventLabel, true);
}, },
@ -538,7 +539,7 @@ export default {
this.pushEventToGA('order_summary', 'edit', 'contact_details', true); this.pushEventToGA('order_summary', 'edit', 'contact_details', true);
let action; let action;
let label; let label;
switch (this.mainStore.coverageType) { switch (this.mainStore.insuranceCoverage.coverageType) {
case coverageType.Deductible: case coverageType.Deductible:
action = 'Covered'; action = 'Covered';
label = this.mainStore.currentDeductible; label = this.mainStore.currentDeductible;

View file

@ -207,8 +207,8 @@ export default {
methods: { methods: {
openModalAction(eventData) { openModalAction(eventData) {
this.$refs[eventData.route].openModal(); this.$refs[eventData.route].openModal();
const packageName = analyticsServicePackageMap.get(eventData.packageName); const packageName = analyticsServicePackageMap.get(eventData.packageName) ?? 'UNKNOWN_PACKAGE';
const modalName = analyticsVapsModalMap.get(eventData.route); const modalName = analyticsVapsModalMap.get(eventData.route) ?? 'UNKNOWN_MODAL';
this.pushEventToGA('service_package', 'modal_displayed', `${packageName}_${modalName}_modal_displayed`, true); this.pushEventToGA('service_package', 'modal_displayed', `${packageName}_${modalName}_modal_displayed`, true);
}, },
arePagePrerequisitesValid() { arePagePrerequisitesValid() {
@ -239,8 +239,8 @@ export default {
} }
store.updateVaps(this.selectedVaps); store.updateVaps(this.selectedVaps);
store.updateServicePackage(this.selectedPackageTier); store.updateServicePackage(this.selectedPackageTier);
const packageName = analyticsServicePackageMap.get(this.selectedPackageTier); const packageName = analyticsServicePackageMap.get(this.selectedPackageTier) ?? 'UNKNOWN_PACKAGE';
this.pushEventToGA('service_package', 'attached_a_package', packageName, true); this.pushEventToGA('service_package', 'attached_a_package', packageName, true);
const scenario = store.isMobileAppointment const scenario = store.isMobileAppointment