From fcfd2e13bd57ca9e363429dac1261d36847000d4 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Sun, 10 Sep 2023 20:29:34 +0300 Subject: [PATCH] track form open after link click --- app/javascript/submission_form/form.vue | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/javascript/submission_form/form.vue b/app/javascript/submission_form/form.vue index 19d885b9..d9bca6c0 100644 --- a/app/javascript/submission_form/form.vue +++ b/app/javascript/submission_form/form.vue @@ -494,8 +494,9 @@ export default { this.$nextTick(() => { this.recalculateButtonDisabledKey = Math.random() - this.maybeTrackEmailClick() - this.trackViewForm() + this.maybeTrackEmailClick().finally(() => { + this.trackViewForm() + }) }) }, methods: { @@ -504,20 +505,24 @@ export default { const queryParams = new URLSearchParams(window.location.search) if (queryParams.has('t')) { - fetch(this.baseUrl + '/api/submitter_email_clicks', { + const t = queryParams.get('t') + + queryParams.delete('t') + const newUrl = [window.location.pathname, queryParams.toString()].filter(Boolean).join('?') + window.history.replaceState({}, document.title, newUrl) + + return fetch(this.baseUrl + '/api/submitter_email_clicks', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - t: queryParams.get('t'), + t, submitter_slug: this.submitterSlug }) }) - - queryParams.delete('t') - const newUrl = [window.location.pathname, queryParams.toString()].filter(Boolean).join('?') - window.history.replaceState({}, document.title, newUrl) + } else { + return Promise.resolve({}) } }, trackViewForm () {