forked from launchdarkly/LaunchDarkly-Docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-browser.ts
54 lines (43 loc) · 1.58 KB
/
gatsby-browser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import aa from 'search-insights'
import { TrackJS } from 'trackjs'
import { initDataDogLogging } from './src/utils/browserMetricsUtils'
import { addRemoveSiteParam, getSiteFromHref } from './src/utils/siteAwareUtils'
import { initUAParser } from './src/utils/userAgent'
export const onClientEntry = () => {
const activeEnv = process.env.GATSBY_ACTIVE_ENV
if (typeof activeEnv === 'undefined') {
return
}
const isProd = activeEnv === 'production'
const isStaging = activeEnv === 'staging'
const isDev = activeEnv === 'development'
const siteLocalStorage = localStorage.getItem('site')
// HACK: this is a migration step for old ls values that shouldn't
// be an issue on prod and can be removed over time.
if (siteLocalStorage === '"launchdarkly"') {
localStorage.removeItem('site')
}
if (isProd || (isDev && process.env.RUN_DATADOG_LOCALLY === 'true')) {
initDataDogLogging()
}
if (isProd || isStaging) {
TrackJS.install({
token: process.env.GATSBY_TRACKJS_TOKEN,
application: isProd ? 'docs-production' : 'docs-staging',
})
}
if (isStaging) {
TrackJS.configure({ version: process.env.PR_NUMBER })
}
initUAParser()
// Algolia search insights
window.aa = aa
const appId = process.env.GATSBY_ALGOLIA_APP_ID
const apiKey = process.env.GATSBY_ALGOLIA_SEARCH_KEY
aa('init', { appId, apiKey, useCookie: true })
const currentSiteHref = getSiteFromHref()
if (siteLocalStorage === '"federal"' && currentSiteHref !== 'federal') {
const to = addRemoveSiteParam(currentSiteHref, 'federal', true)
location.replace(to)
}
}