Skip to content

Commit b97622a

Browse files
authored
Integrate posthog in frontend (#335)
1 parent 636c3dd commit b97622a

31 files changed

Lines changed: 485 additions & 126 deletions

frontend/package-lock.json

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"moment": "^2.29.4",
4646
"nprogress": "0.2.0",
4747
"pluralize": "^8.0.0",
48+
"posthog-js": "^1.36.1",
4849
"qs": "6.9.4",
4950
"regenerator-runtime": "^0.13.9",
5051
"remixicon": "^2.5.0",

frontend/scripts/docker-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ declare -a ENV_VARIABLES=(
1717
"VUE_APP_SEGMENT_KEY"
1818
"VUE_APP_HOTJAR_KEY"
1919
"VUE_APP_ENV"
20+
"VUE_APP_POSTHOG_API_KEY"
2021
)
2122

2223
for ENV_VAR in "${ENV_VARIABLES[@]}"

frontend/src/assets/scss/badge.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
.badge {
22
@apply bg-gray-200 text-gray-900 px-2.5 text-xs py-1 rounded-md;
33

4+
&--sm {
5+
@apply px-1.5 py-0.5;
6+
}
7+
8+
&--xs {
9+
@apply text-3xs py-0.5 px-1;
10+
}
11+
412
&--green {
513
@apply bg-green-100 text-green-900;
614
}
@@ -28,4 +36,8 @@
2836
&--yellow {
2937
@apply bg-yellow-100 text-yellow-900;
3038
}
39+
40+
&--light-yellow {
41+
@apply bg-yellow-50 text-yellow-600;
42+
}
3143
}

frontend/src/config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const defaultConfig = {
3131
edition: process.env.VUE_APP_EDITION,
3232
communityPremium: process.env.VUE_APP_COMMUNITY_PREMIUM,
3333
env: process.env.VUE_APP_ENV,
34-
hotjarKey: process.env.VUE_APP_HOTJAR_KEY
34+
hotjarKey: process.env.VUE_APP_HOTJAR_KEY,
35+
posthogKey: process.env.VUE_APP_POSTHOG_API_KEY
3536
}
3637

3738
const composedConfig = {
@@ -54,14 +55,17 @@ const composedConfig = {
5455
edition: 'CROWD_VUE_APP_EDITION',
5556
communityPremium: 'CROWD_VUE_APP_COMMUNITY_PREMIUM',
5657
env: 'CROWD_VUE_APP_ENV',
57-
hotjarKey: 'CROWD_VUE_APP_HOTJAR_KEY'
58+
hotjarKey: 'CROWD_VUE_APP_HOTJAR_KEY',
59+
posthogKey: 'CROWD_VUE_APP_POSTHOG_API_KEY'
5860
}
5961

6062
const config = defaultConfig.backendUrl
6163
? defaultConfig
6264
: composedConfig
6365

66+
config.isCommunityVersion = config.edition === 'community'
6467
config.hasPremiumModules =
65-
config.edition === 'crowd-hosted' ||
68+
!config.isCommunityVersion ||
6669
config.communityPremium === 'true'
70+
6771
export default config

frontend/src/integrations/integrations-config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import zapier from './zapier'
1212
import crunchbase from './crunchbase'
1313
import make from './make'
1414

15-
import config from '@/config'
16-
1715
class IntegrationsConfig {
1816
get integrations() {
1917
return {
@@ -22,14 +20,14 @@ class IntegrationsConfig {
2220
slack,
2321
twitter,
2422
devto,
25-
...(config.hasPremiumModules && { hackernews }),
23+
hackernews,
2624
discourse,
2725
stackoverflow,
2826
reddit,
2927
linkedin,
3028
zapier,
3129
crunchbase,
32-
...(!config.hasPremiumModules && { make })
30+
make
3331
}
3432
}
3533

frontend/src/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import LogRocket from 'logrocket'
2020
import App from '@/app.vue'
2121
import { vueSanitizeOptions } from '@/plugins/sanitize'
2222
import marked from '@/plugins/marked'
23+
import posthog from 'posthog-js'
2324

2425
i18nInit()
2526
/**
@@ -31,6 +32,15 @@ i18nInit()
3132
LogRocket.init('nm6fil/crowddev')
3233
}
3334

35+
// Initialize posthog for crowd hosted version
36+
if (!config.isCommunityVersion) {
37+
posthog.init(config.posthogKey, {
38+
autocapture: false,
39+
capture_pageview: false,
40+
persistence: 'cookie'
41+
})
42+
}
43+
3444
const app = createApp(App)
3545
const router = await createRouter()
3646
const store = await createStore(LogRocket)

frontend/src/modules/auth/auth-current-tenant.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { tenantSubdomain } from '@/modules/tenant/tenant-subdomain'
2+
import config from '@/config'
3+
import posthog from 'posthog-js'
24

35
/**
46
* Auth Current Tenant
@@ -108,6 +110,13 @@ export default class AuthCurrentTenant {
108110
return this.clear()
109111
}
110112

113+
// Set group in posthog with tenant id
114+
// Refresh feature flags each time tenant is set
115+
if (!config.isCommunityVersion) {
116+
posthog.group('tenant', tenant.id)
117+
posthog.reloadFeatureFlags()
118+
}
119+
111120
localStorage.setItem('tenant', JSON.stringify(tenant))
112121
}
113122

frontend/src/modules/automation/automation-store.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import config from '@/config'
12
import { AutomationService } from '@/modules/automation/automation-service'
23
import Errors from '@/shared/error/errors'
34
import Message from '@/shared/message/message'
5+
import posthog from 'posthog-js'
46

57
const INITIAL_PAGE_SIZE = 20
68

@@ -434,6 +436,12 @@ export default {
434436
)
435437

436438
commit('CREATE_SUCCESS', response)
439+
440+
// Make sure that feature flags are updated for automationsCount
441+
if (!config.isCommunityVersion) {
442+
posthog.reloadFeatureFlags()
443+
}
444+
437445
Message.success('Automation created successfully')
438446
} catch (error) {
439447
Errors.handle(error)
@@ -452,6 +460,11 @@ export default {
452460

453461
commit('DESTROY_SUCCESS', automationId)
454462

463+
// Make sure that feature flags are updated for automationsCount
464+
if (!config.isCommunityVersion) {
465+
posthog.reloadFeatureFlags()
466+
}
467+
455468
dispatch(
456469
`automation/doFetch`,
457470
rootGetters[`automation/filter`],
@@ -477,6 +490,11 @@ export default {
477490

478491
commit('DESTROY_ALL_SUCCESS', automationIds)
479492

493+
// Make sure that feature flags are updated for automationsCount
494+
if (!config.isCommunityVersion) {
495+
posthog.reloadFeatureFlags()
496+
}
497+
480498
dispatch(
481499
`automation/doFetch`,
482500
rootGetters[`automation/filter`],

frontend/src/modules/automation/components/list/automation-list-table.vue

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,10 @@ export default {
107107
computed: {
108108
...mapGetters({
109109
rows: 'automation/rows',
110-
count: 'automation/count',
111110
loading: 'automation/loading',
112-
pagination: 'automation/pagination',
113111
selectedRows: 'automation/selectedRows',
114-
isMobile: 'layout/isMobile',
115112
currentUser: 'auth/currentUser',
116-
currentTenant: 'auth/currentTenant',
117-
paginationLayout: 'layout/paginationLayout'
113+
currentTenant: 'auth/currentTenant'
118114
}),
119115
120116
hasPermissionToEdit() {
@@ -140,23 +136,10 @@ export default {
140136
},
141137
methods: {
142138
...mapActions({
143-
doChangeSort: 'conversation/doChangeSort',
144-
doChangePaginationCurrentPage:
145-
'conversation/doChangePaginationCurrentPage',
146-
doChangePaginationPageSize:
147-
'conversation/doChangePaginationPageSize',
148-
doMountTable: 'conversation/doMountTable',
149-
doDestroy: 'member/doDestroy'
139+
doChangeSort: 'automation/doChangeSort',
140+
doMountTable: 'automation/doMountTable'
150141
}),
151142
152-
doRefresh() {
153-
this.doChangePaginationCurrentPage()
154-
},
155-
156-
presenter(row, fieldName) {
157-
return AutomationModel.presenter(row, fieldName)
158-
},
159-
160143
translate(key) {
161144
return i18n(key)
162145
},

0 commit comments

Comments
 (0)