Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ relevant section below for more details.
the browser will use the frontend node server to send API requests. Do not prepend `api/v1/` - it will be added
automatically.
- `GOOGLE_ANALYTICS_API_KEY`: Google Analytics key to track API usage.
- `PYLON_APP_ID`: Pylon in-app chat widget App ID.
- `FIRST_PROMOTER_ID`: First Promoter ID for checkout affiliates.
- `ALLOW_SIGNUPS`: **DEPRECATED** in favour of `PREVENT_SIGNUP` in the API. Determines whether to prevent manual signups
without invites. Set it to any value to allow signups.
Expand All @@ -99,7 +98,6 @@ relevant section below for more details.
- `REO_API_KEY`: The Reo key to use for behaviour tracking.
- `MIXPANEL_API_KEY`: Mixpanel analytics key to use for behaviour tracking.
- `SENTRY_API_KEY`: Sentry key for error reporting.
- `ALBACROSS_CLIENT_ID`: Albacross client ID key for behaviour tracking.
- `BASE_URL`: Used for specifying a base URL path that's ignored during routing if serving from a subdirectory.
- `USE_SECURE_COOKIES`: Enable/disable the use of secure cookies. If deploying the frontend in a private network without
a domain/SSL cert, disable secure cookies to ensure that session token is persisted. Default: true.
Expand Down
1 change: 0 additions & 1 deletion frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ module.exports = {
'__DEV__': true,
'closeModal': true,
'closeModal2': true,
'delighted': true,
'describe': true,
'em': true,
'flagsmith': true,
Expand Down
3 changes: 0 additions & 3 deletions frontend/api/dev-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = function setupRoutes(app) {
{ name: 'headway', value: process.env.HEADWAY_API_KEY },
{ name: 'ga', value: process.env.GOOGLE_ANALYTICS_API_KEY },
{ name: 'sha', value: sha },
{ name: 'pylonAppId', value: process.env.PYLON_APP_ID },
{ name: 'fpr', value: process.env.FIRST_PROMOTER_ID },
{ name: 'sentry', value: process.env.SENTRY_API_KEY },
{ name: 'api', value: process.env.FLAGSMITH_PROXY_API_URL ? '/api/v1/' : process.env.FLAGSMITH_API_URL },
Expand All @@ -45,11 +44,9 @@ module.exports = function setupRoutes(app) {
{ name: 'flagsmithRealtime', value: envToBool('ENABLE_FLAGSMITH_REALTIME', false) },
{ name: 'amplitude', value: process.env.AMPLITUDE_API_KEY },
{ name: 'reo', value: process.env.REO_API_KEY },
{ name: 'delighted', value: process.env.DELIGHTED_API_KEY },
{ name: 'capterraKey', value: process.env.CAPTERRA_API_KEY },
{ name: 'hideInviteLinks', value: envToBool('DISABLE_INVITE_LINKS', false) },
{ name: 'linkedinPartnerTracking', value: envToBool('LINKEDIN_PARTNER_TRACKING', false) },
{ name: 'albacross', value: process.env.ALBACROSS_CLIENT_ID },
{ name: 'useSecureCookies', value: envToBool('USE_SECURE_COOKIES', true) },
{ name: 'cookieSameSite', value: process.env.USE_SECURE_COOKIES },
{ name: 'cookieAuthEnabled', value: process.env.COOKIE_AUTH_ENABLED },
Expand Down
3 changes: 0 additions & 3 deletions frontend/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ app.get('/config/project-overrides', (req, res) => {
{ name: 'headway', value: process.env.HEADWAY_API_KEY },
{ name: 'ga', value: process.env.GOOGLE_ANALYTICS_API_KEY },
{ name: 'sha', value: sha },
{ name: 'pylonAppId', value: process.env.PYLON_APP_ID },
{ name: 'fpr', value: process.env.FIRST_PROMOTER_ID },
{ name: 'sentry', value: process.env.SENTRY_API_KEY },
{
Expand Down Expand Up @@ -101,7 +100,6 @@ app.get('/config/project-overrides', (req, res) => {
},
{ name: 'amplitude', value: process.env.AMPLITUDE_API_KEY },
{ name: 'reo', value: process.env.REO_API_KEY },
{ name: 'delighted', value: process.env.DELIGHTED_API_KEY },
{ name: 'capterraKey', value: process.env.CAPTERRA_API_KEY },
{
name: 'hideInviteLinks',
Expand All @@ -111,7 +109,6 @@ app.get('/config/project-overrides', (req, res) => {
name: 'linkedinPartnerTracking',
value: envToBool('LINKEDIN_PARTNER_TRACKING', false),
},
{ name: 'albacross', value: process.env.ALBACROSS_CLIENT_ID },
{ name: 'useSecureCookies', value: envToBool('USE_SECURE_COOKIES', true) },
{ name: 'cookieSameSite', value: process.env.USE_SECURE_COOKIES },
{ name: 'cookieAuthEnabled', value: process.env.COOKIE_AUTH_ENABLED },
Expand Down
35 changes: 4 additions & 31 deletions frontend/common/__tests__/loadChat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,17 @@ beforeEach(() => {
})

describe('getChatProvider', () => {
it('returns hubspot when only hubspot_chat is on', () => {
it('returns hubspot when hubspot_chat is on', () => {
// Given
setFlags(['hubspot_chat'])

// When / Then
expect(getChatProvider()).toBe('hubspot')
})

it('prefers hubspot while both flags are on', () => {
// Given
setFlags(['hubspot_chat', 'pylon_chat'])

// When / Then
expect(getChatProvider()).toBe('hubspot')
})

it('returns pylon when only pylon_chat is on', () => {
// Given
setFlags(['pylon_chat'])

// When / Then
expect(getChatProvider()).toBe('pylon')
})

it('keeps HubSpot to paid plans when hubspot_chat has no value', () => {
// Given
setFlags(['hubspot_chat', 'pylon_chat'])
setFlags(['hubspot_chat'])
mockUtils.isOrgOnFreePlan.mockReturnValue(true)

// When / Then
Expand All @@ -128,15 +112,6 @@ describe('getChatProvider', () => {
// When / Then
expect(getChatProvider()).toBe('hubspot')
})

it('keeps Pylon to paid plans', () => {
// Given
setFlags(['pylon_chat'])
mockUtils.isOrgOnFreePlan.mockReturnValue(true)

// When / Then
expect(getChatProvider()).toBeNull()
})
})

describe('openChat', () => {
Expand Down Expand Up @@ -192,19 +167,17 @@ describe('openChat', () => {
})

describe('identifyChatUser', () => {
it('hides Pylon and loads HubSpot when hubspot_chat is on', async () => {
it('loads HubSpot when hubspot_chat is on', async () => {
// Given
setFlags(['hubspot_chat', 'pylon_chat'])
setFlags(['hubspot_chat'])
const widget = hubSpotWidget(false)
window.HubSpotConversations = { widget }
window.Pylon = jest.fn()

// When
identifyChatUser()
await flushPromises()

// Then
expect(window.Pylon).toHaveBeenCalledWith('hideChatBubble')
expect(widget.load).toHaveBeenCalledWith({ widgetOpen: false })
})

Expand Down
91 changes: 2 additions & 89 deletions frontend/common/loadChat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
declare global {
interface Window {
Pylon?: ((...args: unknown[]) => void) & { q?: unknown[][] }
pylon?: { chat_settings: Record<string, string | undefined> }
hsConversationsSettings?: {
loadImmediately?: boolean
identificationEmail?: string
Expand All @@ -22,22 +20,17 @@ declare global {
import AccountStore from './stores/account-store'
import { getStore } from './store'
import { getHubspotChatToken } from './services/useHubspotChatToken'
import getUserDisplayName from './utils/getUserDisplayName'
import Utils from './utils/utils'
import { AccountModel, HubspotChatToken } from './types/responses'
import Project from './project'

const defaultPylonID = '028babb7-d93f-4e32-be6a-59db190a084f'
const SUPPORT_EMAIL_URL = 'mailto:support@flagsmith.com'

export type ChatProvider = 'hubspot' | 'pylon'
export type ChatProvider = 'hubspot'

// hubspot_chat's value sets who gets HubSpot chat: "all" opens it to every
// plan, anything else (including no value) keeps it to paid plans.
const HUBSPOT_CHAT_ALL_PLANS = 'all'

// HubSpot wins while both flags are on, so turning hubspot_chat on is enough
// to switch provider.
export function getChatProvider(): ChatProvider | null {
const isFreePlan = Utils.isOrgOnFreePlan()
if (Utils.getFlagsmithHasFeature('hubspot_chat')) {
Expand All @@ -46,59 +39,9 @@ export function getChatProvider(): ChatProvider | null {
.toLowerCase()
return audience === HUBSPOT_CHAT_ALL_PLANS || !isFreePlan ? 'hubspot' : null
}
if (Utils.getFlagsmithHasFeature('pylon_chat') && !isFreePlan) return 'pylon'
return null
}

async function loadPylon(pylonAppId: string) {
if (window.Pylon) {
return
}

await new Promise((resolve, reject) => {
const t = document
const n: ((...args: unknown[]) => void) & { q?: unknown[][] } =
Object.assign((...args: unknown[]) => n.q!.push(args), { q: [] })
window.Pylon = n

const s = t.createElement('script')
s.setAttribute('type', 'text/javascript')
s.setAttribute('async', 'true')
s.setAttribute('src', `https://widget.usepylon.com/widget/${pylonAppId}`)
s.onload = () => resolve(undefined)
s.onerror = reject
const firstScript = t.getElementsByTagName('script')[0]
firstScript.parentNode?.insertBefore(s, firstScript)
})
}

function setupPylon() {
const user = AccountStore.getUser() as AccountModel
if (typeof window.Pylon === 'undefined' || !user) {
return
}

try {
window.pylon = {
chat_settings: {
account_id: String(user.id),
app_id: Project.pylonAppId || defaultPylonID,
email: user.email,
email_hash: user.pylon_email_signature,
name: getUserDisplayName(user),
},
}
} catch (error) {
console.error('Error setting up Pylon:', error)
}
}

function hidePylon() {
if (typeof window.Pylon !== 'undefined') {
window.Pylon('hideChatBubble')
}
}

let isLoadingHubSpot = false
let openHubSpotOnLoad = false
// load() was called. status().loaded stays false until HubSpot's iframe is
Expand Down Expand Up @@ -203,21 +146,12 @@ function removeHubSpot() {
}

export function hideChat() {
hidePylon()
removeHubSpot()
}

export function identifyChatUser() {
const provider = getChatProvider()
if (provider === 'hubspot') {
hidePylon()
if (getChatProvider() === 'hubspot') {
showHubSpot()
} else if (provider === 'pylon') {
removeHubSpot()
setupPylon()
if (typeof window.Pylon !== 'undefined') {
window.Pylon('showChatBubble')
}
} else {
hideChat()
}
Expand All @@ -235,27 +169,6 @@ export function openChat() {
}
return
}
if (provider === 'pylon' && typeof window.Pylon !== 'undefined') {
window.Pylon('show')
setupPylon()
return
}
// No chat for this org, or the widget was blocked: email beats a dead click.
window.location.href = SUPPORT_EMAIL_URL
}

export default async function loadChat(forceDefaultAPIKey?: boolean) {
try {
const isWidget = document.location.href.includes('/widget')
if (isWidget) return

if (getChatProvider() === 'pylon') {
const pylonId = forceDefaultAPIKey ? defaultPylonID : Project.pylonAppId
if (pylonId) {
await loadPylon(pylonId)
}
}
} catch (error) {
console.error('Failed to initialize chat widget:', error)
}
}
13 changes: 0 additions & 13 deletions frontend/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ declare global {
command: 'send',
fields: UniversalAnalytics.PageviewFieldsObject,
): void
const delighted: {
survey: (opts: {
createdAt: string
email: string
name: string
properties: Record<string, any>
}) => void
}
const openModal: (
title: ReactNode,
body?: ReactNode,
Expand Down Expand Up @@ -92,11 +84,6 @@ declare global {

interface Window {
E2E: boolean
engagement: {
init(apiKey: string, options?: InitOptions): void
plugin(): unknown
boot(options: BootOptions): Promise<void>
}
}
}

Expand Down
16 changes: 0 additions & 16 deletions frontend/package-lock.json

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

1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
},
"dependencies": {
"@amplitude/analytics-browser": "^2.11.3",
"@amplitude/engagement-browser": "^0.0.5",
"@amplitude/plugin-session-replay-browser": "^1.6.24",
"@babel/core": "7.29.6",
"@babel/plugin-proposal-class-properties": "^7.12.1",
Expand Down
2 changes: 0 additions & 2 deletions frontend/web/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import get from 'lodash/get'
import find from 'lodash/find'
import { matchPath, withRouter } from 'react-router-dom'
import * as amplitude from '@amplitude/analytics-browser'
import { plugin as engagementPlugin } from '@amplitude/engagement-browser'
import { sessionReplayPlugin } from '@amplitude/plugin-session-replay-browser'
import TwoFactorPrompt from './SimpleTwoFactor/prompt'
import Maintenance from './Maintenance'
Expand Down Expand Up @@ -88,7 +87,6 @@ const App = class extends Component {
defaultTracking: true,
serverZone: 'EU',
})
amplitude.add(engagementPlugin())
const sessionReplayTracking = sessionReplayPlugin({
sampleRate: 0.5,
serverZone: 'EU',
Expand Down
5 changes: 2 additions & 3 deletions frontend/web/components/pages/GettingStartedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, useEffect, useState } from 'react'
import PageTitle from 'components/PageTitle'
import Button from 'components/base/forms/Button'
import loadChat, { openChat } from 'common/loadChat'
import { openChat } from 'common/loadChat'
import Utils from 'common/utils/utils'
import ConfigProvider from 'common/providers/ConfigProvider'
import Icon from 'components/icons/Icon'
Expand All @@ -27,8 +27,7 @@ const GettingStartedPage: FC = () => {
document.body.classList.remove('full-screen')
}
}, [])
async function onChatClick() {
await loadChat(true)
function onChatClick() {
openChat()
}

Expand Down
Loading
Loading