[go: nahoru, domu]

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

useAnalytics missing in ReactFire v4 #429 #431

Merged
merged 7 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add an example for Analytics
  • Loading branch information
shiiinji committed Aug 26, 2021
commit c971ab4fc34d1fec8bb5d044e3864af003493c2a
23 changes: 23 additions & 0 deletions example/withoutSuspense/Analytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react'
import { AnalyticsProvider, useFirebaseApp, useAnalytics } from 'reactfire';
import { getAnalytics, logEvent } from 'firebase/analytics'


function MyPageViewLogger() {
const analytics = useAnalytics()

React.useEffect(() => {
logEvent(analytics, 'page_view')
}, [location.pathname])
shiiinji marked this conversation as resolved.
Show resolved Hide resolved

return null
}

export function Analytics() {
const app = useFirebaseApp();
return (
<AnalyticsProvider sdk={getAnalytics(app)}>
<MyPageViewLogger />
</AnalyticsProvider>
);
}
2 changes: 2 additions & 0 deletions example/withoutSuspense/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { AuthProvider, useFirebaseApp, useInitPerformance } from 'reactfire';
import { Card } from '../display/Card';
import { Analytics } from './Analytics'
import { Auth } from './Auth';
import { Firestore } from './Firestore';
import { RealtimeDatabase } from './RealtimeDatabase';
Expand Down Expand Up @@ -39,6 +40,7 @@ export const App = () => {
<Storage />
</Card>
</AuthProvider>
<Analytics />
</div>
);
};