Add analytics to the web build (close #233) (#385)

* Add analytics to the web build (close #233)

* Use bsky endpoint for analytics
zio/stable
Paul Frazee 2023-04-04 13:01:38 -05:00 committed by GitHub
parent b100abca0e
commit f717ff6719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1010 additions and 20 deletions

View File

@ -40,6 +40,8 @@
"@react-navigation/drawer": "^6.6.2", "@react-navigation/drawer": "^6.6.2",
"@react-navigation/native": "^6.1.6", "@react-navigation/native": "^6.1.6",
"@react-navigation/native-stack": "^6.9.12", "@react-navigation/native-stack": "^6.9.12",
"@segment/analytics-next": "^1.51.3",
"@segment/analytics-react": "^1.0.0-rc1",
"@segment/analytics-react-native": "^2.10.1", "@segment/analytics-react-native": "^2.10.1",
"@segment/sovran-react-native": "^0.4.5", "@segment/sovran-react-native": "^0.4.5",
"@tiptap/core": "^2.0.0-beta.220", "@tiptap/core": "^2.0.0-beta.220",

View File

@ -2,6 +2,7 @@ import React, {useState, useEffect} from 'react'
import {SafeAreaProvider} from 'react-native-safe-area-context' import {SafeAreaProvider} from 'react-native-safe-area-context'
import {RootSiblingParent} from 'react-native-root-siblings' import {RootSiblingParent} from 'react-native-root-siblings'
import * as view from './view/index' import * as view from './view/index'
import * as analytics from 'lib/analytics'
import {RootStoreModel, setupState, RootStoreProvider} from './state' import {RootStoreModel, setupState, RootStoreProvider} from './state'
import {Shell} from './view/shell/index' import {Shell} from './view/shell/index'
import {ToastContainer} from './view/com/util/Toast.web' import {ToastContainer} from './view/com/util/Toast.web'
@ -16,6 +17,7 @@ function App() {
view.setup() view.setup()
setupState().then(store => { setupState().then(store => {
setRootStore(store) setRootStore(store)
analytics.init(store)
}) })
}, []) }, [])
@ -26,12 +28,14 @@ function App() {
return ( return (
<RootSiblingParent> <RootSiblingParent>
<RootStoreProvider value={rootStore}> <analytics.Provider>
<SafeAreaProvider> <RootStoreProvider value={rootStore}>
<Shell /> <SafeAreaProvider>
</SafeAreaProvider> <Shell />
<ToastContainer /> </SafeAreaProvider>
</RootStoreProvider> <ToastContainer />
</RootStoreProvider>
</analytics.Provider>
</RootSiblingParent> </RootSiblingParent>
) )
} }

View File

@ -1,19 +1,29 @@
// TODO
import React from 'react' import React from 'react'
import {createClient, AnalyticsProvider} from '@segment/analytics-react'
import {RootStoreModel} from 'state/models/root-store' import {RootStoreModel} from 'state/models/root-store'
const _analytics = { const segmentClient = createClient(
screen(_name: string) {}, {
track(_name: string, _opts: any) {}, writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI',
identify(_userId: string, _userTraits: any) {}, },
} {
export const track = _analytics.track integrations: {
export function useAnalytics() { 'Segment.io': {
return _analytics apiHost: 'api.evt.bsky.app/v1',
} },
},
},
)
export const track = segmentClient?.track?.bind?.(segmentClient)
export function init(_store: RootStoreModel) {} export {useAnalytics} from '@segment/analytics-react'
export function init(_store: RootStoreModel) {
// no init needed on web
}
export function Provider({children}: React.PropsWithChildren<{}>) { export function Provider({children}: React.PropsWithChildren<{}>) {
return children return (
<AnalyticsProvider client={segmentClient}>{children}</AnalyticsProvider>
)
} }

978
yarn.lock

File diff suppressed because it is too large Load Diff