Skip to content

Commit

Permalink
fix: using reorganized analytics library (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
adjkant authored Dec 22, 2022
1 parent ed928df commit 311ed31
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@mdx-js/react": "^1.6.21",
"@types/react": "^17.0.11",
"@uniswap/analytics": "1.1.0",
"@uniswap/analytics-events": "1.1.1",
"@uniswap/analytics-events": "2.0.0",
"algoliasearch": "^4.9.1",
"clsx": "^1.1.1",
"hast-util-is-element": "1.1.0",
Expand Down
8 changes: 4 additions & 4 deletions src/components/SentimentTracking/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from '@emotion/styled'
import { TraceEvent } from '@uniswap/analytics'
import { BrowserEvent, DocsSentiment, DocsSentimentSection, EventName } from '@uniswap/analytics-events'
import { BrowserEvent, DocsSentiment, DocsSentimentSection, SharedEventName } from '@uniswap/analytics-events'
import React, { useCallback, useState } from 'react'
import { Frown, Meh, Smile } from 'react-feather'

Expand Down Expand Up @@ -66,7 +66,7 @@ export default function SentimentTracking({ analyticsSection }: { analyticsSecti
<StyledTextDiv>Helpful?</StyledTextDiv>
<TraceEvent
element={DocsSentiment.POSITIVE_SENTIMENT}
name={EventName.SENTIMENT_SUBMITTED}
name={SharedEventName.SENTIMENT_SUBMITTED}
events={[BrowserEvent.onClick]}
section={analyticsSection}
>
Expand All @@ -79,7 +79,7 @@ export default function SentimentTracking({ analyticsSection }: { analyticsSecti
</TraceEvent>
<TraceEvent
element={DocsSentiment.NEUTRAL_SENTIMENT}
name={EventName.SENTIMENT_SUBMITTED}
name={SharedEventName.SENTIMENT_SUBMITTED}
events={[BrowserEvent.onClick]}
section={analyticsSection}
>
Expand All @@ -92,7 +92,7 @@ export default function SentimentTracking({ analyticsSection }: { analyticsSecti
</TraceEvent>
<TraceEvent
element={DocsSentiment.NEGATIVE_SENTIMENT}
name={EventName.SENTIMENT_SUBMITTED}
name={SharedEventName.SENTIMENT_SUBMITTED}
events={[BrowserEvent.onClick]}
section={analyticsSection}
>
Expand Down
16 changes: 8 additions & 8 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
BrowserEvent,
DocsHomepageElementName as ElementName,
DocsSectionName as SectionName,
EventName,
SharedEventName,
} from '@uniswap/analytics-events'
import React from 'react'
import { ArrowUpRight as LinkIcon, BookOpen, HelpCircle, Info, MessageCircle } from 'react-feather'
Expand Down Expand Up @@ -332,7 +332,7 @@ export default function Home() {
key={action.to}
element={action.to}
events={[BrowserEvent.onClick]}
name={EventName.PAGE_CLICKED}
name={SharedEventName.PAGE_CLICKED}
section={SectionName.WELCOME_LINKS}
>
<Link style={{ textDecoration: 'none' }} to={action.to}>
Expand Down Expand Up @@ -368,7 +368,7 @@ export default function Home() {
key={action.to}
element={action.to}
events={[BrowserEvent.onClick]}
name={EventName.PAGE_CLICKED}
name={SharedEventName.PAGE_CLICKED}
section={SectionName.DAPP_LINKS}
>
<Link style={{ textDecoration: 'none' }} key={action.title} to={action.to}>
Expand Down Expand Up @@ -397,7 +397,7 @@ export default function Home() {
key={action.to}
element={action.to}
events={[BrowserEvent.onClick]}
name={EventName.PAGE_CLICKED}
name={SharedEventName.PAGE_CLICKED}
section={SectionName.SMART_CONTRACT_LINKS}
>
<Link style={{ textDecoration: 'none' }} key={action.title} to={action.to}>
Expand Down Expand Up @@ -438,7 +438,7 @@ export default function Home() {
<TraceEvent
key={action.href}
element={action.href}
name={EventName.PAGE_CLICKED}
name={SharedEventName.PAGE_CLICKED}
events={[BrowserEvent.onClick]}
section={SectionName.DEVELOPER_LINKS}
>
Expand Down Expand Up @@ -469,7 +469,7 @@ export default function Home() {
events={[BrowserEvent.onClick]}
element={ElementName.DISCORD}
section={SectionName.BOTTOM_MENU_LINKS}
name={EventName.PAGE_CLICKED}
name={SharedEventName.PAGE_CLICKED}
>
<Link style={{ textDecoration: 'none' }} href={'https://discord.gg/ybKVQUWb4s'}>
<CenterCard>
Expand All @@ -485,7 +485,7 @@ export default function Home() {
events={[BrowserEvent.onClick]}
element={ElementName.GRANTS}
section={SectionName.BOTTOM_MENU_LINKS}
name={EventName.PAGE_CLICKED}
name={SharedEventName.PAGE_CLICKED}
>
<Link style={{ textDecoration: 'none' }} href={'https://gov.uniswap.org/'}>
<CenterCard>
Expand All @@ -501,7 +501,7 @@ export default function Home() {
events={[BrowserEvent.onClick]}
section={SectionName.BOTTOM_MENU_LINKS}
element={ElementName.GITHUB}
name={EventName.PAGE_CLICKED}
name={SharedEventName.PAGE_CLICKED}
>
<Link style={{ textDecoration: 'none' }} href={'https://github.com/Uniswap'}>
<CenterCard>
Expand Down
4 changes: 2 additions & 2 deletions src/theme/DocSidebarItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import OriginalDocSidebarItem from '@theme-original/DocSidebarItem'
import { TraceEvent } from '@uniswap/analytics'
import { BrowserEvent, EventName } from '@uniswap/analytics-events'
import { BrowserEvent, SharedEventName } from '@uniswap/analytics-events'
import React from 'react'

const DOCUSAURUS_LINK_ITEM_TYPE = 'link'
Expand All @@ -11,7 +11,7 @@ export default function DocSidebarItem(props: { item }) {
<TraceEvent
events={[BrowserEvent.onClick]}
element={props.item.href}
name={EventName.MENU_CLICKED}
name={SharedEventName.MENU_CLICKED}
shouldLogImpression={props.item.type === DOCUSAURUS_LINK_ITEM_TYPE}
>
{/* Required for onClick to register */}
Expand Down
4 changes: 2 additions & 2 deletions src/theme/NavbarItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLocation } from '@docusaurus/router'
import OriginalNavBarItem from '@theme-original/NavbarItem'
import { TraceEvent } from '@uniswap/analytics'
import { BrowserEvent, DocsProtocolVersion, EventName } from '@uniswap/analytics-events'
import { BrowserEvent, DocsProtocolVersion, SharedEventName } from '@uniswap/analytics-events'
import React from 'react'

enum ProtocolVersion {
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function NavbarItem(props: { className: string; label: string })
<TraceEvent
events={[BrowserEvent.onClick]}
element={props.label}
name={EventName.NAVBAR_CLICKED}
name={SharedEventName.NAVBAR_CLICKED}
section={getSection(selectedDocVersion)}
>
<OriginalNavBarItem {...props} className={getClassName(props.className, selectedDocVersion)} />
Expand Down
16 changes: 9 additions & 7 deletions src/theme/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLocation } from '@docusaurus/router'
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
import { initializeAnalytics, OriginApplication, sendAnalyticsEvent, Trace, user } from '@uniswap/analytics'
import { CustomUserProperties, EventName, getBrowser } from '@uniswap/analytics-events'
import { CustomUserProperties, getBrowser, SharedEventName } from '@uniswap/analytics-events'
import React, { useEffect } from 'react'
import { getCLS, getFCP, getFID, getLCP, Metric } from 'web-vitals'

Expand Down Expand Up @@ -32,20 +32,22 @@ export default function Root({ children }: React.PropsWithChildren<{ open: boole

// Fires on initial render of the page
useEffect(() => {
sendAnalyticsEvent(EventName.APP_LOADED)
sendAnalyticsEvent(SharedEventName.APP_LOADED)
user.set(CustomUserProperties.USER_AGENT, navigator.userAgent)
user.set(CustomUserProperties.BROWSER, getBrowser())
user.set(CustomUserProperties.SCREEN_RESOLUTION_HEIGHT, window.screen.height)
user.set(CustomUserProperties.SCREEN_RESOLUTION_WIDTH, window.screen.width)
getCLS(({ delta }: Metric) => sendAnalyticsEvent(EventName.WEB_VITALS, { cumulative_layout_shift: delta }))
getFCP(({ delta }: Metric) => sendAnalyticsEvent(EventName.WEB_VITALS, { first_contentful_paint_ms: delta }))
getFID(({ delta }: Metric) => sendAnalyticsEvent(EventName.WEB_VITALS, { first_input_delay_ms: delta }))
getLCP(({ delta }: Metric) => sendAnalyticsEvent(EventName.WEB_VITALS, { largest_contentful_paint_ms: delta }))
getCLS(({ delta }: Metric) => sendAnalyticsEvent(SharedEventName.WEB_VITALS, { cumulative_layout_shift: delta }))
getFCP(({ delta }: Metric) => sendAnalyticsEvent(SharedEventName.WEB_VITALS, { first_contentful_paint_ms: delta }))
getFID(({ delta }: Metric) => sendAnalyticsEvent(SharedEventName.WEB_VITALS, { first_input_delay_ms: delta }))
getLCP(({ delta }: Metric) =>
sendAnalyticsEvent(SharedEventName.WEB_VITALS, { largest_contentful_paint_ms: delta })
)
}, [])

// Fires on route change
useEffect(() => {
sendAnalyticsEvent(EventName.PAGE_VIEWED, {
sendAnalyticsEvent(SharedEventName.PAGE_VIEWED, {
page: pathname,
})
}, [pathname])
Expand Down
4 changes: 2 additions & 2 deletions src/theme/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import OriginalSearchBar from '@theme-original/SearchBar'
import { TraceEvent } from '@uniswap/analytics'
import { BrowserEvent, EventName } from '@uniswap/analytics-events'
import { BrowserEvent, SharedEventName } from '@uniswap/analytics-events'
import React from 'react'

export default function SearchBarWithAnalytics(props) {
return (
<>
<TraceEvent events={[BrowserEvent.onClick]} name={EventName.SEARCH_BAR_CLICKED}>
<TraceEvent events={[BrowserEvent.onClick]} name={SharedEventName.SEARCH_BAR_CLICKED}>
{/* Required for onClick to register */}
<div>
<OriginalSearchBar {...props} />
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3146,10 +3146,10 @@
"@typescript-eslint/types" "5.42.1"
eslint-visitor-keys "^3.3.0"

"@uniswap/analytics-events@1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-1.1.1.tgz#7514f45ec4936fb44f94c691b977ba3f741a54b3"
integrity sha512-B8cIbBdpqv3do4mO+/bu6WGsIuTuQqjtYDGZthhCrmdiN3ImE8HVGXKzVV3t9CyG1vPssxCtRSeSgyPVOm/4vA==
"@uniswap/analytics-events@2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@uniswap/analytics-events/-/analytics-events-2.0.0.tgz#5370421c916f900900965a5f8da5316dbb39c674"
integrity sha512-Cmr+1H0VJX+vdxGwpZpL5hOkRw49j8hu2uLddiXChP64HHihjiYljC3tckkCJpkpW6NHHlfX9U+D2Wy0MiVaDw==

"@uniswap/analytics@1.1.0":
version "1.1.0"
Expand Down

1 comment on commit 311ed31

@vercel
Copy link

@vercel vercel bot commented on 311ed31 Dec 22, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

docs – ./

docs-git-main-uniswap.vercel.app
docs-uniswap.vercel.app
docs.uniswap.org

Please sign in to comment.