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