about summary refs log tree commit diff
path: root/src/lib/analytics.web.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-04-04 13:01:38 -0500
committerGitHub <noreply@github.com>2023-04-04 13:01:38 -0500
commitf717ff67190320d86de97f0984e70ed8cf2c9fab (patch)
tree297ee8f6e0c1a54d1dd7db07ab03d1ea6d398abf /src/lib/analytics.web.tsx
parentb100abca0e3007c4d5ce331d5877c3036fd945ec (diff)
downloadvoidsky-f717ff67190320d86de97f0984e70ed8cf2c9fab.tar.zst
Add analytics to the web build (close #233) (#385)
* Add analytics to the web build (close #233)

* Use bsky endpoint for analytics
Diffstat (limited to 'src/lib/analytics.web.tsx')
-rw-r--r--src/lib/analytics.web.tsx34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/lib/analytics.web.tsx b/src/lib/analytics.web.tsx
index 10488c303..97f456893 100644
--- a/src/lib/analytics.web.tsx
+++ b/src/lib/analytics.web.tsx
@@ -1,19 +1,29 @@
-// TODO
 import React from 'react'
+import {createClient, AnalyticsProvider} from '@segment/analytics-react'
 import {RootStoreModel} from 'state/models/root-store'
 
-const _analytics = {
-  screen(_name: string) {},
-  track(_name: string, _opts: any) {},
-  identify(_userId: string, _userTraits: any) {},
-}
-export const track = _analytics.track
-export function useAnalytics() {
-  return _analytics
-}
+const segmentClient = createClient(
+  {
+    writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI',
+  },
+  {
+    integrations: {
+      'Segment.io': {
+        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<{}>) {
-  return children
+  return (
+    <AnalyticsProvider client={segmentClient}>{children}</AnalyticsProvider>
+  )
 }