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

73 feature add matomo analytics 2 #110

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ BUILD_ENV=
COMMUNITY_API_KEY=
THEGRAPH_API_KEY=
REALTOKENAPI='https://api.realtoken.community/v1/token'
REALTOKENAPI_HISTORY='https://history.api.realtoken.community/'
REALTOKENAPI_HISTORY='https://history.api.realtoken.community/'
# Matomo analytics
MATOMO_URL='https://data.realtoken.community/'
# 1: prod
MATOMO_SITE_ID=1
2 changes: 2 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ jobs:
COMMUNITY_API_KEY=${{ secrets.COMMUNITY_API_KEY }} \
REALTOKENAPI=https://api.realtoken.community/v1/token \
REALTOKENAPI_HISTORY=https://history.api.realtoken.community/ \
MATOMO_URL=https://data.realtoken.community/ \
MATOMO_SITE_ID=1 \
HOSTNAME=${{ github.ref_name == 'master' && 'dashboard.realtoken.community' || 'dashboard.${DOCKER_BRANCH}.realtoken.community' }} \
docker compose --project-name ${{ github.ref_name }}-dashboard --file docker-compose-branch.yml up -d'
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ THEGRAPH_API_KEY=XXXXXXXXXXXX

REALTOKENAPI='https://api.realtoken.community/v1/token'
REALTOKENAPI_HISTORY='https://history.api.realtoken.community/'

```

OPTIONAL:

```
MATOMO_URL=''
MATOMO_SITE_ID=''
```

To get a `COMMUNITY_API_KEY`, join the dedicated [telegram dev channel](https://t.me/+XQyoaFfmN61yk7X0) then ask for.

To get a THEGRAPH_API_KEY, you need to create an account on thegraph.com [Thegraph docs](https://thegraph.com/docs/en/querying/managing-api-keys/)

To get a MATOMO_URL and MATOMO_SITE_ID, you need to create an account on matomo.org [Matomo docs](https://fr.matomo.org/)

### Node.js version

<strong>📣 Node.js needed version is `v18.12.1`</strong>
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
- COMMUNITY_API_KEY=$COMMUNITY_API_KEY
- REALTOKENAPI=$REALTOKENAPI
- REALTOKENAPI_HISTORY=$REALTOKENAPI_HISTORY
- MATOMO_URL=$MATOMO_URL
- MATOMO_SITE_ID=$MATOMO_SITE_ID
networks:
- traefik-realt
labels:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@mantine/notifications": "^7.5.3",
"@realtoken/realt-commons": "1.4.6",
"@reduxjs/toolkit": "^2.2.1",
"@socialgouv/matomo-next": "^1.9.2",
"@tabler/icons": "^1.74.0",
"@web3-react/core": "^8.0.35-beta.0",
"cookies-next": "^2.0.5",
Expand Down
29 changes: 29 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react'
import { QueryClient, QueryClientProvider } from 'react-query'
import { Provider } from 'react-redux'

Expand Down Expand Up @@ -25,6 +26,7 @@ import {
metaMaskHooks,
parseAllowedChain,
} from '@realtoken/realt-commons'
import { init as initMatomoNext } from '@socialgouv/matomo-next'

import { getCookie } from 'cookies-next'
import { Provider as JotaiProvider } from 'jotai'
Expand All @@ -37,13 +39,22 @@ import { MantineProviders } from 'src/providers'
import InitStoreProvider from 'src/providers/InitStoreProvider'
import store from 'src/store/store'

// Matomo property added to window object
declare global {
interface Window {
_paq?: unknown[]
}
}

const i18n = initLanguage(resources)

type AppProps = NextAppProps & {
colorScheme: MantineColorScheme
locale: string
env: {
THEGRAPH_API_KEY: string
MATOMO_URL: string
MATOMO_SITE_ID: string
}
}

Expand Down Expand Up @@ -74,6 +85,8 @@ const libraryConnectors = getConnectors({
export const getServerSideProps = async () => ({
props: {
THEGRAPH_API_KEY: process.env.THEGRAPH_API_KEY,
MATOMO_URL: process.env.MATOMO_URL,
MATOMO_SITE_ID: process.env.MATOMO_SITE_ID,
},
})

Expand All @@ -91,6 +104,20 @@ const App = ({ Component, pageProps, colorScheme, env }: AppProps) => {
}
Router.events.on('routeChangeComplete', scrollToTop)

// Event tracking
useEffect(() => {
// eslint-disable-next-line no-underscore-dangle
if (!window._paq) {
// Note: Triggered twice on page load when using strict mode in DEV
initMatomoNext({
url: process.env.MATOMO_URL ?? '',
siteId: process.env.MATOMO_SITE_ID ?? '',
disableCookies: false,
// excludeUrlsPatterns: [/^\/login.php/, /\?token=.+/],
})
}
}, [])

return (
<QueryClientProvider client={queryClient}>
<JotaiProvider>
Expand Down Expand Up @@ -122,6 +149,8 @@ App.getInitialProps = ({ ctx }: { ctx: GetServerSidePropsContext }) => {
return {
env: {
THEGRAPH_API_KEY: process.env.THEGRAPH_API_KEY,
MATOMO_URL: process.env.MATOMO_URL,
MATOMO_SITE_ID: process.env.MATOMO_SITE_ID,
},
colorScheme: getCookie('mantine-color-scheme', ctx) || 'dark',
locale: getCookie('react-i18next', ctx) || 'fr',
Expand Down
Loading