-
-
-
- You need a subscription to access your form
- analytics.
-
-
-
- Subscribe
-
-
-
-
-

+
+
+
+ Views & Submission History
+
+
+
+
+
+
+
+
+ You need a subscription to access your form
+ analytics.
+
+
+
+ Subscribe
+
+
+
+
+

+
+
+
-
-
@@ -55,7 +70,6 @@ import {
CategoryScale,
PointElement,
} from "chart.js"
-import ProTag from "~/components/global/ProTag.vue"
ChartJS.register(
Title,
@@ -69,10 +83,7 @@ ChartJS.register(
export default {
name: "FormStats",
- components: {
- ProTag,
- LineChart,
- },
+ components: { LineChart },
props: {
form: {
type: Object,
@@ -81,8 +92,12 @@ export default {
},
setup() {
const subscriptionModalStore = useSubscriptionModalStore()
+ const filterForm = useForm({
+ filter_date: null,
+ })
return {
- subscriptionModalStore
+ subscriptionModalStore,
+ filterForm
}
},
data() {
@@ -119,8 +134,23 @@ export default {
},
}
},
+ watch: {
+ filterForm: {
+ deep: true,
+ handler(newVal) {
+ if(newVal.filter_date && Array.isArray(newVal.filter_date) && newVal.filter_date[0] && newVal.filter_date[1]) {
+ this.getChartData()
+ }
+ }
+ }
+ },
mounted() {
- this.getChartData()
+ if (this.form.is_pro) {
+ const toDate = new Date()
+ const fromDate = new Date(toDate)
+ fromDate.setDate(toDate.getDate() - 29)
+ this.filterForm.filter_date = [fromDate.toISOString().split('T')[0], toDate.toISOString().split('T')[0]]
+ }
},
methods: {
getChartData() {
@@ -131,6 +161,12 @@ export default {
this.form.workspace_id +
"/form-stats/" +
this.form.id,
+ {
+ params: {
+ date_from: this.filterForm.filter_date[0] ? this.filterForm.filter_date[0].split('T')[0] : null,
+ date_to: this.filterForm.filter_date[1] ? this.filterForm.filter_date[1].split('T')[0] : null,
+ }
+ }
).then((statsData) => {
if (statsData && statsData.views !== undefined) {
this.chartData.labels = Object.keys(statsData.views)
@@ -138,6 +174,9 @@ export default {
this.chartData.datasets[1].data = statsData.submissions
this.isLoading = false
}
+ }).catch((error) => {
+ this.isLoading = false
+ useAlert().error(error.data.message)
})
},
},
diff --git a/client/composables/forms/pendingSubmission.js b/client/composables/forms/pendingSubmission.js
index 033dac25..0a7ffc95 100644
--- a/client/composables/forms/pendingSubmission.js
+++ b/client/composables/forms/pendingSubmission.js
@@ -7,6 +7,9 @@ export const pendingSubmission = (form) => {
? form.form_pending_submission_key + "-" + hash(window.location.href)
: ""
})
+ const formPendingSubmissionTimerKey = computed(() => {
+ return formPendingSubmissionKey.value + "-timer"
+ })
const enabled = computed(() => {
return form?.auto_save ?? false
@@ -28,10 +31,27 @@ export const pendingSubmission = (form) => {
return pendingSubmission ? JSON.parse(pendingSubmission) : defaultValue
}
+ const setTimer = (value) => {
+ if (import.meta.server) return
+ useStorage(formPendingSubmissionTimerKey.value).value = value
+ }
+
+ const removeTimer = () => {
+ return setTimer(null)
+ }
+
+ const getTimer = (defaultValue = null) => {
+ if (import.meta.server) return
+ return useStorage(formPendingSubmissionTimerKey.value).value ?? defaultValue
+ }
+
return {
enabled,
set,
get,
remove,
+ setTimer,
+ removeTimer,
+ getTimer,
}
}
diff --git a/client/pages/forms/[slug]/show/stats.vue b/client/pages/forms/[slug]/show/stats.vue
index 800bc43d..b853b3f5 100644
--- a/client/pages/forms/[slug]/show/stats.vue
+++ b/client/pages/forms/[slug]/show/stats.vue
@@ -1,8 +1,39 @@
-
- Form Analytics (last 30 days)
-
+
+
+
+ {{ stat.label }}
+
+
+
+
+ {{ stat.value }}
+
+
+ {{ stat.placeholder }}
+
+
+
+
@@ -20,4 +51,33 @@ definePageMeta({
useOpnSeoMeta({
title: props.form ? "Form Analytics - " + props.form.title : "Form Analytics",
})
+
+const isLoading = ref(false)
+const totalViews = ref(0)
+const totalSubmissions = ref(0)
+const completionRate = ref(0)
+const averageDuration = ref('-')
+
+onMounted(() => {
+ getCardData()
+})
+
+const getCardData = async() => {
+ if (!props.form || !props.form.is_pro) { return null }
+ isLoading.value = true
+ opnFetch(
+ "/open/workspaces/" +
+ props.form.workspace_id +
+ "/form-stats-details/" +
+ props.form.id,
+ ).then((responseData) => {
+ if (responseData) {
+ totalViews.value = responseData.views ?? 0
+ totalSubmissions.value = responseData.submissions ?? 0
+ completionRate.value = Math.min(100,responseData.completion_rate ?? 0)
+ averageDuration.value = responseData.average_duration ?? '-'
+ isLoading.value = false
+ }
+ })
+}