Skip to content

Commit

Permalink
chore: remove HappyKit & A/B testing code (#2545)
Browse files Browse the repository at this point in the history
  • Loading branch information
heatlikeheatwave committed Aug 15, 2024
1 parent b86ecff commit c12d24b
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 218 deletions.
2 changes: 0 additions & 2 deletions analytics/spec/events/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@
- $ref: ./video_played.yaml
- $ref: ./product_downloaded.yaml
- $ref: ./error_page_loaded.yaml
- $ref: ./ab_test_result.yaml
- $ref: ./ab_test_served.yaml
23 changes: 0 additions & 23 deletions analytics/spec/events/ab_test_result.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions analytics/spec/events/ab_test_served.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const withHashicorp = require('@hashicorp/platform-nextjs-plugin')
const { redirectsConfig } = require('./build-libs/redirects')
const HashiConfigPlugin = require('./config/plugin')

// Set api key for Happy Kit feature flags
const happyKitKey = process.env.NEXT_PUBLIC_FLAGS_ENV_KEY
? process.env.NEXT_PUBLIC_FLAGS_ENV_KEY
: 'flags_pub_development_343442393171755603'

/**
* @type {import('next/dist/lib/load-custom-routes').Header}
*
Expand Down Expand Up @@ -88,7 +83,6 @@ module.exports = withHashicorp({
MKTG_CONTENT_API: process.env.MKTG_CONTENT_API,
// TODO: determine if DevDot needs this or not
SEGMENT_WRITE_KEY: process.env.SEGMENT_WRITE_KEY,
HAPPY_KIT_KEY: happyKitKey,
},
svgo: {
plugins: [
Expand Down
24 changes: 0 additions & 24 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"dependencies": {
"@actions/core": "^1.9.1",
"@apidevtools/json-schema-ref-parser": "^9.0.9",
"@happykit/flags": "^3.1.1",
"@hashicorp/design-system-tokens": "^2.1.0",
"@hashicorp/flight-icons": "^3.5.0",
"@hashicorp/localstorage-polyfill": "^1.0.14",
Expand Down
16 changes: 0 additions & 16 deletions src/flags/client.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/flags/config.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/flags/edge.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/flags/server.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/lib/ab-test-track.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import redirects from 'data/_redirects.generated.json'
import variantRewrites from '.generated/tutorial-variant-map.json'
import setGeoCookie from '@hashicorp/platform-edge-utils/lib/set-geo-cookie'
import { HOSTNAME_MAP } from 'constants/hostname-map'
import { getEdgeFlags } from 'flags/edge'
import { getVariantParam } from 'views/tutorial-view/utils/variants'

function determineProductSlug(req: NextRequest): string {
Expand All @@ -22,24 +21,12 @@ function determineProductSlug(req: NextRequest): string {
return '*'
}

function setHappyKitCookie(
cookie: { args: Parameters<NextResponse['cookies']['set']> },
response: NextResponse
): NextResponse {
if (cookie) {
response.cookies.set(...cookie.args)
}
return response
}

/**
* Root-level middleware that will process all middleware-capable requests.
* Currently used to support:
* - Handling simple one-to-one redirects for .io routes
*/
export async function middleware(req: NextRequest, ev: NextFetchEvent) {
const { geo } = req

// UA checks to prevent misuse
const { ua } = userAgent(req)
if (/(bytespider|bytedance)/i.test(ua)) {
Expand Down Expand Up @@ -90,22 +77,6 @@ export async function middleware(req: NextRequest, ev: NextFetchEvent) {
return NextResponse.redirect(url, permanent ? 308 : 307)
}

/**
* We are running A/B tests on a subset of routes, so we are limiting the call to resolve flags from HappyKit to only those routes. This limits the impact of any additional latency to the routes which need the data.
*/
// if (
// geo?.country === 'US' &&
// ['vault', 'consul'].includes(product) &&
// ['/'].includes(req.nextUrl.pathname)
// ) {
// try {
// const edgeFlags = await getEdgeFlags({ request: req })
// const { flags, cookie } = edgeFlags
// } catch {
// // Fallback to default URLs
// }
// }

// Check if this path is associated with a tutorial variant
if (variantRewrites[req.nextUrl.pathname]) {
// check for query param first
Expand Down
49 changes: 22 additions & 27 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { NextAdapter } from 'next-query-params'
import { QueryParamProvider } from 'use-query-params'
import type { AppProps } from 'next/app'
import { useFlags } from 'flags/client'
import { FlagBagProvider } from 'flags/client'
import { SpeedInsights } from '@vercel/speed-insights/next'

// HashiCorp imports
Expand Down Expand Up @@ -59,7 +57,6 @@ export default function App({
Component,
pageProps: { session, ...pageProps },
}: AppProps<{ session?: Session } & Record<string, any>>) {
const flagBag = useFlags()
useAnchorLinkAnalytics()
useEffect(() => makeDevAnalyticsLogger(), [])

Expand Down Expand Up @@ -87,30 +84,28 @@ export default function App({
<SSRProvider>
<QueryParamProvider adapter={NextAdapter}>
<ErrorBoundary FallbackComponent={DevDotClient}>
<FlagBagProvider value={flagBag}>
<SessionProvider session={session}>
<DeviceSizeProvider>
<CurrentProductProvider currentProduct={currentProduct}>
<CodeTabsProvider>
<HeadMetadata {...pageProps.metadata} />
<LazyMotion
features={() =>
import('lib/framer-motion-features').then(
(mod) => mod.default
)
}
strict={process.env.NODE_ENV === 'development'}
>
<Component {...pageProps} />
<Toaster />
<ReactQueryDevtools />
<SpeedInsights sampleRate={0.05} />
</LazyMotion>
</CodeTabsProvider>
</CurrentProductProvider>
</DeviceSizeProvider>
</SessionProvider>
</FlagBagProvider>
<SessionProvider session={session}>
<DeviceSizeProvider>
<CurrentProductProvider currentProduct={currentProduct}>
<CodeTabsProvider>
<HeadMetadata {...pageProps.metadata} />
<LazyMotion
features={() =>
import('lib/framer-motion-features').then(
(mod) => mod.default
)
}
strict={process.env.NODE_ENV === 'development'}
>
<Component {...pageProps} />
<Toaster />
<ReactQueryDevtools />
<SpeedInsights sampleRate={0.05} />
</LazyMotion>
</CodeTabsProvider>
</CurrentProductProvider>
</DeviceSizeProvider>
</SessionProvider>
</ErrorBoundary>
</QueryParamProvider>
</SSRProvider>
Expand Down

0 comments on commit c12d24b

Please sign in to comment.