Skip to content

Commit

Permalink
chore: feature flag delighted (#3732)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Apr 10, 2024
1 parent f2302ee commit 80b6f07
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 26 deletions.
15 changes: 0 additions & 15 deletions frontend/common/stores/account-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,6 @@ const controller = {
}
}

if (Project.delighted) {
delighted.survey({
// customer name (optional)
createdAt: store.organisation && store.organisation.created_date,

email: store.model.email,
// customer email (optional)
name: `${store.model.first_name} ${store.model.last_name}`, // time subscribed (optional)
properties: {
// extra context (optional)
company: store.organisation && store.organisation.name,
},
})
}

AsyncStorage.setItem('user', JSON.stringify(store.model))
API.alias(user.email, user)
API.identify(user && user.email, user)
Expand Down
1 change: 1 addition & 0 deletions frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export type User = {
first_name: string
last_name: string
role: 'ADMIN' | 'USER'
date_joined: string
}
export type GroupUser = Omit<User, 'role'> & {
group_admin: boolean
Expand Down
117 changes: 117 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"file-loader": "6.2.0",
"flagsmith": "3.18.0",
"flux-react-dispatcher": "1.2.5",
"free-email-domains": "^1.2.13",
"fs-extra": "2.0.0",
"history": "4.10.1",
"html-loader": "1.3.2",
Expand Down
53 changes: 42 additions & 11 deletions frontend/web/project/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import amplitude from 'amplitude-js'
import data from 'common/data/base/_data'
const enableDynatrace = !!window.enableDynatrace && typeof dtrum !== 'undefined'

import freeEmailDomains from 'free-email-domains'
global.API = {
ajaxHandler(store, res) {
switch (res.status) {
Expand Down Expand Up @@ -82,8 +82,46 @@ global.API = {
const identify = new amplitude.Identify().set('email', id)
amplitude.getInstance().identify(identify)
}
flagsmith.identify(id)
flagsmith.setTrait('email', id)
API.flagsmithIdentify()
},
flagsmithIdentify() {
const user = AccountStore.model
if (!user) {
return
}

flagsmith
.identify(user.email, {
email: user.email,
organisations: user.organisations
? user.organisations.map((o) => `"${o.id}"`).join(',')
: '',
})
.then(() => {
return flagsmith.setTrait(
'logins',
(flagsmith.getTrait('logins') || 0) + 1,
)
})
.then(() => {
const organisation = AccountStore.getOrganisation()
const emailDomain = `${user?.email}`?.split('@')[1] || ''
const freeDomain = freeEmailDomains.includes(emailDomain)
if (
!freeDomain &&
typeof delighted !== 'undefined' &&
flagsmith.hasFeature('delighted')
) {
delighted.survey({
createdAt: user.date_joined || new Date().toISOString(),
email: user.email,
name: `${user.first_name || ''} ${user.last_name || ''}`, // time subscribed (optional)
properties: {
company: organisation?.name,
},
})
}
})
},
getCookie(key) {
const res = require('js-cookie').get(key)
Expand Down Expand Up @@ -177,14 +215,7 @@ global.API = {

amplitude.getInstance().identify(identify)
}
flagsmith.identify(id)
flagsmith.setTrait(
'organisations',
user.organisations
? user.organisations.map((o) => `"${o.id}"`).join(',')
: '',
)
flagsmith.setTrait('email', id)
API.flagsmithIdentify()
} catch (e) {
console.error('Error identifying', e)
}
Expand Down

0 comments on commit 80b6f07

Please sign in to comment.