Fix ya metrika hopefully
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-07-05 11:58:01 +03:00
parent a77fefc251
commit 7a0480fa69
6 changed files with 2948 additions and 22363 deletions

View File

@@ -0,0 +1,39 @@
import Router from 'next/router'
import React, { useCallback, useEffect } from 'react'
import ym, { YMInitializer } from 'react-yandex-metrika'
const enabled =
process.env.NODE_ENV === 'production' &&
process.env.YA_METRIKA_ID
const WithYandexMetrika = (props) => {
const { children } = props
const hit = useCallback((url) => {
if (enabled) {
ym('hit', url)
} else {
console.log('%c[YandexMetrika](HIT)', 'color: orange', url)
}
}, [])
useEffect(() => {
hit(window.location.pathname + window.location.search)
Router.events.on('routeChangeComplete', hit)
}, [])
return (
<>
{enabled && (
<YMInitializer
accounts={[Number(process.env.YA_METRIKA_ID)]}
options={{ webvisor: true, defer: true }}
version='2'
/>
)}
{children}
</>
)
}
export default WithYandexMetrika

View File

@@ -1,4 +1,5 @@
const withPlugins = require('next-compose-plugins')
const { i18n } = require('./next-i18next.config')
/** @type {import('next').NextConfig} */

7828
app/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -14,10 +14,10 @@
"next": "latest",
"next-compose-plugins": "^2.2.1",
"next-i18next": "^11.0.0",
"next-ym": "^2.3.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-moment": "^1.1.1",
"react-yandex-metrika": "^2.6.0",
"reset-css": "^5.0.1",
"sass": "^1.49.9",
"shared-stuff": "file:../shared-stuff",

View File

@@ -1,12 +1,11 @@
import { CssBaseline } from '@mui/material'
import { createTheme, ThemeProvider } from '@mui/material/styles'
import { appWithTranslation } from 'next-i18next'
import withYM from 'next-ym'
import Router from 'next/router'
import 'reset-css'
import '../styles/global.scss'
import Layout from '../components/layout'
import WithYandexMetrika from '../components/WithYandexMetrika'
function App ({ Component, pageProps }) {
const theme = createTheme({
@@ -16,13 +15,15 @@ function App ({ Component, pageProps }) {
})
return (
<WithYandexMetrika>
<ThemeProvider theme={theme}>
<CssBaseline />
<Layout>
<Component {...pageProps} />
</Layout>
</ThemeProvider>
</WithYandexMetrika>
)
}
export default withYM(process.env.YA_METRIKA_ID, Router)(appWithTranslation(App))
export default appWithTranslation(App)

17386
package-lock.json generated

File diff suppressed because it is too large Load Diff