end user ping for client apps
This commit is contained in:
parent
8226859e07
commit
13a07a5e51
|
@ -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`,
|
||||
})
|
||||
}
|
|
@ -9,3 +9,4 @@ export * from "./routes"
|
|||
export * from "./queries"
|
||||
export * from "./app"
|
||||
export * from "./automations"
|
||||
export * from "./analytics"
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
dataLoaded = true
|
||||
if ($builderStore.inBuilder) {
|
||||
builderStore.actions.notifyLoaded()
|
||||
} else {
|
||||
builderStore.actions.pingEndUser()
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { writable, derived } from "svelte/store"
|
||||
import Manifest from "manifest.json"
|
||||
import { findComponentById, findComponentPathById } from "../utils/components"
|
||||
import analytics from "../api/analytics"
|
||||
|
||||
const dispatchEvent = (type, data = {}) => {
|
||||
window.dispatchEvent(
|
||||
|
@ -63,6 +64,9 @@ const createBuilderStore = () => {
|
|||
notifyLoaded: () => {
|
||||
dispatchEvent("preview-loaded")
|
||||
},
|
||||
pingEndUser: () => {
|
||||
analytics.pingEndUser()
|
||||
},
|
||||
setSelectedPath: path => {
|
||||
console.log("set to ")
|
||||
console.log(path)
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
"open": "7.3.0",
|
||||
"pg": "8.5.1",
|
||||
"pino-pretty": "4.0.0",
|
||||
"posthog-node": "^1.1.4",
|
||||
"pouchdb": "7.2.1",
|
||||
"pouchdb-adapter-memory": "^7.2.1",
|
||||
"pouchdb-all-dbs": "1.0.2",
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
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) {
|
||||
ctx.body = {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,6 @@ const controller = require("../controllers/analytics")
|
|||
const router = Router()
|
||||
|
||||
router.get("/api/analytics", controller.isEnabled)
|
||||
router.post("/api/analytics/ping", controller.endUserPing)
|
||||
|
||||
module.exports = router
|
||||
|
|
|
@ -52,6 +52,7 @@ module.exports = {
|
|||
AUTOMATION_BUCKET: process.env.AUTOMATION_BUCKET,
|
||||
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
|
||||
DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
|
||||
POSTHOG_TOKEN: process.env.POSTHOG_TOKEN,
|
||||
// old - to remove
|
||||
CLIENT_ID: process.env.CLIENT_ID,
|
||||
BUDIBASE_DIR: process.env.BUDIBASE_DIR,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue