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

Page stats cassée #849

Merged
merged 16 commits into from
Mar 1, 2023
Merged
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
1 change: 1 addition & 0 deletions source/components/stats/StatsContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
useVisitsDuration,
useWebsites,
} from './matomo'

import Section from './utils/Section'

const Wrapper = styled.div`
Expand Down
6 changes: 4 additions & 2 deletions source/components/stats/content/IframeFigures.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ const Text = styled.p`
`

export default function IframeFigures(props) {
const { i18n } = useTranslation()
const currentLangInfos = getCurrentLangInfos(i18n)
if (!props.pages.length || !props.activePages.length) return
const [iframes, activeIframes] =
props.pages &&
props.activePages &&
getIframeRate(props.pages, props.activePages)

const [iframePages, totalIframe] =
props.pages && getIdentifiedIframes(props.pages)
const { i18n } = useTranslation()
const currentLangInfos = getCurrentLangInfos(i18n)

return (
<div>
Expand Down
1 change: 1 addition & 0 deletions source/components/stats/content/ScoreFromURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Text = styled.p`
`

export default function ScoreFromURL(props) {
if (!props.pages.length) return
const scores = props.pages && getScores(props.pages)
// we exclude high number of visits on same urls (corresponds to average test score ?)
// pb : if a user goes to end page, come back to test, change test score, come back to end page, 2 score values are taken into account instead of one.
Expand Down
3 changes: 2 additions & 1 deletion source/components/stats/content/sources/Table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components'
import { Trans } from 'react-i18next'
import styled from 'styled-components'

import Tile from '../../utils/Tile'

Expand Down Expand Up @@ -75,6 +75,7 @@ export default function Table(props) {
<th>%</th>
</tr>
{props.data &&
props.data.length > 0 &&
props.data.map(
(line, index) =>
(!props.limit || index < props.limit) && (
Expand Down
47 changes: 20 additions & 27 deletions source/components/stats/matomo.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
import { useQuery } from 'react-query'
import axios from 'axios'
import { useQuery } from 'react-query'
import { serverURL } from '../../sites/publicodes/conference/useDatabase'

const idSite = 153

export const useChart = ({ chartPeriod, chartDate }) =>
export const useX = (queryName, urlQuery, transformResult, keepPreviousData) =>
useQuery(
['chart', chartPeriod, chartDate],
queryName,
() =>
axios
.get(
`https://stats.data.gouv.fr/?module=API&date=last${chartDate}&period=${chartPeriod}&format=json&idSite=${idSite}&method=VisitsSummary.getVisits`
serverURL + '/get-stats?requestParams=' + encodeURIComponent(urlQuery)
)
.then((res) => res.data),
{
keepPreviousData: true,
}
.then((res) => transformResult(res)),
{ keepPreviousData }
)

export const useSimulationsTerminees = () =>
useQuery(
['SimulationsTerminees'],
() =>
axios
.get(
`https://stats.data.gouv.fr/?module=API&method=Events.getAction&idSite=${idSite}&period=range&date=last6000&format=JSON`
)
.then((res) =>
res.data.find((action) => action.label === 'A terminé la simulation')
),
{
keepPreviousData: true,
}
export const useChart = ({ chartPeriod, chartDate }) =>
useX(
['chart', chartPeriod, chartDate],
`module=API&date=last${chartDate}&period=${chartPeriod}&format=json&idSite=${idSite}&method=VisitsSummary.getVisits`,
(res) => res.data,
true
)

export const useX = (queryName, urlQuery, transformResult) =>
useQuery(queryName, () =>
axios
.get('https://stats.data.gouv.fr/?' + urlQuery)
.then((res) => transformResult(res))
export const useSimulationsTerminees = () =>
useX(
['SimulationsTerminees'],
`module=API&method=Events.getAction&idSite=${idSite}&period=range&date=last6000&format=JSON`,
(res) =>
res.data.find((action) => action.label === 'A terminé la simulation'),
true
)

export const useVisitsDuration = () =>
Expand Down
4 changes: 4 additions & 0 deletions source/locales/pages/fr/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Le simulateur est amélioré en continu.
[✨️ Découvrez les dernières nouveautés et les notes de
versions](/nouveautés).

## Statistiques

Une sélection de statistiques d'audience est disponible publiquement [sur notre page stats](/stats).

## Vie privée

Nous collectons des données anonymisées uniquement pour améliorer ce
Expand Down
7 changes: 4 additions & 3 deletions source/sites/publicodes/conference/useDatabase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { io } from 'socket.io-client'

const secure = NODE_ENV === 'development' ? '' : 's'
const protocol = `http${secure}://`
export const serverURL = protocol + SERVER_URL

export const answersURL = protocol + SERVER_URL + '/answers/'
export const answersURL = serverURL + '/answers/'

export const surveysURL = protocol + SERVER_URL + '/surveys/'
export const surveysURL = serverURL + '/surveys/'

export const contextURL = protocol + SERVER_URL
export const contextURL = serverURL

export default () => {
const database = useMemo(
Expand Down