Skip to content

Commit

Permalink
feat: add type and conditional siteName attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
harishv7 committed Aug 27, 2023
1 parent 3676e12 commit 95d97be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/routing/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useLoginContext } from "contexts/LoginContext"
import { getDecodedParams } from "utils/decoding"
import { getSiteNameAttributeFromPath } from "utils/growthbook"

import { GBAttributes } from "types/featureFlags"

// axios settings
axios.defaults.withCredentials = true

Expand All @@ -34,17 +36,23 @@ export const ProtectedRoute = ({
} = useLoginContext()
const growthbook = useGrowthBook()
const currPath = useLocation().pathname
const siteNameFromPath = getSiteNameAttributeFromPath(currPath)

useEffect(() => {
if (growthbook)
growthbook.setAttributes({
if (growthbook) {
const gbAttributes: GBAttributes = {
userId,
userType,
email,
displayedName,
contactNumber,
siteName: getSiteNameAttributeFromPath(currPath),
})
}
// add siteName if it exists
if (siteNameFromPath && siteNameFromPath !== "") {
gbAttributes.siteName = siteNameFromPath
}
growthbook.setAttributes(gbAttributes)
}
}, [userId, userType, email, displayedName, contactNumber, currPath])

if (isLoading) {
Expand Down
9 changes: 9 additions & 0 deletions src/types/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ export type FeatureFlag = {
key: string
type: FeatureFlagTypes
}

export type GBAttributes = {
userId: string
userType: string
email: string
displayedName: string
contactNumber: string
siteName?: string
}

0 comments on commit 95d97be

Please sign in to comment.