mirror of https://github.com/Budibase/budibase.git
9 changed files with 866 additions and 19 deletions
@ -0,0 +1,10 @@ |
|||||
|
import API from "./api" |
||||
|
|
||||
|
/** |
||||
|
* Notifies that an end user client app has been loaded. |
||||
|
*/ |
||||
|
export const pingEndUser = async () => { |
||||
|
return await API.post({ |
||||
|
url: `/api/analytics/ping`, |
||||
|
}) |
||||
|
} |
||||
@ -1,7 +1,27 @@ |
|||||
const env = require("../../environment") |
const env = require("../../environment") |
||||
|
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 function (ctx) { |
exports.isEnabled = async function (ctx) { |
||||
ctx.body = { |
ctx.body = { |
||||
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true", |
enabled: !env.SELF_HOSTED && env.ENABLE_ANALYTICS === "true", |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
|
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 |
||||
|
} |
||||
|
} |
||||
|
|||||
File diff suppressed because it is too large
Loading…
Reference in new issue