CSR-762 GA WIP

This commit is contained in:
Katie 2022-10-07 15:29:32 -04:00
parent ee53cac9e3
commit 08f43a15a2
4 changed files with 99 additions and 47 deletions

View file

@ -12,8 +12,8 @@
</template> </template>
<script> <script>
// TODO KO glass-part-question has nested button questions // TODO KO glass-part-question has nested button questions
// TODO KO selectedValues - make consistent for checkbox and radio if possible // TODO KO selectedValues - make consistent for checkbox and radio if possible
export default { export default {
name: "app", name: "app",
data() { data() {
@ -28,7 +28,7 @@ export default {
// console.log(targetType) // console.log(targetType)
if (targetType !== "radio" && targetType !== "checkbox") { if (targetType !== "radio" && targetType !== "checkbox") {
this.handleInputFocus({ this.handleInputFocus({
groupName: null groupName: null,
}); });
} }
}, },
@ -55,6 +55,13 @@ export default {
} }
}, },
}, },
watch: {
$route: {
handler() {
this.lastFocusedInputGroup = null;
},
},
},
}; };
</script> </script>

View file

@ -5,6 +5,8 @@
@focusin="handleFocus" @focusin="handleFocus"
@focusout="handleBlur" @focusout="handleBlur"
@mousedown.left="handleEventAction('click', $event)"> @mousedown.left="handleEventAction('click', $event)">
lastValuePushedToGa: {{ lastValuePushedToGa }}<br />
<input <input
:type="inputType" :type="inputType"
:id="buttonId" :id="buttonId"
@ -61,10 +63,12 @@ export default {
default: true, default: true,
}, },
isRequired: Boolean, isRequired: Boolean,
lastValuePushedToGa: { lastValuePushedToGa: [String, Number],
type: [String, Number], setLastValuePushedToGa: Function
required: true, // wasThisValueJustPushedToGa: {
}, // type: [String, Number],
// required: true,
// },
// fullName: { // fullName: {
// type: String, // type: String,
// default: "", // default: "",
@ -75,6 +79,8 @@ export default {
return { return {
valueToEmit: null, valueToEmit: null,
// lastValuePushedToGa: null, // lastValuePushedToGa: null,
// wasPushedToGa: false
// wasThisValueJustPushedToGa: false,
}; };
}, },
mounted() { mounted() {
@ -99,7 +105,7 @@ export default {
// even if it's pushing from here, it needs to keep track // even if it's pushing from here, it needs to keep track
// of lastFocusedInputGroupName and such // of lastFocusedInputGroupName and such
this.pushClickEventToGA(); this.pushClickEventToGA("test");
break; break;
} }
} else { } else {
@ -108,7 +114,7 @@ export default {
case this.eventTypes.ENTER: case this.eventTypes.ENTER:
case this.eventTypes.SPACE: case this.eventTypes.SPACE:
this.handleClick(e); this.handleClick(e);
this.pushClickEventToGA("test");
// this.pushClickEventToGAIfReady(); // this.pushClickEventToGAIfReady();
break; break;
case this.eventTypes.CHANGE: case this.eventTypes.CHANGE:
@ -118,12 +124,13 @@ export default {
break; break;
} }
if (eventType === this.eventTypes.CLICK) { // if (eventType === this.eventTypes.CLICK) {
console.log("PUSH FROM RADIO CLICK"); // console.log("PUSH FROM RADIO CLICK");
this.pushClickEventToGA(); // this.pushClickEventToGA("test");
} // }
} }
// this.wasThisValueJustPushedToGa = false;
// this.pushClickEventToGA(eventType); // this.pushClickEventToGA(eventType);
}, },
handleSelectionChange(e) { handleSelectionChange(e) {
@ -155,11 +162,18 @@ export default {
}, },
handleClick(e) { handleClick(e) {
this.handleSelectionChange(e); this.handleSelectionChange(e);
console.log("inputButtonClicked");
this.$emit("inputButtonClicked", { // TODO KO NOTES
selectedAnswers: this.valueToEmit, // if you click on a radio button > go to another button > go back to original > tab out
lastValuePushedToGa: this.lastValuePushedToGa, // shouldn't do anything, but it does because wasThisValueJustPushedToGa gets set to false?
}); // console.log("---inputButtonClicked: ", {
// value: this.value,
// // wasThisValueJustPushedToGa: this.wasThisValueJustPushedToGa
// });
// const lastValuePushedToGa = this.wasThisValueJustPushedToGa ? this.value : null;
// this.wasThisValueJustPushedToGa = false;
this.$emit("inputButtonClicked", this.valueToEmit);
}, },
onFocusCallbackForRoot() { onFocusCallbackForRoot() {
// console.log("onFocusCallbackForRoot: ", { // console.log("onFocusCallbackForRoot: ", {
@ -200,19 +214,41 @@ export default {
onFocusCallback: this.onFocusCallbackForRoot, onFocusCallback: this.onFocusCallbackForRoot,
}); });
}, },
pushClickEventToGA(eventType) {
if (this.isMultiSelect || !eventType) { // TODO KO NOTES
console.log("PUSHING: ", this.value); // base-input-button has the value to push to GA and the click vs focus events
// but button-question would have to keep track of the button group's last held value
// is there a way to make each individual button hold the group's last held value
// WITHOUT listening to an event on each component that uses the button?
pushClickEventToGA(source) {
if (source == "test") {
// this.wasThisValueJustPushedToGa = true;
// this.$emit("update:lastValuePushedToGa", this.value)
console.log("------------------PUSHING 1: ", this.value);
// this.$emit("gaClickEventPushed", this.value)
this.setLastValuePushedToGa(this.value)
// this.wasPushedToGa = true
} else { } else {
if (eventType === this.eventTypes.CLICK) { // console.log("PCETGA: ", {
console.log("PUSHING: ", this.value); // lastValuePushedToGa: this.lastValuePushedToGa,
} else { // isChecked: this.isChecked,
if ( // value: this.value,
this.isChecked && // // wasThisValueJustPushedToGa: this.wasThisValueJustPushedToGa
this.lastValuePushedToGa != this.value // });
) { if (
console.log("PUSHING: ", this.value); !this.isValueSelectedOnClick &&
} this.isChecked &&
// !this.wasThisValueJustPushedToGa &&
this.lastValuePushedToGa != this.value
) {
// this.$emit("update:lastValuePushedToGa", this.value)
// this.wasPushedToGa = true
// this.wasThisValueJustPushedToGa = true;
console.log("------------------PUSHING 2: ", this.value);
// this.$emit("gaClickEventPushed", this.value)
this.setLastValuePushedToGa(this.value)
} }
} }

View file

@ -34,7 +34,6 @@
}} }}
</legend> </legend>
<div :class="getComponentLoopWrapperClasses"> <div :class="getComponentLoopWrapperClasses">
lastValuePushedToGa: {{ lastValuePushedToGa }}<br />
<div <div
:class="getComponentWrapperClasses" :class="getComponentWrapperClasses"
v-for="answer in buttonsInfo" v-for="answer in buttonsInfo"
@ -49,12 +48,13 @@
:isMultiSelect="isMultiSelect" :isMultiSelect="isMultiSelect"
:value="answer.value" :value="answer.value"
:modelValue="modelValue" :modelValue="modelValue"
v-model:lastValuePushedToGa="lastValuePushedToGa"
:selectingInitiatesLoad="selectingInitiatesLoad" :selectingInitiatesLoad="selectingInitiatesLoad"
:isWide="isWide" :isWide="isWide"
:validationRules="validationRules" :validationRules="validationRules"
:textPosition="textPosition" :textPosition="textPosition"
:selectOnKeypress="selectOnKeypress" :selectOnKeypress="selectOnKeypress"
:lastValuePushedToGa="lastValuePushedToGa"
:setLastValuePushedToGa="setLastValuePushedToGa"
@inputButtonClicked="handleAnswerChange" /> @inputButtonClicked="handleAnswerChange" />
<!-- For nested questions --> <!-- For nested questions -->
<transition name="fade" mode="out-in"> <transition name="fade" mode="out-in">
@ -130,8 +130,8 @@ export default {
return { return {
selectedValues: "", selectedValues: "",
// lastFocusedInputGroup: "", // lastFocusedInputGroup: "",
lastPushedGaEventValue: null, lastValuePushedToGa: null,
mostRecentlySelectedValue: null, // mostRecentlySelectedValue: null,
}; };
}, },
computed: { computed: {
@ -229,9 +229,12 @@ export default {
: this.formatString(answer.toString()); : this.formatString(answer.toString());
} }
}, },
handleAnswerChange({ selectedAnswers, mostRecentlySelectedValue }) { handleAnswerChange(selectedAnswers) {
this.selectedValues = selectedAnswers; this.selectedValues = selectedAnswers;
this.mostRecentlySelectedValue = mostRecentlySelectedValue; // if (lastValuePushedToGa) {
// this.lastValuePushedToGa = lastValuePushedToGa;
// // console.log("BQ lastValuePushedToGa: ", lastValuePushedToGa);
// }
// if (this.isValueSelectedOnClick) { // if (this.isValueSelectedOnClick) {
// this.pushClickEventToGA(); // this.pushClickEventToGA();
@ -240,7 +243,10 @@ export default {
this.$emit("buttonQuestionChange", selectedAnswers); this.$emit("buttonQuestionChange", selectedAnswers);
this.$emit("update:modelValue", selectedAnswers); this.$emit("update:modelValue", selectedAnswers);
}, },
///////////////////////////// /////////////////////////////
setLastValuePushedToGa(lastValuePushedToGa) {
this.lastValuePushedToGa = lastValuePushedToGa;
},
// onFocusCallbackForRoot() { // onFocusCallbackForRoot() {
// console.log("onFocusCallbackForRoot: ", { // console.log("onFocusCallbackForRoot: ", {
// isValueSelectedOnClick: this.isValueSelectedOnClick, // isValueSelectedOnClick: this.isValueSelectedOnClick,
@ -297,7 +303,7 @@ export default {
// this.valueToLogType // this.valueToLogType
// ); // );
// }, // },
////////////////////////////////// //////////////////////////////////
// pushClickEventToGA() { // pushClickEventToGA() {
// // const valueToPushToGa = // // const valueToPushToGa =
// // value?.toString() ?? this.selectedValues?.toString(); // // value?.toString() ?? this.selectedValues?.toString();

View file

@ -9,7 +9,7 @@ export default {
buttonImage: String, buttonImage: String,
altText: { altText: {
type: String, type: String,
default: "" default: "",
}, },
textPosition: String, textPosition: String,
screenReaderOnlyText: String, screenReaderOnlyText: String,
@ -18,22 +18,25 @@ export default {
isWide: Boolean, isWide: Boolean,
isRequired: { isRequired: {
type: Boolean, type: Boolean,
default: true default: true,
}, },
// pushClickEventToGA: Function, // pushClickEventToGA: Function,
lastValuePushedToGa: [String, Number] lastValuePushedToGa: [String, Number],
setLastValuePushedToGa: Function
}, },
methods: { methods: {
handleAnswerChange(e) { handleAnswerChange(e) {
if (this.preHandleAnswerChange) { if (this.preHandleAnswerChange) {
this.preHandleAnswerChange(e.selectedAnswers) this.preHandleAnswerChange(e);
} }
this.$emit("change", e.selectedAnswers); // console.log("IBWM: ", e)
// this.$emit("update:lastValuePushedToGa", e.lastValuePushedToGa); this.$emit("change", e);
// if (e.lastValuePushedToGa) {
// console.log("sup")
// this.$emit("update:lastValuePushedToGa", e.lastValuePushedToGa);
// }
}, },
}, },
// computed: { // computed: {
// selectedValueHandler: { // selectedValueHandler: {