feat: posthog initialization

This commit is contained in:
Jannat Patel
2024-08-07 11:31:58 +05:30
parent 9a0056b6ca
commit a9e93a679b
7 changed files with 114 additions and 40 deletions

View File

@@ -6,6 +6,7 @@ import App from './App.vue'
import { createPinia } from 'pinia'
import dayjs from '@/utils/dayjs'
import translationPlugin from './translation'
import posthog from './posthog'
import { usersStore } from './stores/user'
import { sessionStore } from './stores/session'
import { initSocket } from './socket'
@@ -25,6 +26,7 @@ app.use(FrappeUI)
app.use(pinia)
app.use(router)
app.use(translationPlugin)
app.use(posthog)
app.use(pageMetaPlugin)
app.provide('$dayjs', dayjs)
app.provide('$socket', initSocket())

24
frontend/src/posthog.js Normal file
View File

@@ -0,0 +1,24 @@
import posthog from "posthog-js";
import { createResource } from 'frappe-ui'
const apiInfo = createResource({
url: 'lms.lms.api.get_posthog_api_key',
cache: 'apiInfo',
auto: true,
onSuccess(data) {
return data
},
})
export default {
install(app) {
app.config.globalProperties.$posthog = posthog.init(apiInfo.data.project_id, {
api_host: apiInfo.data.posthog_host,
autocapture: false,
capture_pageview: false,
capture_pageleave: false,
advanced_disable_decide: apiInfo.data.should_record_session,
});
},
};