Fix ya metrika hopefully

This commit is contained in:
2022-07-05 11:58:01 +03:00
parent a77fefc251
commit d3cb737972
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)
}, [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 withPlugins = require('next-compose-plugins')
const { i18n } = require('./next-i18next.config') const { i18n } = require('./next-i18next.config')
/** @type {import('next').NextConfig} */ /** @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": "latest",
"next-compose-plugins": "^2.2.1", "next-compose-plugins": "^2.2.1",
"next-i18next": "^11.0.0", "next-i18next": "^11.0.0",
"next-ym": "^2.3.5",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-moment": "^1.1.1", "react-moment": "^1.1.1",
"react-yandex-metrika": "^2.6.0",
"reset-css": "^5.0.1", "reset-css": "^5.0.1",
"sass": "^1.49.9", "sass": "^1.49.9",
"shared-stuff": "file:../shared-stuff", "shared-stuff": "file:../shared-stuff",

View File

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

17384
package-lock.json generated

File diff suppressed because it is too large Load Diff