Feature/nps survey (#13423)

* get process env in JS file

* Hard-code posthog token

* Set posthog key based on env

* Don't run posthog locally in dev

* fix

* Only run posthog analytics in prod

* Don't use posthog in dev

* Revert posthog code changes.

* Remove intercom

* lint
This commit is contained in:
melohagan 2024-04-09 15:24:03 +01:00 committed by GitHub
parent 19fe037391
commit 923ae021a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1 additions and 131 deletions

View File

@ -1,95 +0,0 @@
export default class IntercomClient {
constructor(token) {
this.token = token
}
//
/**
* Instantiate intercom using their provided script.
*/
init() {
if (!this.token) return
const token = this.token
var w = window
var ic = w.Intercom
if (typeof ic === "function") {
ic("reattach_activator")
ic("update", w.intercomSettings)
} else {
var d = document
var i = function () {
i.c(arguments)
}
i.q = []
i.c = function (args) {
i.q.push(args)
}
w.Intercom = i
var l = function () {
var s = d.createElement("script")
s.type = "text/javascript"
s.async = true
s.src = "https://widget.intercom.io/widget/" + token
var x = d.getElementsByTagName("script")[0]
x.parentNode.insertBefore(s, x)
}
if (document.readyState === "complete") {
l()
} else if (w.attachEvent) {
w.attachEvent("onload", l)
} else {
w.addEventListener("load", l, false)
}
this.initialised = true
}
}
/**
* Show the intercom chat bubble.
* @param {Object} user - user to identify
* @returns Intercom global object
*/
show(user = {}, enabled) {
if (!this.initialised || !enabled) return
return window.Intercom("boot", {
app_id: this.token,
...user,
})
}
/**
* Update intercom user details and messages.
* @returns Intercom global object
*/
update() {
if (!this.initialised) return
return window.Intercom("update")
}
/**
* Capture analytics events and send them to intercom.
* @param {String} event - event identifier
* @param {Object} props - properties for the event
* @returns Intercom global object
*/
captureEvent(event, props = {}) {
if (!this.initialised) return
return window.Intercom("trackEvent", event, props)
}
/**
* Disassociate the user from the current session.
* @returns Intercom global object
*/
logout() {
if (!this.initialised) return
return window.Intercom("shutdown")
}
}

View File

@ -1,14 +1,12 @@
import { API } from "api"
import PosthogClient from "./PosthogClient"
import IntercomClient from "./IntercomClient"
import { Events, EventSource } from "./constants"
const posthog = new PosthogClient(process.env.POSTHOG_TOKEN)
const intercom = new IntercomClient(process.env.INTERCOM_TOKEN)
class AnalyticsHub {
constructor() {
this.clients = [posthog, intercom]
this.clients = [posthog]
this.initialised = false
}
@ -31,20 +29,10 @@ class AnalyticsHub {
captureEvent(eventName, props = {}) {
posthog.captureEvent(eventName, props)
intercom.captureEvent(eventName, props)
}
showChat(user) {
intercom.show(user)
}
initPosthog() {
posthog.init()
}
async logout() {
posthog.logout()
intercom.logout()
}
}

View File

@ -32,7 +32,6 @@
import TourWrap from "components/portal/onboarding/TourWrap.svelte"
import { TOUR_STEP_KEYS } from "components/portal/onboarding/tours.js"
import { goto } from "@roxi/routify"
import { onMount } from "svelte"
export let application
export let loaded
@ -151,10 +150,6 @@
notifications.error("Error refreshing app")
}
}
onMount(() => {
analytics.initPosthog()
})
</script>
<!-- svelte-ignore a11y-click-events-have-key-events -->

View File

@ -2,7 +2,6 @@ import { derived, writable, get } from "svelte/store"
import { API } from "api"
import { admin } from "stores/portal"
import analytics from "analytics"
import { sdk } from "@budibase/shared-core"
export function createAuthStore() {
const auth = writable({
@ -42,20 +41,6 @@ export function createAuthStore() {
.activate()
.then(() => {
analytics.identify(user._id)
analytics.showChat(
{
email: user.email,
created_at: (user.createdAt || Date.now()) / 1000,
name: user.account?.name,
user_id: user._id,
tenant: user.tenantId,
admin: sdk.users.isAdmin(user),
builder: sdk.users.isBuilder(user),
"Company size": user.account?.size,
"Job role": user.account?.profession,
},
!!user?.account
)
})
.catch(() => {
// This request may fail due to browser extensions blocking requests

View File

@ -77,9 +77,6 @@ export default defineConfig(({ mode }) => {
isProduction ? "production" : "development"
),
"process.env.POSTHOG_TOKEN": JSON.stringify(process.env.POSTHOG_TOKEN),
"process.env.INTERCOM_TOKEN": JSON.stringify(
process.env.INTERCOM_TOKEN
),
}),
copyFonts("fonts"),
...(isProduction ? [] : devOnlyPlugins),