diff --git a/frontend/packages/launcher-app/src/app/launcher-app.tsx b/frontend/packages/launcher-app/src/app/launcher-app.tsx index ad91bfacf..7e1fb91e0 100755 --- a/frontend/packages/launcher-app/src/app/launcher-app.tsx +++ b/frontend/packages/launcher-app/src/app/launcher-app.tsx @@ -1,11 +1,11 @@ import '@patternfly/react-core/dist/styles/base.css'; -import React, { useContext } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { Redirect, Route, Switch } from 'react-router'; import { BrowserRouter } from 'react-router-dom'; import { AuthenticationApiContext, useAuthenticationApiStateProxy } from '../auth/auth-context'; import { newAuthApi } from '../auth/authentication-api-factory'; import { createRouterLink, getRequestedRoute, useRouter } from '../router/use-router'; -import { authConfig, authMode, creatorApiUrl, launcherApiUrl, publicUrl } from './config'; +import { authConfig, authMode, creatorApiUrl, launcherApiUrl, publicUrl, trackerToken } from './config'; import './launcher-app.scss'; import { Layout } from './layout'; import { LoginPage } from './login-page'; @@ -13,10 +13,9 @@ import { LauncherMenu } from '../launcher/launcher'; import { CreateNewAppFlow } from '../flows/create-new-app-flow'; import { ImportExistingFlow } from '../flows/import-existing-flow'; import { DeployExampleAppFlow } from '../flows/deploy-example-app-flow'; -import { DataLoader, AnalyticsContext } from '@launcher/component'; +import { DataLoader, AnalyticsContext, useAnalytics, Analytics, GoogleAnalytics } from '@launcher/component'; import { LauncherDepsProvider } from '../contexts/launcher-client-provider'; - function Routes(props: {}) { const analytics = useContext(AnalyticsContext); const router = useRouter(); @@ -76,6 +75,17 @@ function HomePage(props: {}) { const authApi = newAuthApi(authMode, authConfig); export function LauncherApp() { + const [analytics, setAnalytics] = useState(useAnalytics()); + + useEffect(() => { + setAnalytics((prev) => { + const newAnalytics = trackerToken ? new GoogleAnalytics(trackerToken) : prev; + newAnalytics.init(); + return newAnalytics; + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + const proxyAuthApi = useAuthenticationApiStateProxy(authApi); const authLoader = () => { return proxyAuthApi.init().catch(e => console.error(e)); @@ -83,13 +93,15 @@ export function LauncherApp() { return ( - - - + + + + + ); diff --git a/frontend/packages/launcher-app/src/launcher/launcher.tsx b/frontend/packages/launcher-app/src/launcher/launcher.tsx index 71bd39eea..bff86e8c6 100755 --- a/frontend/packages/launcher-app/src/launcher/launcher.tsx +++ b/frontend/packages/launcher-app/src/launcher/launcher.tsx @@ -1,13 +1,12 @@ +import React from 'react'; import { Card, CardBody, CardFooter, CardHeader, Grid, GridItem, Text, TextVariants } from '@patternfly/react-core'; -import React, { useContext } from 'react'; import { CreateNewAppFlow } from '../flows/create-new-app-flow'; import { DeployExampleAppFlow } from '../flows/deploy-example-app-flow'; import style from './launcher.module.scss'; import { ImportExistingFlow } from '../flows/import-existing-flow'; import { CatalogIcon, FileImportIcon, TopologyIcon } from '@patternfly/react-icons'; import { useSessionStorage } from 'react-use-sessionstorage'; -import { ButtonLink, useAnalytics, GoogleAnalytics, Analytics } from '@launcher/component'; -import { trackerToken } from '../app/config'; +import { ButtonLink } from '@launcher/component'; enum Type { NEW = 'NEW', EXAMPLE = 'EXAMPLE', IMPORT = 'IMPORT' @@ -25,15 +24,7 @@ export interface LauncherMenuProps { } export function LauncherMenu({createNewApp, createExampleApp, importExistingApp}: LauncherMenuProps) { - let analyticsImpl = useAnalytics(); - if (trackerToken) { - analyticsImpl = new GoogleAnalytics(trackerToken!); - } - const AnalyticsContext = React.createContext(analyticsImpl) - const analytics = useContext(AnalyticsContext); - return ( - Launcher @@ -75,7 +66,6 @@ export function LauncherMenu({createNewApp, createExampleApp, importExistingApp} - ); }