Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📈 226 Instrument app with Google Analytics #354

Merged
merged 4 commits into from
Apr 26, 2022

Conversation

xoscar
Copy link
Collaborator

@xoscar xoscar commented Apr 26, 2022

This PR adds analytics to the FE application.

The architecture consists of a provider that spreads the analytics instance and the enabled flag and the main hook that can be extended by the components.

Changes

  • Adding Google analytics to the app.
  • Using hooks and providers.

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

@xoscar xoscar added this to the MVP milestone Apr 26, 2022
@xoscar xoscar self-assigned this Apr 26, 2022
@xoscar xoscar linked an issue Apr 26, 2022 that may be closed by this pull request
return <Router />;
return (
<TourProvider steps={[]}>
<AnalyticsProvider>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the analytics provider to the app


const value = useMemo(() => ({isEnabled, instance}), []);

return isInitialized ? <Context.Provider value={value}>{children}</Context.Provider> : <div />;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spreads the instance and the is enabled flag

event(action: A, label: string): void;
};

const useAnalytics = <A>(category: Categories = Categories.Home): TAnalyticsService<A> => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main hook for analytics

@@ -0,0 +1,23 @@
import useAnalytics, {Categories} from '../Analytics/useAnalytics';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom hooks for the assertion table analytics

<Tabs.TabPane
tab={
<span data-tour={GuidedTourService.getStep(GuidedTours.Trace, Steps.SpanDetail)}>
Span Detail
</span>
}
key="1"
key="span-detail"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this to match the name we are going to send to GA


import * as serviceWorker from './serviceWorker';
import {TEnv} from './types';

declare global {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding support for the Environment object form the window

@@ -6,8 +6,8 @@ const Router = (): JSX.Element => {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/test/:id" element={<Test />} />
<Route path="/" element={<Home path="home" />} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now uses the new HOC for tracking, the path is sent to GA

];
return uniqBy(
[
...spanFieldList,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing annoying react warning

import {ReactElement, useEffect, useState, createContext, useCallback, useMemo} from 'react';
import GA4React from 'ga-4-react';

const {analyticsEnabled = 'true', measurementId = 'G-ZP277L2M37'} = window.ENV || {};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking this with @mathnogueira might remove in a follow up commit

Copy link
Collaborator

@kdhamric kdhamric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do it!

@xoscar xoscar merged commit 0dfd462 into main Apr 26, 2022
@xoscar xoscar deleted the 226-instrument-app-with-google-analytics-draft branch April 26, 2022 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instrument app with Google Analytics - DRAFT
2 participants