Merge branch 'master' into remove-test-container-logs
This commit is contained in:
commit
ce5c849d44
|
@ -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")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +1,12 @@
|
||||||
import { API } from "api"
|
import { API } from "api"
|
||||||
import PosthogClient from "./PosthogClient"
|
import PosthogClient from "./PosthogClient"
|
||||||
import IntercomClient from "./IntercomClient"
|
|
||||||
import { Events, EventSource } from "./constants"
|
import { Events, EventSource } from "./constants"
|
||||||
|
|
||||||
const posthog = new PosthogClient(process.env.POSTHOG_TOKEN)
|
const posthog = new PosthogClient(process.env.POSTHOG_TOKEN)
|
||||||
const intercom = new IntercomClient(process.env.INTERCOM_TOKEN)
|
|
||||||
|
|
||||||
class AnalyticsHub {
|
class AnalyticsHub {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.clients = [posthog, intercom]
|
this.clients = [posthog]
|
||||||
this.initialised = false
|
this.initialised = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,20 +29,10 @@ class AnalyticsHub {
|
||||||
|
|
||||||
captureEvent(eventName, props = {}) {
|
captureEvent(eventName, props = {}) {
|
||||||
posthog.captureEvent(eventName, props)
|
posthog.captureEvent(eventName, props)
|
||||||
intercom.captureEvent(eventName, props)
|
|
||||||
}
|
|
||||||
|
|
||||||
showChat(user) {
|
|
||||||
intercom.show(user)
|
|
||||||
}
|
|
||||||
|
|
||||||
initPosthog() {
|
|
||||||
posthog.init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async logout() {
|
async logout() {
|
||||||
posthog.logout()
|
posthog.logout()
|
||||||
intercom.logout()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
import TourWrap from "components/portal/onboarding/TourWrap.svelte"
|
import TourWrap from "components/portal/onboarding/TourWrap.svelte"
|
||||||
import { TOUR_STEP_KEYS } from "components/portal/onboarding/tours.js"
|
import { TOUR_STEP_KEYS } from "components/portal/onboarding/tours.js"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import { onMount } from "svelte"
|
|
||||||
|
|
||||||
export let application
|
export let application
|
||||||
export let loaded
|
export let loaded
|
||||||
|
@ -151,10 +150,6 @@
|
||||||
notifications.error("Error refreshing app")
|
notifications.error("Error refreshing app")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
analytics.initPosthog()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { derived, writable, get } from "svelte/store"
|
||||||
import { API } from "api"
|
import { API } from "api"
|
||||||
import { admin } from "stores/portal"
|
import { admin } from "stores/portal"
|
||||||
import analytics from "analytics"
|
import analytics from "analytics"
|
||||||
import { sdk } from "@budibase/shared-core"
|
|
||||||
|
|
||||||
export function createAuthStore() {
|
export function createAuthStore() {
|
||||||
const auth = writable({
|
const auth = writable({
|
||||||
|
@ -42,20 +41,6 @@ export function createAuthStore() {
|
||||||
.activate()
|
.activate()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
analytics.identify(user._id)
|
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(() => {
|
.catch(() => {
|
||||||
// This request may fail due to browser extensions blocking requests
|
// This request may fail due to browser extensions blocking requests
|
||||||
|
|
|
@ -77,9 +77,6 @@ export default defineConfig(({ mode }) => {
|
||||||
isProduction ? "production" : "development"
|
isProduction ? "production" : "development"
|
||||||
),
|
),
|
||||||
"process.env.POSTHOG_TOKEN": JSON.stringify(process.env.POSTHOG_TOKEN),
|
"process.env.POSTHOG_TOKEN": JSON.stringify(process.env.POSTHOG_TOKEN),
|
||||||
"process.env.INTERCOM_TOKEN": JSON.stringify(
|
|
||||||
process.env.INTERCOM_TOKEN
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
copyFonts("fonts"),
|
copyFonts("fonts"),
|
||||||
...(isProduction ? [] : devOnlyPlugins),
|
...(isProduction ? [] : devOnlyPlugins),
|
||||||
|
|
Loading…
Reference in New Issue