2020-10-29 09:35:06 +13:00
|
|
|
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)
|
|
|
|
}
|
2020-10-29 09:35:06 +13:00
|
|
|
|
2021-05-03 19:31:09 +12:00
|
|
|
exports.isEnabled = async function (ctx) {
|
2021-03-11 00:47:39 +13:00
|
|
|
ctx.body = {
|
2021-09-22 07:39:56 +12:00
|
|
|
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true",
|
2021-03-11 00:47:39 +13:00
|
|
|
}
|
2020-09-30 04:23:34 +13:00
|
|
|
}
|
2021-10-01 03:03:57 +13:00
|
|
|
|
|
|
|
exports.endUserPing = async (ctx, next) => {
|
|
|
|
if (!posthogClient) return next()
|
|
|
|
|
|
|
|
posthogClient.capture("budibase:end_user_ping", {
|
|
|
|
userId: ctx.user?._id,
|
|
|
|
appId: ctx.appId
|
|
|
|
})
|
|
|
|
|
|
|
|
ctx.body = {
|
|
|
|
ping: true
|
|
|
|
}
|
|
|
|
}
|