opnform-host-nginx/client/components/vendor/FeatureBase.vue

80 lines
1.9 KiB
Vue
Raw Normal View History

2024-03-22 09:53:42 +01:00
<template></template>
<script setup>
2024-03-12 12:43:17 +01:00
import {onMounted} from "vue";
const scriptLoaded = ref(false);
2024-03-22 09:53:42 +01:00
const authStore = useAuthStore()
const user = computed(() => authStore.user)
const isImpersonating = computed(() => authStore.isImpersonating)
2024-03-12 12:43:17 +01:00
const featureBaseOrganization = useRuntimeConfig().public.featureBaseOrganization;
const loadScript = () => {
if (scriptLoaded.value || !user.value || !featureBaseOrganization) return;
const script = document.createElement("script");
script.src = "https://do.featurebase.app/js/sdk.js";
script.id = "featurebase-sdk";
document.head.appendChild(script);
scriptLoaded.value = true;
};
const setupForUser = () => {
2024-03-22 09:53:42 +01:00
if (process.server || !user.value || !featureBaseOrganization ||isImpersonating.value) return
2024-03-12 12:43:17 +01:00
window.Featurebase(
"identify",
{
organization: featureBaseOrganization,
email: user.value.email,
name: user.value.name,
id: user.value.id.toString(),
profilePicture: user.value.photo_url
}
);
window.Featurebase("initialize_changelog_widget", {
organization: featureBaseOrganization,
placement: "right",
theme: "light",
alwaysShow: true,
fullscreenPopup: true,
usersName: user.value?.name
})
window.Featurebase("initialize_feedback_widget", {
organization: featureBaseOrganization,
theme: "light",
placement: "right",
email: user.value?.email,
usersName: user.value?.name
});
}
onMounted(() => {
if (process.server) return
// Setup base
if (!window.hasOwnProperty('Featurebase') || typeof window.Featurebase !== "function") {
window.Featurebase = function () {
(window.Featurebase.q = window.Featurebase.q || []).push(arguments);
};
}
if (!user.value) return
loadScript()
setupForUser()
})
watch(user, (val) => {
if (process.server || !val) return
loadScript()
setupForUser()
});
</script>
2024-03-22 09:53:42 +01:00
<style>
.fb-feedback-widget-feedback-button {
z-index: 20 !important;
}
</style>