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
5 changes: 5 additions & 0 deletions .changeset/nervous-shrimps-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@frigade/js': patch
---

Skip all Frigade API requests when `generateGuestId` is set to `false` and no `userId` has been provided. Previously the SDK would still send a `flowStates` request with an auto-generated guest ID on initialization, page navigation, and tab focus.
2 changes: 1 addition & 1 deletion packages/js-api/src/core/frigade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export class Frigade extends Fetchable {
frigadeGlobalState[globalStateKey].refreshStateFromAPI = async (
overrideFlowStateRaw?: FlowStates
) => {
if (this.config.__readOnly) {
if (this.config.__readOnly || this.isAnonymousWithGuestIdDisabled()) {
return
}

Expand Down
22 changes: 20 additions & 2 deletions packages/js-api/src/shared/fetchable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { generateGuestId, getEmptyResponse, getHeaders, gracefulFetch } from './utils'
import {
generateGuestId,
getEmptyResponse,
getHeaders,
gracefulFetch,
GUEST_PREFIX,
} from './utils'
import { DEFAULT_REFRESH_INTERVAL_IN_MS, FrigadeConfig } from '../core/types'
import { frigadeGlobalState, FrigadeGlobalState, getGlobalStateKey } from './state'

Expand All @@ -24,7 +30,7 @@ export class Fetchable {
* @ignore
*/
public async fetch(path: string, options?: Record<any, any>) {
if (this.config.__readOnly) {
if (this.config.__readOnly || this.isAnonymousWithGuestIdDisabled()) {
return getEmptyResponse()
}

Expand All @@ -39,6 +45,18 @@ export class Fetchable {
return `${this.config.apiUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}`
}

/**
* @ignore
* True when `generateGuestId` is explicitly disabled and no real userId has been provided,
* in which case no requests should be sent to the Frigade API.
*/
protected isAnonymousWithGuestIdDisabled(): boolean {
return (
this.config.generateGuestId === false &&
(!this.config.userId || this.config.userId.startsWith(GUEST_PREFIX))
)
}

/**
* @ignore
*/
Expand Down
Loading