Create generic GTM logging method
This commit is contained in:
parent
bbbc66f124
commit
db9f5f38f7
2 changed files with 152 additions and 0 deletions
|
|
@ -136,6 +136,7 @@ export default {
|
|||
vm.lineItems = lineItemsFromSubmittedOrder;
|
||||
vm.vaps = availableVaps;
|
||||
analyticsMixin.methods.pushSubmittedOrderToDataLayer();
|
||||
analyticsMixin.methods.pushOrderToDataLayer();
|
||||
});
|
||||
},
|
||||
data() {
|
||||
|
|
|
|||
|
|
@ -120,6 +120,157 @@ export default {
|
|||
await this.logPageView(analyticsPageEvents.ENTRY);
|
||||
},
|
||||
|
||||
pushOrderToDataLayer() {
|
||||
// Get correct order object
|
||||
const hasSubmittedOrder = store.getters.hasSubmittedOrder;
|
||||
const order = hasSubmittedOrder ? store.getters.submittedOrder : store.getters.order;
|
||||
|
||||
// Begin assembling payload for data layer
|
||||
const payload = {};
|
||||
|
||||
// Service Zip
|
||||
if (
|
||||
order.serviceLocation.appointmentType === AppointmentTypeStrings.MOBILE &&
|
||||
order.serviceLocation.zipCode
|
||||
) {
|
||||
payload.serviceZipCode = order.serviceLocation.zipCode;
|
||||
} else if (
|
||||
order.serviceLocation.appointmentType &&
|
||||
order.serviceLocation.appointmentType !== AppointmentTypeStrings.MOBILE &&
|
||||
order.serviceLocation.provider.address.zipCode
|
||||
) {
|
||||
payload.serviceZipCode = order.serviceLocation.provider.address.zipCode;
|
||||
} else {
|
||||
payload.serviceZipCode = "";
|
||||
}
|
||||
|
||||
// Damage Type
|
||||
if (order.damage.isRepair !== null && order.damage.isRepair !== undefined) {
|
||||
payload.damageType = order.damage.isRepair ? "repair" : "replace";
|
||||
} else {
|
||||
payload.damageType = "";
|
||||
}
|
||||
|
||||
// Account Type
|
||||
if (order.payment.isInsurance !== null && order.payment.isInsurance !== undefined) {
|
||||
payload.accountType = order.payment.isInsurance ? "insurance" : "cash";
|
||||
} else {
|
||||
payload.accountType = "";
|
||||
}
|
||||
|
||||
// Promo Codes
|
||||
const promos = order.lineItems.promos ?? [];
|
||||
if (promos.length === 0) {
|
||||
payload.promoCodes = "";
|
||||
} else {
|
||||
const promoCodes = promos.map((promo) => promo.promoCode);
|
||||
const promoString = promoCodes.reduce((prev, next) => `${prev},${next}`);
|
||||
payload.promoCodes = promoString;
|
||||
}
|
||||
|
||||
// Vehicle info
|
||||
if (order.vehicle.year !== null && order.vehicle.year !== undefined) {
|
||||
// Ensure cast to string.
|
||||
payload.vehicleYear = `${order.vehicle.year}`;
|
||||
} else {
|
||||
payload.vehicleYear = "";
|
||||
}
|
||||
|
||||
if (order.vehicle.make) {
|
||||
payload.vehicleMake = order.vehicle.make;
|
||||
} else {
|
||||
payload.vehicleMake = "";
|
||||
}
|
||||
|
||||
if (order.vehicle.model) {
|
||||
payload.vehicleModel = order.vehicle.model;
|
||||
} else {
|
||||
payload.vehicleModel = "";
|
||||
}
|
||||
|
||||
if (order.vehicle.style) {
|
||||
payload.vehicleStyle = order.vehicle.style;
|
||||
} else {
|
||||
payload.vehicleStyle = "";
|
||||
}
|
||||
|
||||
// Glass pieces
|
||||
const glass = order.damage.glassToReplace ?? [];
|
||||
if (glass.length === 0) {
|
||||
payload.glassToReplace = "";
|
||||
} else {
|
||||
const glassNames = glass.map((g) => `${g.glassLocation}/${g.glassName}`);
|
||||
const glassString = glassNames.reduce((prev, next) => `${prev},${next}`);
|
||||
|
||||
payload.glassToReplace = glassString;
|
||||
}
|
||||
|
||||
// Work Order Id
|
||||
if (order.workOrderId) {
|
||||
payload.workOrderId = parseInt(order.workOrderId);
|
||||
} else {
|
||||
payload.workOrderId = "";
|
||||
}
|
||||
|
||||
// Provider Ctu
|
||||
if (order.serviceLocation.zipCodeCtu) {
|
||||
payload.providerCtu = parseInt(order.serviceLocation.zipCodeCtu);
|
||||
} else {
|
||||
payload.providerCtu = "";
|
||||
}
|
||||
|
||||
// Work Order Number
|
||||
if (order.workOrderNumber) {
|
||||
payload.orderNumber = order.workOrderNumber;
|
||||
} else {
|
||||
payload.orderNumber = "";
|
||||
}
|
||||
|
||||
// Pricing
|
||||
// Only fire for completed orders?
|
||||
if (hasSubmittedOrder) {
|
||||
const lineItems = order.lineItems ?? {};
|
||||
const combinedLineItems = [
|
||||
...(lineItems.glassParts ?? []),
|
||||
...(lineItems.supportingItems ?? []),
|
||||
...(lineItems.vaps ?? []),
|
||||
...(lineItems.promos ?? []),
|
||||
];
|
||||
|
||||
const subtotal = baseMixin.methods
|
||||
.getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, false)
|
||||
.toFixed(2);
|
||||
|
||||
const total = baseMixin.methods
|
||||
.getTotalPriceOfAllLineItemsAndChildParts(combinedLineItems, true)
|
||||
.toFixed(2);
|
||||
|
||||
payload.priceTotal = parseFloat(total);
|
||||
payload.priceSubTotal = parseFloat(subtotal);
|
||||
} else {
|
||||
payload.priceTotal = "";
|
||||
payload.priceSubTotal = "";
|
||||
}
|
||||
|
||||
// Recalibration
|
||||
if (hasSubmittedOrder) {
|
||||
payload.isRecalibrationOnOrder = store.getters.isRecalibrationOnSubmittedOrder;
|
||||
} else {
|
||||
payload.isRecalibrationOnOrder = store.getters.isRecalibrationOnOrder;
|
||||
}
|
||||
|
||||
// Appointment Type
|
||||
if (order.serviceLocation.appointmentType) {
|
||||
payload.appointmentType = order.serviceLocation.appointmentType;
|
||||
} else {
|
||||
payload.appointmentType = "";
|
||||
}
|
||||
|
||||
payload.isNew = true;
|
||||
|
||||
pushToDataLayerIfDefined(payload);
|
||||
},
|
||||
|
||||
pushSubmittedOrderToDataLayer() {
|
||||
// check if submitted order exists; exit if not.
|
||||
const hasSubmittedOrder = store.getters.hasSubmittedOrder;
|
||||
|
|
|
|||
Loading…
Reference in a new issue