1
0
Fork 0
mirror of synced 2024-06-30 12:00:31 +12:00
budibase/packages/server/src/api/controllers/analytics.js

40 lines
755 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
2021-10-20 04:52:55 +13:00
posthogClient.identify({
distinctId: ctx.user && ctx.user._id,
properties: {},
})
2021-10-08 00:15:05 +13:00
posthogClient.capture({
event: "budibase:end_user_ping",
distinctId: ctx.user && ctx.user._id,
properties: {
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
}