1
0
Fork 0
mirror of synced 2024-07-02 13:01:09 +12:00
budibase/packages/server/src/api/controllers/analytics.js

33 lines
619 B
JavaScript
Raw Normal View History

const env = require("../../environment")
2021-10-01 03:03:57 +13:00
const PostHog = require("posthog-node")
let posthogClient
if (env.POSTHOG_TOKEN && env.ENABLE_ANALYTICS && !env.SELF_HOSTED) {
posthogClient = new PostHog(env.POSTHOG_TOKEN)
}
exports.isEnabled = async ctx => {
ctx.body = {
2021-09-22 07:39:56 +12:00
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true",
}
}
2021-10-01 03:03:57 +13:00
exports.endUserPing = async ctx => {
if (!posthogClient) {
ctx.body = {
ping: false,
}
return
}
2021-10-01 03:03:57 +13:00
posthogClient.capture("budibase:end_user_ping", {
2021-10-01 05:04:55 +13:00
userId: ctx.user && ctx.user._id,
2021-10-01 04:39:10 +13:00
appId: ctx.appId,
2021-10-01 03:03:57 +13:00
})
ctx.body = {
2021-10-01 04:39:10 +13:00
ping: true,
2021-10-01 03:03:57 +13:00
}
2021-10-01 04:39:10 +13:00
}