Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
desoindx committed Nov 28, 2024
2 parents e4fc8b1 + 8769009 commit a34818a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions detection/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export const initMatomo = () => {
window.please.track = function (ary) {
//@ts-expect-error: Matomo redefinition
const matomo = window.Matomo
if (matomo) {
if (matomo && ary[0] === 'trackEvent') {
//@ts-expect-error: injected MATOMO_SITE_URL, MATOMO_SITE_ID constant from env var, see webpack.config.js
const matomoTracker = matomo.getTracker(MATOMO_SITE_URL + '/matomo.php', MATOMO_SITE_ID)
matomoTracker.trackEvent(ary[0], ary[1], ary[2], ary[3])
matomoTracker.trackEvent(ary[1], ary[2], ary[3])
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/scripts/getStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getMatomoStats = async (date: string) => {
const [allVisits, allEventsByCategory, allEventsByAction, lastWeekEventsByCategory] = await Promise.all([
await axios
.post<
{ label: string; nb_visits: number }[]
{ label: string; nb_visits: number; url: string }[]
>(`${process.env.NEXT_PUBLIC_MATOMO_SITE_URL}?idSite=${process.env.NEXT_PUBLIC_MATOMO_SITE_ID}&method=Actions.getPageUrls&format=JSON&module=API&period=week&date=${date}&showColumns=nb_visits&filter_limit=-1&flat=1`)
.then((response) => response.data),
await axios
Expand All @@ -52,11 +52,15 @@ export const getMatomoStats = async (date: string) => {
.then((response) => response.data),
])

const impactco2Visits = allVisits.filter(
(page) =>
page.url && (page.url.startsWith('https://impactco2.fr/') || page.url.startsWith('https://www.impactco2.fr/'))
)
const iframes = allEventsByCategory.filter((event) => event.label.startsWith('IFrame_'))
const lastWeekIframes = lastWeekEventsByCategory.filter((event) => event.label.startsWith('IFrame_'))

const internalVisits: Record<string, number> = {}
allVisits.forEach((page) => {
impactco2Visits.forEach((page) => {
const segments = page.label.split('?')
const key = (segments[0].startsWith('/') ? segments[0].slice(1) : segments[0]).replace('outils/', '')
if (internalPages.includes(key)) {
Expand All @@ -82,7 +86,7 @@ export const getMatomoStats = async (date: string) => {
})

const results = {
visits: allVisits.reduce((acc, visit) => acc + visit.nb_visits, 0),
visits: impactco2Visits.reduce((acc, visit) => acc + visit.nb_visits, 0),
iframes: iframes.reduce((acc, visit) => acc + visit.nb_visits, 0),
api: allEventsByCategory
.filter(
Expand Down

0 comments on commit a34818a

Please sign in to comment.