1
0
Fork 0
mirror of synced 2024-06-01 18:20:18 +12:00

end user ping for client apps

This commit is contained in:
Martin McKeaveney 2021-09-30 15:03:57 +01:00
parent 722cf24e7e
commit b8fef9965d
9 changed files with 866 additions and 19 deletions

View file

@ -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`,
})
}

View file

@ -9,3 +9,4 @@ export * from "./routes"
export * from "./queries"
export * from "./app"
export * from "./automations"
export * from "./analytics"

View file

@ -40,6 +40,8 @@
dataLoaded = true
if ($builderStore.inBuilder) {
builderStore.actions.notifyLoaded()
} else {
builderStore.actions.pingEndUser()
}
})

View file

@ -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)

View file

@ -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",

View file

@ -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
}
}

View file

@ -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

View file

@ -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