add unhelpful survey GA4 events

This commit is contained in:
Ryan Johnson 2024-10-29 14:30:09 -07:00
Родитель b7a7972b18
Коммит d964262752
Не найден ключ, соответствующий данной подписи
3 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -138,6 +138,10 @@ export default function AjaxVote(form, options) {
// remove the extra message when the survey opens.
$container.remove();
// Dispatch a custom "survey-loaded" event to allow other code to add event
// listeners to the survey, now that it has been freshly loaded into the DOM.
document.dispatchEvent(new CustomEvent("survey-loaded", { bubbles: true }));
$submit.prop('disabled', true);
function validate() {

Просмотреть файл

@ -20,6 +20,29 @@ document.addEventListener("DOMContentLoaded", () => {
}
});
document.addEventListener("survey-loaded", (event) => {
const surveyCloseButton = document.querySelector("#unhelpful-survey .close-button");
const surveySubmitButton = document.querySelector('#unhelpful-survey button[type="submit"]');
function trackCloseEvent(event) {
trackEvent("article_unhelpful_survey_close");
}
if (surveySubmitButton) {
surveySubmitButton.addEventListener("click", function(event) {
trackEvent("article_unhelpful_survey_submit");
if (surveyCloseButton) {
// After the survey is submitted, we don't want to track the
// close of the final message.
surveyCloseButton.removeEventListener("click", trackCloseEvent)
}
});
}
if (surveyCloseButton) {
surveyCloseButton.addEventListener("click", trackCloseEvent);
}
});
// Track showfor changes in GA.
if (versionSelect) {
versionSelect.addEventListener("change", function(event) {

Просмотреть файл

@ -22,6 +22,5 @@
<div class="sumo-button-wrap align-end">
<button class="sumo-button button-sm primary-button" type="submit" data-type="submit">{{ _('Submit') }}</button>
</div>
</form>
</div>